27 ///\brief Extenders for iterable maps. |
27 ///\brief Extenders for iterable maps. |
28 |
28 |
29 namespace lemon { |
29 namespace lemon { |
30 |
30 |
31 /// \ingroup graphbits |
31 /// \ingroup graphbits |
|
32 /// |
|
33 /// \brief Extender for maps |
32 template <typename _Map> |
34 template <typename _Map> |
33 class IterableMapExtender : public _Map { |
35 class MapExtender : public _Map { |
34 public: |
36 public: |
35 |
37 |
36 typedef _Map Parent; |
38 typedef _Map Parent; |
37 typedef IterableMapExtender Map; |
39 typedef MapExtender Map; |
38 |
40 |
39 |
41 |
40 typedef typename Parent::Graph Graph; |
42 typedef typename Parent::Graph Graph; |
41 typedef typename Parent::Key Item; |
43 typedef typename Parent::Key Item; |
42 |
44 |
47 class ConstMapIt; |
49 class ConstMapIt; |
48 |
50 |
49 friend class MapIt; |
51 friend class MapIt; |
50 friend class ConstMapIt; |
52 friend class ConstMapIt; |
51 |
53 |
52 protected: |
|
53 |
|
54 using Parent::getGraph; |
|
55 |
|
56 public: |
54 public: |
57 |
55 |
58 IterableMapExtender(const Graph& graph) : Parent(graph) {} |
56 MapExtender(const Graph& graph) |
|
57 : Parent(graph) {} |
59 |
58 |
60 IterableMapExtender(const Graph& graph, const Value& value) |
59 MapExtender(const Graph& graph, const Value& value) |
61 : Parent(graph, value) {} |
60 : Parent(graph, value) {} |
62 |
61 |
63 |
62 |
64 class MapIt : public ItemSetTraits<Graph, Item>::ItemIt { |
63 class MapIt : public Item { |
65 public: |
64 public: |
66 |
65 |
67 typedef typename ItemSetTraits<Graph, Item>::ItemIt Parent; |
66 typedef Item Parent; |
68 |
|
69 typedef typename Map::Value Value; |
67 typedef typename Map::Value Value; |
70 |
68 |
71 MapIt(Map& _map) : Parent(*_map.getGraph()), map(_map) {} |
69 MapIt() {} |
|
70 |
|
71 MapIt(Invalid i) : Parent(i) { } |
|
72 |
|
73 explicit MapIt(Map& _map) : map(_map) { |
|
74 map.getNotifier()->first(*this); |
|
75 } |
|
76 |
|
77 MapIt(const Map& _map, const Item& item) |
|
78 : Parent(item), map(_map) {} |
|
79 |
|
80 MapIt& operator++() { |
|
81 map.getNotifier()->next(*this); |
|
82 return *this; |
|
83 } |
72 |
84 |
73 typename MapTraits<Map>::ConstReturnValue operator*() const { |
85 typename MapTraits<Map>::ConstReturnValue operator*() const { |
74 return map[*this]; |
86 return map[*this]; |
75 } |
87 } |
76 |
88 |
85 protected: |
97 protected: |
86 Map& map; |
98 Map& map; |
87 |
99 |
88 }; |
100 }; |
89 |
101 |
90 class ConstMapIt : public ItemSetTraits<Graph, Key>::ItemIt { |
102 class ConstMapIt : public Item { |
91 public: |
103 public: |
92 |
104 |
93 typedef typename ItemSetTraits<Graph, Key>::ItemIt Parent; |
105 typedef Item Parent; |
94 |
106 |
95 typedef typename Map::Value Value; |
107 typedef typename Map::Value Value; |
|
108 |
|
109 ConstMapIt() {} |
96 |
110 |
97 ConstMapIt(const Map& _map) : Parent(*_map.getGraph()), map(_map) {} |
111 ConstMapIt(Invalid i) : Parent(i) { } |
|
112 |
|
113 explicit ConstMapIt(Map& _map) : map(_map) { |
|
114 map.getNotifier()->first(*this); |
|
115 } |
|
116 |
|
117 ConstMapIt(const Map& _map, const Item& item) |
|
118 : Parent(item), map(_map) {} |
|
119 |
|
120 ConstMapIt& operator++() { |
|
121 map.getNotifier()->next(*this); |
|
122 return *this; |
|
123 } |
98 |
124 |
99 typename MapTraits<Map>::ConstReturnValue operator*() const { |
125 typename MapTraits<Map>::ConstReturnValue operator*() const { |
100 return map[*this]; |
126 return map[*this]; |
101 } |
127 } |
|
128 |
102 protected: |
129 protected: |
103 const Map& map; |
130 const Map& map; |
104 }; |
131 }; |
105 |
132 |
106 class ItemIt : public ItemSetTraits<Graph, Key>::ItemIt { |
133 class ItemIt : Item { |
107 public: |
134 public: |
108 |
135 |
109 typedef typename ItemSetTraits<Graph, Key>::ItemIt Parent; |
136 typedef Item Parent; |
|
137 |
|
138 ItemIt() {} |
110 |
139 |
111 ItemIt(Map& _map) : Parent(*_map.getGraph()) {} |
140 ItemIt(Invalid i) : Parent(i) { } |
|
141 |
|
142 explicit ItemIt(Map& _map) : map(_map) { |
|
143 map->getNotifier()->first(*this); |
|
144 } |
|
145 |
|
146 ItemIt(const Map& _map, const Item& item) |
|
147 : Parent(item), map(_map) {} |
|
148 |
|
149 ItemIt& operator++() { |
|
150 map.getNotifier()->next(*this); |
|
151 return *this; |
|
152 } |
|
153 |
|
154 protected: |
|
155 const Map& map; |
112 |
156 |
113 }; |
157 }; |
114 }; |
158 }; |
115 |
159 |
116 } |
160 } |