lemon/bits/map_extender.h
changeset 865 e9c203fb003d
parent 314 2cc60866a0c9
child 867 994c7df296c9
child 1078 c59bdcc8e33e
equal deleted inserted replaced
4:71bb5c1d0034 9:05423e998490
    78     public:
    78     public:
    79 
    79 
    80       typedef Item Parent;
    80       typedef Item Parent;
    81       typedef typename Map::Value Value;
    81       typedef typename Map::Value Value;
    82 
    82 
    83       MapIt() {}
    83       MapIt() : map(NULL) {}
    84 
    84 
    85       MapIt(Invalid i) : Parent(i) { }
    85       MapIt(Invalid i) : Parent(i), map(NULL) {}
    86 
    86 
    87       explicit MapIt(Map& _map) : map(_map) {
    87       explicit MapIt(Map& _map) : map(&_map) {
    88         map.notifier()->first(*this);
    88         map->notifier()->first(*this);
    89       }
    89       }
    90 
    90 
    91       MapIt(const Map& _map, const Item& item)
    91       MapIt(const Map& _map, const Item& item)
       
    92         : Parent(item), map(&_map) {}
       
    93 
       
    94       MapIt& operator++() {
       
    95         map->notifier()->next(*this);
       
    96         return *this;
       
    97       }
       
    98 
       
    99       typename MapTraits<Map>::ConstReturnValue operator*() const {
       
   100         return (*map)[*this];
       
   101       }
       
   102 
       
   103       typename MapTraits<Map>::ReturnValue operator*() {
       
   104         return (*map)[*this];
       
   105       }
       
   106 
       
   107       void set(const Value& value) {
       
   108         map->set(*this, value);
       
   109       }
       
   110 
       
   111     protected:
       
   112       Map* map;
       
   113 
       
   114     };
       
   115 
       
   116     class ConstMapIt : public Item {
       
   117     public:
       
   118 
       
   119       typedef Item Parent;
       
   120 
       
   121       typedef typename Map::Value Value;
       
   122 
       
   123       ConstMapIt() : map(NULL) {}
       
   124 
       
   125       ConstMapIt(Invalid i) : Parent(i), map(NULL) {}
       
   126 
       
   127       explicit ConstMapIt(Map& _map) : map(&_map) {
       
   128         map->notifier()->first(*this);
       
   129       }
       
   130 
       
   131       ConstMapIt(const Map& _map, const Item& item)
    92         : Parent(item), map(_map) {}
   132         : Parent(item), map(_map) {}
    93 
   133 
    94       MapIt& operator++() {
   134       ConstMapIt& operator++() {
    95         map.notifier()->next(*this);
   135         map->notifier()->next(*this);
    96         return *this;
   136         return *this;
    97       }
   137       }
    98 
   138 
    99       typename MapTraits<Map>::ConstReturnValue operator*() const {
   139       typename MapTraits<Map>::ConstReturnValue operator*() const {
   100         return map[*this];
   140         return map[*this];
   101       }
   141       }
   102 
   142 
   103       typename MapTraits<Map>::ReturnValue operator*() {
   143     protected:
   104         return map[*this];
   144       const Map* map;
   105       }
       
   106 
       
   107       void set(const Value& value) {
       
   108         map.set(*this, value);
       
   109       }
       
   110 
       
   111     protected:
       
   112       Map& map;
       
   113 
       
   114     };
       
   115 
       
   116     class ConstMapIt : public Item {
       
   117     public:
       
   118 
       
   119       typedef Item Parent;
       
   120 
       
   121       typedef typename Map::Value Value;
       
   122 
       
   123       ConstMapIt() {}
       
   124 
       
   125       ConstMapIt(Invalid i) : Parent(i) { }
       
   126 
       
   127       explicit ConstMapIt(Map& _map) : map(_map) {
       
   128         map.notifier()->first(*this);
       
   129       }
       
   130 
       
   131       ConstMapIt(const Map& _map, const Item& item)
       
   132         : Parent(item), map(_map) {}
       
   133 
       
   134       ConstMapIt& operator++() {
       
   135         map.notifier()->next(*this);
       
   136         return *this;
       
   137       }
       
   138 
       
   139       typename MapTraits<Map>::ConstReturnValue operator*() const {
       
   140         return map[*this];
       
   141       }
       
   142 
       
   143     protected:
       
   144       const Map& map;
       
   145     };
   145     };
   146 
   146 
   147     class ItemIt : public Item {
   147     class ItemIt : public Item {
   148     public:
   148     public:
   149 
   149 
   150       typedef Item Parent;
   150       typedef Item Parent;
   151 
   151 
   152       ItemIt() {}
   152       ItemIt() : map(NULL) {}
   153 
   153 
   154       ItemIt(Invalid i) : Parent(i) { }
   154       ItemIt(Invalid i) : Parent(i), map(NULL) {}
   155 
   155 
   156       explicit ItemIt(Map& _map) : map(_map) {
   156       explicit ItemIt(Map& _map) : map(&_map) {
   157         map.notifier()->first(*this);
   157         map->notifier()->first(*this);
   158       }
   158       }
   159 
   159 
   160       ItemIt(const Map& _map, const Item& item)
   160       ItemIt(const Map& _map, const Item& item)
   161         : Parent(item), map(_map) {}
   161         : Parent(item), map(&_map) {}
   162 
   162 
   163       ItemIt& operator++() {
   163       ItemIt& operator++() {
   164         map.notifier()->next(*this);
   164         map->notifier()->next(*this);
   165         return *this;
   165         return *this;
   166       }
   166       }
   167 
   167 
   168     protected:
   168     protected:
   169       const Map& map;
   169       const Map* map;
   170 
   170 
   171     };
   171     };
   172   };
   172   };
   173 
   173 
   174   // \ingroup graphbits
   174   // \ingroup graphbits
   222     public:
   222     public:
   223 
   223 
   224       typedef Item Parent;
   224       typedef Item Parent;
   225       typedef typename Map::Value Value;
   225       typedef typename Map::Value Value;
   226 
   226 
   227       MapIt() {}
   227       MapIt() : map(NULL) {}
   228 
   228 
   229       MapIt(Invalid i) : Parent(i) { }
   229       MapIt(Invalid i) : Parent(i), map(NULL) { }
   230 
   230 
   231       explicit MapIt(Map& _map) : map(_map) {
   231       explicit MapIt(Map& _map) : map(&_map) {
   232         map.graph.first(*this);
   232         map->graph.first(*this);
   233       }
   233       }
   234 
   234 
   235       MapIt(const Map& _map, const Item& item)
   235       MapIt(const Map& _map, const Item& item)
   236         : Parent(item), map(_map) {}
   236         : Parent(item), map(&_map) {}
   237 
   237 
   238       MapIt& operator++() {
   238       MapIt& operator++() {
   239         map.graph.next(*this);
   239         map->graph.next(*this);
   240         return *this;
   240         return *this;
   241       }
   241       }
   242 
   242 
   243       typename MapTraits<Map>::ConstReturnValue operator*() const {
   243       typename MapTraits<Map>::ConstReturnValue operator*() const {
   244         return map[*this];
   244         return (*map)[*this];
   245       }
   245       }
   246 
   246 
   247       typename MapTraits<Map>::ReturnValue operator*() {
   247       typename MapTraits<Map>::ReturnValue operator*() {
   248         return map[*this];
   248         return (*map)[*this];
   249       }
   249       }
   250 
   250 
   251       void set(const Value& value) {
   251       void set(const Value& value) {
   252         map.set(*this, value);
   252         map->set(*this, value);
   253       }
   253       }
   254 
   254 
   255     protected:
   255     protected:
   256       Map& map;
   256       Map* map;
   257 
   257 
   258     };
   258     };
   259 
   259 
   260     class ConstMapIt : public Item {
   260     class ConstMapIt : public Item {
   261     public:
   261     public:
   262 
   262 
   263       typedef Item Parent;
   263       typedef Item Parent;
   264 
   264 
   265       typedef typename Map::Value Value;
   265       typedef typename Map::Value Value;
   266 
   266 
   267       ConstMapIt() {}
   267       ConstMapIt() : map(NULL) {}
   268 
   268 
   269       ConstMapIt(Invalid i) : Parent(i) { }
   269       ConstMapIt(Invalid i) : Parent(i), map(NULL) { }
   270 
   270 
   271       explicit ConstMapIt(Map& _map) : map(_map) {
   271       explicit ConstMapIt(Map& _map) : map(&_map) {
   272         map.graph.first(*this);
   272         map->graph.first(*this);
   273       }
   273       }
   274 
   274 
   275       ConstMapIt(const Map& _map, const Item& item)
   275       ConstMapIt(const Map& _map, const Item& item)
   276         : Parent(item), map(_map) {}
   276         : Parent(item), map(&_map) {}
   277 
   277 
   278       ConstMapIt& operator++() {
   278       ConstMapIt& operator++() {
   279         map.graph.next(*this);
   279         map->graph.next(*this);
   280         return *this;
   280         return *this;
   281       }
   281       }
   282 
   282 
   283       typename MapTraits<Map>::ConstReturnValue operator*() const {
   283       typename MapTraits<Map>::ConstReturnValue operator*() const {
   284         return map[*this];
   284         return (*map)[*this];
   285       }
   285       }
   286 
   286 
   287     protected:
   287     protected:
   288       const Map& map;
   288       const Map* map;
   289     };
   289     };
   290 
   290 
   291     class ItemIt : public Item {
   291     class ItemIt : public Item {
   292     public:
   292     public:
   293 
   293 
   294       typedef Item Parent;
   294       typedef Item Parent;
   295 
   295 
   296       ItemIt() {}
   296       ItemIt() : map(NULL) {}
   297 
   297 
   298       ItemIt(Invalid i) : Parent(i) { }
   298       ItemIt(Invalid i) : Parent(i), map(NULL) { }
   299 
   299 
   300       explicit ItemIt(Map& _map) : map(_map) {
   300       explicit ItemIt(Map& _map) : map(&_map) {
   301         map.graph.first(*this);
   301         map->graph.first(*this);
   302       }
   302       }
   303 
   303 
   304       ItemIt(const Map& _map, const Item& item)
   304       ItemIt(const Map& _map, const Item& item)
   305         : Parent(item), map(_map) {}
   305         : Parent(item), map(&_map) {}
   306 
   306 
   307       ItemIt& operator++() {
   307       ItemIt& operator++() {
   308         map.graph.next(*this);
   308         map->graph.next(*this);
   309         return *this;
   309         return *this;
   310       }
   310       }
   311 
   311 
   312     protected:
   312     protected:
   313       const Map& map;
   313       const Map* map;
   314 
   314 
   315     };
   315     };
   316 
   316 
   317   private:
   317   private:
   318 
   318