COIN-OR::LEMON - Graph Library

Changeset 2031:080d51024ac5 in lemon-0.x for lemon/bits/map_extender.h


Ignore:
Timestamp:
04/03/06 11:45:23 (18 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2670
Message:

Correcting the structure of the graph's and adaptor's map.
The template assign operators and map iterators can be used for adaptors also.

Some bugfix in the adaptors

New class SwapBpUGraphAdaptor which swaps the two nodeset of the graph.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/bits/map_extender.h

    r1999 r2031  
    2323
    2424#include <lemon/bits/traits.h>
     25
     26#include <lemon/concept_check.h>
     27#include <lemon/concept/maps.h>
    2528
    2629///\file
     
    6063      : Parent(graph, value) {}
    6164
     65    MapExtender& operator=(const MapExtender& cmap) {
     66      return operator=<MapExtender>(cmap);
     67    }
     68
     69    template <typename CMap>
     70    MapExtender& operator=(const CMap& cmap) {
     71      Parent::operator=(cmap);
     72      return *this;
     73    }
    6274
    6375    class MapIt : public Item {
     
    131143    };
    132144
    133     class ItemIt : Item {
     145    class ItemIt : public Item {
    134146    public:
    135147     
     
    141153
    142154      explicit ItemIt(Map& _map) : map(_map) {
    143         map->getNotifier()->first(*this);
     155        map.getNotifier()->first(*this);
    144156      }
    145157
     
    158170  };
    159171
     172  /// \ingroup graphbits
     173  ///
     174  /// \brief Extender for maps which use a subset of the items.
     175  template <typename _Graph, typename _Map>
     176  class SubMapExtender : public _Map {
     177  public:
     178
     179    typedef _Map Parent;
     180    typedef SubMapExtender Map;
     181
     182    typedef _Graph Graph;
     183
     184    typedef typename Parent::Key Item;
     185
     186    typedef typename Parent::Key Key;
     187    typedef typename Parent::Value Value;
     188
     189    class MapIt;
     190    class ConstMapIt;
     191
     192    friend class MapIt;
     193    friend class ConstMapIt;
     194
     195  public:
     196
     197    SubMapExtender(const Graph& _graph)
     198      : Parent(_graph), graph(_graph) {}
     199
     200    SubMapExtender(const Graph& _graph, const Value& _value)
     201      : Parent(_graph, _value), graph(_graph) {}
     202
     203    SubMapExtender& operator=(const SubMapExtender& cmap) {
     204      return operator=<MapExtender>(cmap);
     205    }
     206
     207    template <typename CMap>
     208    SubMapExtender& operator=(const CMap& cmap) {
     209      checkConcept<concept::ReadMap<Key, Value>, CMap>();
     210      Item it;
     211      for (graph.first(it); it != INVALID; graph.next(it)) {
     212        Parent::set(it, cmap[it]);
     213      }
     214      return *this;
     215    }
     216
     217    class MapIt : public Item {
     218    public:
     219     
     220      typedef Item Parent;
     221      typedef typename Map::Value Value;
     222     
     223      MapIt() {}
     224
     225      MapIt(Invalid i) : Parent(i) { }
     226
     227      explicit MapIt(Map& _map) : map(_map) {
     228        map.graph.first(*this);
     229      }
     230
     231      MapIt(const Map& _map, const Item& item)
     232        : Parent(item), map(_map) {}
     233
     234      MapIt& operator++() {
     235        map.graph.next(*this);
     236        return *this;
     237      }
     238     
     239      typename MapTraits<Map>::ConstReturnValue operator*() const {
     240        return map[*this];
     241      }
     242
     243      typename MapTraits<Map>::ReturnValue operator*() {
     244        return map[*this];
     245      }
     246     
     247      void set(const Value& value) {
     248        map.set(*this, value);
     249      }
     250     
     251    protected:
     252      Map& map;
     253     
     254    };
     255
     256    class ConstMapIt : public Item {
     257    public:
     258
     259      typedef Item Parent;
     260
     261      typedef typename Map::Value Value;
     262     
     263      ConstMapIt() {}
     264
     265      ConstMapIt(Invalid i) : Parent(i) { }
     266
     267      explicit ConstMapIt(Map& _map) : map(_map) {
     268        map.graph.first(*this);
     269      }
     270
     271      ConstMapIt(const Map& _map, const Item& item)
     272        : Parent(item), map(_map) {}
     273
     274      ConstMapIt& operator++() {
     275        map.graph.next(*this);
     276        return *this;
     277      }
     278
     279      typename MapTraits<Map>::ConstReturnValue operator*() const {
     280        return map[*this];
     281      }
     282
     283    protected:
     284      const Map& map;
     285    };
     286
     287    class ItemIt : public Item {
     288    public:
     289     
     290      typedef Item Parent;
     291     
     292      ItemIt() {}
     293
     294      ItemIt(Invalid i) : Parent(i) { }
     295
     296      explicit ItemIt(Map& _map) : map(_map) {
     297        map.graph.first(*this);
     298      }
     299
     300      ItemIt(const Map& _map, const Item& item)
     301        : Parent(item), map(_map) {}
     302
     303      ItemIt& operator++() {
     304        map.graph.next(*this);
     305        return *this;
     306      }
     307
     308    protected:
     309      const Map& map;
     310     
     311    };
     312   
     313  private:
     314
     315    const Graph& graph;
     316   
     317  };
     318
    160319}
    161320
Note: See TracChangeset for help on using the changeset viewer.