33 /** The base class all of the map iterators. |
34 /** The base class all of the map iterators. |
34 * The class defines the typedefs of the iterators, |
35 * The class defines the typedefs of the iterators, |
35 * simple step functions and equality operators. |
36 * simple step functions and equality operators. |
36 */ |
37 */ |
37 |
38 |
38 template <typename Map> |
39 template < |
|
40 typename _Graph, |
|
41 typename _Item> |
39 class MapIteratorBase { |
42 class MapIteratorBase { |
40 |
43 |
41 public: |
44 protected: |
42 |
45 |
43 /// The key type of the iterator. |
46 /// The key type of the iterator. |
44 typedef typename Map::Key Key; |
47 typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt; |
45 /// The iterator to iterate on the keys. |
48 |
46 typedef typename Map::KeyIt KeyIt; |
49 ItemIt it; |
47 |
|
48 /// The value type of the iterator. |
|
49 typedef typename Map::Value Value; |
|
50 /// The reference type of the iterator. |
|
51 typedef typename Map::Reference Reference; |
|
52 /// The pointer type of the iterator. |
|
53 typedef typename Map::Pointer Pointer; |
|
54 |
|
55 /// The const value type of the iterator. |
|
56 typedef typename Map::ConstValue ConstValue; |
|
57 /// The const reference type of the iterator. |
|
58 typedef typename Map::ConstReference ConstReference; |
|
59 /// The pointer type of the iterator. |
|
60 typedef typename Map::ConstPointer ConstPointer; |
|
61 |
|
62 protected: |
|
63 |
|
64 KeyIt it; |
|
65 |
50 |
66 /// Default constructor. |
51 /// Default constructor. |
67 MapIteratorBase() {} |
52 MapIteratorBase() {} |
68 |
53 |
69 /// KeyIt initialized MapIteratorBase constructor. |
54 /// ItemIt initialized MapIteratorBase constructor. |
70 MapIteratorBase(const KeyIt pit) : it(pit) {} |
55 MapIteratorBase(const ItemIt _it) : it(_it) {} |
71 |
56 |
72 public: |
57 public: |
73 |
58 |
74 /// Stepping forward in the map. |
59 /// Stepping forward in the map. |
75 void increment() { |
60 void increment() { |
76 ++it; |
61 ++it; |
77 } |
62 } |
78 |
63 |
79 /// The equality operator of the map. |
64 /// The equality operator of the map. |
80 bool operator==(const MapIteratorBase& pit) const { |
65 bool operator==(const MapIteratorBase& _it) const { |
81 return pit.it == it; |
66 return _it.it == it; |
82 } |
67 } |
83 |
68 |
84 /// The not-equality operator of the map. |
69 /// The not-equality operator of the map. |
85 bool operator!=(const MapIteratorBase& pit) const { |
70 bool operator!=(const MapIteratorBase& _it) const { |
86 return !(*this == pit); |
71 return !(*this == _it); |
87 } |
72 } |
88 }; |
73 }; |
89 |
74 |
90 template <typename Map> class MapConstIterator; |
75 |
|
76 template < |
|
77 typename _Graph, |
|
78 typename _Item, |
|
79 typename _Map> |
|
80 class MapConstIterator; |
91 |
81 |
92 /** Compatible iterator with the stl maps' iterators. |
82 /** Compatible iterator with the stl maps' iterators. |
93 * It iterates on pairs of a key and a value. |
83 * It iterates on pairs of a key and a value. |
94 */ |
84 */ |
95 template <typename Map> |
85 template < |
96 class MapIterator : public MapIteratorBase<Map> { |
86 typename _Graph, |
97 |
87 typename _Item, |
98 friend class MapConstIterator<Map>; |
88 typename _Map> |
|
89 class MapIterator : public MapIteratorBase<_Graph, _Item> { |
|
90 |
|
91 friend class MapConstIterator<_Graph, _Item, _Map>; |
99 |
92 |
100 |
93 |
101 public: |
94 public: |
102 |
95 |
103 /// The iterator base class. |
96 /// The iterator base class. |
104 typedef MapIteratorBase<Map> Base; |
97 typedef MapIteratorBase<_Graph, _Item> Parent; |
105 |
98 |
106 /// The key type of the iterator. |
99 typedef _Item Item; |
107 typedef typename Map::Key Key; |
100 typedef _Map Map; |
108 /// The iterator to iterate on the keys. |
101 typedef _Graph Graph; |
109 typedef typename Map::KeyIt KeyIt; |
102 |
|
103 protected: |
|
104 |
|
105 typedef typename Parent::ItemIt ItemIt; |
|
106 |
|
107 typedef typename ReferenceMapTraits<_Map>::Value MapValue; |
|
108 typedef typename ReferenceMapTraits<_Map>::Reference MapReference; |
|
109 |
|
110 public: |
110 |
111 |
111 /// The value type of the iterator. |
112 /// The value type of the iterator. |
112 typedef typename Map::Value Value; |
113 typedef extended_pair<Item, const Item&, |
113 /// The reference type of the iterator. |
114 MapValue, const MapValue&> Value; |
114 typedef typename Map::Reference Reference; |
|
115 /// The pointer type of the iterator. |
|
116 typedef typename Map::Pointer Pointer; |
|
117 |
|
118 /// The const value type of the iterator. |
|
119 typedef typename Map::ConstValue ConstValue; |
|
120 /// The const reference type of the iterator. |
|
121 typedef typename Map::ConstReference ConstReference; |
|
122 /// The pointer type of the iterator. |
|
123 typedef typename Map::ConstPointer ConstPointer; |
|
124 |
|
125 public: |
|
126 |
|
127 /// The value type of the iterator. |
|
128 typedef extended_pair<Key, const Key&, |
|
129 Value, const Value&> PairValue; |
|
130 |
115 |
131 /// The reference type of the iterator. |
116 /// The reference type of the iterator. |
132 typedef extended_pair<const Key&, const Key&, |
117 typedef extended_pair<const Item&, const Item&, |
133 Reference, Reference> PairReference; |
118 MapReference, MapReference> Reference; |
134 |
119 |
135 /// Default constructor. |
120 /// Default constructor. |
136 MapIterator() {} |
121 MapIterator() {} |
137 |
122 |
138 /// Constructor to initalize the iterators returned |
123 /// Constructor to initalize the iterators returned |
139 /// by the begin() and end(). |
124 /// by the begin() and end(). |
140 MapIterator(Map& pmap, const KeyIt& pit) : Base(pit), map(&pmap) {} |
125 MapIterator(Map& _map, const ItemIt& _it) |
|
126 : Parent(_it), map(&_map) {} |
141 |
127 |
142 /// Dereference operator for the iterator. |
128 /// Dereference operator for the iterator. |
143 PairReference operator*() { |
129 Reference operator*() { |
144 return PairReference(Base::it, (*map)[Base::it]); |
130 return Reference(Parent::it, (*map)[Parent::it]); |
145 } |
131 } |
146 |
132 |
147 /// The pointer type of the iterator. |
133 /// The pointer type of the iterator. |
148 class PairPointer { |
134 class Pointer { |
149 friend class MapIterator; |
135 friend class MapIterator; |
150 private: |
136 protected: |
151 PairReference data; |
137 Reference data; |
152 PairPointer(const Key& key, Reference val) |
138 Pointer(const Item& item, MapReference val) |
153 : data(key, val) {} |
139 : data(item, val) {} |
154 public: |
140 public: |
155 PairReference* operator->() {return &data;} |
141 Reference* operator->() {return &data;} |
156 }; |
142 }; |
157 |
143 |
158 /// Arrow operator for the iterator. |
144 /// Arrow operator for the iterator. |
159 PairPointer operator->() { |
145 Pointer operator->() { |
160 return PairPointer(Base::it, ((*map)[Base::it])); |
146 return Pointer(Parent::it, (*map)[Parent::it]); |
161 } |
147 } |
162 |
148 |
163 /// The pre increment operator of the iterator. |
149 /// The pre increment operator of the iterator. |
164 MapIterator& operator++() { |
150 MapIterator& operator++() { |
165 Base::increment(); |
151 Parent::increment(); |
166 return *this; |
152 return *this; |
167 } |
153 } |
168 |
154 |
169 /// The post increment operator of the iterator. |
155 /// The post increment operator of the iterator. |
170 MapIterator operator++(int) { |
156 MapIterator operator++(int) { |
171 MapIterator tmp(*this); |
157 MapIterator tmp(*this); |
172 Base::increment(); |
158 Parent::increment(); |
173 return tmp; |
159 return tmp; |
174 } |
160 } |
175 |
161 |
176 private: |
162 protected: |
|
163 |
177 Map* map; |
164 Map* map; |
178 |
165 |
179 public: |
166 public: |
180 // STL compatibility typedefs. |
167 // STL compatibility typedefs. |
181 typedef std::forward_iterator_tag iterator_category; |
168 typedef std::forward_iterator_tag iterator_category; |
182 typedef int difference_type; |
169 typedef int difference_type; |
183 typedef PairValue value_type; |
170 typedef Value value_type; |
184 typedef PairReference reference; |
171 typedef Reference reference; |
185 typedef PairPointer pointer; |
172 typedef Pointer pointer; |
186 }; |
173 }; |
187 |
174 |
188 /** Compatible iterator with the stl maps' iterators. |
175 /** Compatible iterator with the stl maps' iterators. |
189 * It iterates on pairs of a key and a value. |
176 * It iterates on pairs of a key and a value. |
190 */ |
177 */ |
191 template <typename Map> |
178 template < |
192 class MapConstIterator : public MapIteratorBase<Map> { |
179 typename _Graph, |
193 |
180 typename _Item, |
|
181 typename _Map> |
|
182 class MapConstIterator : public MapIteratorBase<_Graph, _Item> { |
|
183 |
194 public: |
184 public: |
195 |
185 |
196 /// The iterator base class. |
186 /// The iterator base class. |
197 typedef MapIteratorBase<Map> Base; |
187 typedef MapIteratorBase<_Graph, _Item> Parent; |
198 |
188 |
199 /// The key type of the iterator. |
189 typedef _Graph Graph; |
200 typedef typename Map::Key Key; |
190 typedef _Item Item; |
201 /// The iterator to iterate on the keys. |
191 typedef _Map Map; |
202 typedef typename Map::KeyIt KeyIt; |
192 |
|
193 protected: |
|
194 |
|
195 typedef typename Parent::ItemIt ItemIt; |
|
196 |
|
197 typedef typename ReferenceMapTraits<_Map>::Value MapValue; |
|
198 typedef typename ReferenceMapTraits<_Map>::ConstReference |
|
199 MapReference; |
|
200 |
|
201 public: |
203 |
202 |
204 /// The value type of the iterator. |
203 /// The value type of the iterator. |
205 typedef typename Map::Value Value; |
204 typedef extended_pair<Item, const Item&, |
206 /// The reference type of the iterator. |
205 MapValue, const MapValue&> Value; |
207 typedef typename Map::Reference Reference; |
206 |
208 /// The pointer type of the iterator. |
207 /// The reference type of the iterator. |
209 typedef typename Map::Pointer Pointer; |
208 typedef extended_pair<const Item&, const Item&, |
210 |
209 MapReference, MapReference> Reference; |
211 /// The const value type of the iterator. |
|
212 typedef typename Map::ConstValue ConstValue; |
|
213 /// The const reference type of the iterator. |
|
214 typedef typename Map::ConstReference ConstReference; |
|
215 /// The pointer type of the iterator. |
|
216 typedef typename Map::ConstPointer ConstPointer; |
|
217 |
|
218 public: |
|
219 |
210 |
220 /// Default constructor. |
211 /// Default constructor. |
221 MapConstIterator() {} |
212 MapConstIterator() {} |
222 |
213 |
223 /// Constructor to initalize the the iterators returned |
214 /// Constructor to initalize the iterators returned |
224 /// by the begin() and end(). |
215 /// by the begin() and end(). |
225 MapConstIterator(const Map& pmap, const KeyIt& pit) |
216 MapConstIterator(const Map& _map, const ItemIt& _it) |
226 : Base(pit), map(&pmap) {} |
217 : Parent(_it), map(&_map) {} |
227 |
|
228 /// Constructor to create const iterator from a non const. |
|
229 MapConstIterator(const MapIterator<Map>& pit) { |
|
230 Base::it = pit.Base::it; |
|
231 map = pit.map; |
|
232 } |
|
233 |
|
234 /// The value type of the iterator. |
|
235 typedef extended_pair<Key, const Key&, |
|
236 Value, const Value&> PairValue; |
|
237 |
|
238 /// The reference type of map. |
|
239 typedef extended_pair<const Key&, const Key&, |
|
240 ConstReference, ConstReference> PairReference; |
|
241 |
218 |
242 /// Dereference operator for the iterator. |
219 /// Dereference operator for the iterator. |
243 PairReference operator*() { |
220 Reference operator*() { |
244 return PairReference(Base::it, (*map)[Base::it]); |
221 return Reference(Parent::it, (*map)[Parent::it]); |
245 } |
222 } |
246 |
223 |
247 /// The pointer type of the iterator. |
224 /// The pointer type of the iterator. |
248 class PairPointer { |
225 class Pointer { |
249 friend class MapConstIterator; |
226 friend class MapConstIterator; |
250 private: |
227 protected: |
251 PairReference data; |
228 Reference data; |
252 PairPointer(const Key& key, ConstReference val) |
229 Pointer(const Item& item, MapReference val) |
253 : data(key, val) {} |
230 : data(item, val) {} |
254 public: |
231 public: |
255 PairReference* operator->() {return &data;} |
232 Reference* operator->() {return &data;} |
256 }; |
233 }; |
257 |
234 |
258 /// Arrow operator for the iterator. |
235 /// Arrow operator for the iterator. |
259 PairPointer operator->() { |
236 Pointer operator->() { |
260 return PairPointer(Base::it, (*map)[Base::it]); |
237 return Pointer(Parent::it, ((*map)[Parent::it])); |
261 } |
238 } |
262 |
239 |
263 /// The pre increment operator of the iterator. |
240 /// The pre increment operator of the iterator. |
264 MapConstIterator& operator++() { |
241 MapConstIterator& operator++() { |
265 Base::increment(); |
242 Parent::increment(); |
266 return *this; |
243 return *this; |
267 } |
244 } |
268 |
245 |
269 /// The post increment operator of the iterator. |
246 /// The post increment operator of the iterator. |
270 MapConstIterator operator++(int) { |
247 MapConstIterator operator++(int) { |
271 MapConstIterator tmp(*this); |
248 MapConstIterator tmp(*this); |
272 Base::increment(); |
249 Parent::increment(); |
273 return tmp; |
250 return tmp; |
274 } |
251 } |
275 |
252 |
276 private: |
253 protected: |
277 const Map* map; |
254 const Map* map; |
278 |
255 |
279 public: |
256 public: |
280 // STL compatibility typedefs. |
257 // STL compatibility typedefs. |
281 typedef std::input_iterator_tag iterator_category; |
258 typedef std::forward_iterator_tag iterator_category; |
282 typedef int difference_type; |
259 typedef int difference_type; |
283 typedef PairValue value_type; |
260 typedef Value value_type; |
284 typedef PairReference reference; |
261 typedef Reference reference; |
285 typedef PairPointer pointer; |
262 typedef Pointer pointer; |
286 }; |
263 }; |
287 |
264 |
288 /** The class makes the KeyIt to an stl compatible iterator |
265 /** The class makes the ItemIt to an stl compatible iterator |
289 * with dereferencing operator. |
266 * with dereferencing operator. |
290 */ |
267 */ |
291 template <typename Map> |
268 template < |
292 class MapKeyIterator : public MapIteratorBase<Map> { |
269 typename _Graph, |
|
270 typename _Item> |
|
271 class MapConstKeyIterator : public MapIteratorBase<_Graph, _Item> { |
293 |
272 |
294 public: |
273 public: |
295 |
274 |
296 /// The iterator base class. |
275 /// The iterator base class. |
297 typedef MapIteratorBase<Map> Base; |
276 typedef MapIteratorBase<_Graph, _Item> Parent; |
298 |
277 |
299 /// The key type of the iterator. |
278 typedef _Graph Graph; |
300 typedef typename Map::Key Key; |
279 typedef _Item Item; |
|
280 |
|
281 protected: |
301 /// The iterator to iterate on the keys. |
282 /// The iterator to iterate on the keys. |
302 typedef typename Map::KeyIt KeyIt; |
283 typedef typename Parent::ItemIt ItemIt; |
303 |
284 |
304 public: |
285 public: |
|
286 |
|
287 typedef Item Value; |
|
288 typedef const Item& Reference; |
|
289 typedef const Item* Pointer; |
305 |
290 |
306 /// Default constructor. |
291 /// Default constructor. |
307 MapKeyIterator() {} |
292 MapConstKeyIterator() {} |
308 |
293 |
309 /// KeyIt initialized iterator. |
294 /// ItemIt initialized iterator. |
310 MapKeyIterator(const KeyIt& pit) : Base(pit) {} |
295 MapConstKeyIterator(const ItemIt& pit) : Parent(pit) {} |
311 |
296 |
312 /// The pre increment operator of the iterator. |
297 /// The pre increment operator of the iterator. |
313 MapKeyIterator& operator++() { |
298 MapConstKeyIterator& operator++() { |
314 Base::increment(); |
299 Parent::increment(); |
315 return *this; |
300 return *this; |
316 } |
301 } |
317 |
302 |
318 /// The post increment operator of the iterator. |
303 /// The post increment operator of the iterator. |
319 MapKeyIterator operator++(int) { |
304 MapConstKeyIterator operator++(int) { |
320 MapKeyIterator tmp(*this); |
305 MapConstKeyIterator tmp(*this); |
321 Base::increment(); |
306 Parent::increment(); |
322 return tmp; |
307 return tmp; |
323 } |
308 } |
324 |
309 |
325 /// The dereferencing operator of the iterator. |
310 /// The dereferencing operator of the iterator. |
326 Key operator*() const { |
311 Item operator*() const { |
327 return static_cast<Key>(Base::it); |
312 return static_cast<Item>(Parent::it); |
328 } |
313 } |
329 |
314 |
330 public: |
315 public: |
331 // STL compatibility typedefs. |
316 // STL compatibility typedefs. |
332 typedef std::input_iterator_tag iterator_category; |
317 typedef std::input_iterator_tag iterator_category; |
333 typedef int difference_type; |
318 typedef int difference_type; |
334 typedef Key value_type; |
319 typedef Value value_type; |
335 typedef const Key& reference; |
320 typedef Reference reference; |
336 typedef const Key* pointer; |
321 typedef Pointer pointer; |
337 }; |
322 }; |
338 |
323 |
339 template <typename Map> class MapConstValueIterator; |
324 template < |
|
325 typename _Graph, |
|
326 typename _Item, |
|
327 typename _Map> |
|
328 class MapConstValueIterator; |
340 |
329 |
341 /** MapValueIterator creates an stl compatible iterator |
330 /** MapValueIterator creates an stl compatible iterator |
342 * for the values. |
331 * for the values. |
343 */ |
332 */ |
344 template <typename Map> |
333 template < |
345 class MapValueIterator : public MapIteratorBase<Map> { |
334 typename _Graph, |
346 |
335 typename _Item, |
347 friend class MapConstValueIterator<Map>; |
336 typename _Map> |
|
337 class MapValueIterator : public MapIteratorBase<_Graph, _Item> { |
|
338 |
|
339 friend class MapConstValueIterator<_Graph, _Item, _Map>; |
348 |
340 |
349 public: |
341 public: |
350 |
342 |
351 /// The iterator base class. |
343 /// The iterator base class. |
352 typedef MapIteratorBase<Map> Base; |
344 typedef MapIteratorBase<_Graph, _Item> Parent; |
353 |
345 |
354 /// The key type of the iterator. |
346 typedef _Graph Graph; |
355 typedef typename Map::Key Key; |
347 typedef _Item Item; |
|
348 typedef _Map Map; |
|
349 |
|
350 protected: |
|
351 |
356 /// The iterator to iterate on the keys. |
352 /// The iterator to iterate on the keys. |
357 typedef typename Map::KeyIt KeyIt; |
353 typedef typename Parent::ItemIt ItemIt; |
358 |
|
359 |
354 |
360 /// The value type of the iterator. |
355 /// The value type of the iterator. |
361 typedef typename Map::Value Value; |
356 typedef typename ReferenceMapTraits<Map>::Value MapValue; |
362 /// The reference type of the iterator. |
357 /// The reference type of the iterator. |
363 typedef typename Map::Reference Reference; |
358 typedef typename ReferenceMapTraits<Map>::Reference MapReference; |
364 /// The pointer type of the iterator. |
359 /// The pointer type of the iterator. |
365 typedef typename Map::Pointer Pointer; |
360 typedef typename ReferenceMapTraits<Map>::Pointer MapPointer; |
366 |
361 |
367 /// The const value type of the iterator. |
362 public: |
368 typedef typename Map::ConstValue ConstValue; |
363 |
369 /// The const reference type of the iterator. |
364 typedef MapValue Value; |
370 typedef typename Map::ConstReference ConstReference; |
365 typedef MapReference Reference; |
371 /// The pointer type of the iterator. |
366 typedef MapPointer Pointer; |
372 typedef typename Map::ConstPointer ConstPointer; |
|
373 |
|
374 private: |
|
375 |
|
376 Map* map; |
|
377 |
|
378 public: |
|
379 |
367 |
380 /// Default constructor. |
368 /// Default constructor. |
381 MapValueIterator() {} |
369 MapValueIterator() {} |
382 |
370 |
383 /// Map and KeyIt initialized iterator. |
371 /// Map and ItemIt initialized iterator. |
384 MapValueIterator(Map& pmap, const KeyIt& pit) |
372 MapValueIterator(Map& _map, const ItemIt& _it) |
385 : Base(pit), map(&pmap) {} |
373 : Parent(_it), map(&_map) {} |
386 |
374 |
387 |
375 |
388 /// The pre increment operator of the iterator. |
376 /// The pre increment operator of the iterator. |
389 MapValueIterator& operator++() { |
377 MapValueIterator& operator++() { |
390 Base::increment(); |
378 Parent::increment(); |
391 return *this; |
379 return *this; |
392 } |
380 } |
393 |
381 |
394 /// The post increment operator of the iterator. |
382 /// The post increment operator of the iterator. |
395 MapValueIterator operator++(int) { |
383 MapValueIterator operator++(int) { |
396 MapValueIterator tmp(*this); |
384 MapValueIterator tmp(*this); |
397 Base::increment(); |
385 Parent::increment(); |
398 return tmp; |
386 return tmp; |
399 } |
387 } |
400 |
388 |
401 /// The dereferencing operator of the iterator. |
389 /// The dereferencing operator of the iterator. |
402 Reference operator*() const { |
390 Reference operator*() const { |
403 return (*map)[Base::it]; |
391 return (*map)[Parent::it]; |
404 } |
392 } |
405 |
393 |
406 /// The arrow operator of the iterator. |
394 /// The arrow operator of the iterator. |
407 Pointer operator->() const { |
395 Pointer operator->() const { |
408 return &(operator*()); |
396 return &(operator*()); |
409 } |
397 } |
410 |
398 |
|
399 protected: |
|
400 |
|
401 Map* map; |
|
402 |
411 public: |
403 public: |
412 // STL compatibility typedefs. |
404 // STL compatibility typedefs. |
413 typedef std::forward_iterator_tag iterator_category; |
405 typedef std::forward_iterator_tag iterator_category; |
414 typedef int difference_type; |
406 typedef int difference_type; |
415 typedef Value value_type; |
407 typedef Value value_type; |
416 typedef Reference reference; |
408 typedef Reference reference; |
417 typedef Pointer pointer; |
409 typedef Pointer pointer; |
418 }; |
410 }; |
419 |
411 |
420 /** MapValueIterator creates an stl compatible iterator |
412 /** MapValueIterator creates an stl compatible iterator |
421 * for the const values. |
413 * for the values. |
422 */ |
414 */ |
423 |
415 template < |
424 template <typename Map> |
416 typename _Graph, |
425 class MapConstValueIterator : public MapIteratorBase<Map> { |
417 typename _Item, |
|
418 typename _Map> |
|
419 class MapConstValueIterator : public MapIteratorBase<_Graph, _Item> { |
426 |
420 |
427 public: |
421 public: |
428 |
422 |
429 /// The iterator base class. |
423 /// The iterator base class. |
430 typedef MapIteratorBase<Map> Base; |
424 typedef MapIteratorBase<_Graph, _Item> Parent; |
431 |
425 |
432 /// The key type of the iterator. |
426 typedef _Graph Graph; |
433 typedef typename Map::Key Key; |
427 typedef _Item Item; |
|
428 typedef _Map Map; |
|
429 |
|
430 protected: |
|
431 |
434 /// The iterator to iterate on the keys. |
432 /// The iterator to iterate on the keys. |
435 typedef typename Map::KeyIt KeyIt; |
433 typedef typename Parent::ItemIt ItemIt; |
436 |
434 |
437 /// The value type of the iterator. |
435 /// The value type of the iterator. |
438 typedef typename Map::Value Value; |
436 typedef typename ReferenceMapTraits<Map>::Value MapValue; |
439 /// The reference type of the iterator. |
437 /// The reference type of the iterator. |
440 typedef typename Map::Reference Reference; |
438 typedef typename ReferenceMapTraits<Map>::ConstReference MapReference; |
441 /// The pointer type of the iterator. |
439 /// The pointer type of the iterator. |
442 typedef typename Map::Pointer Pointer; |
440 typedef typename ReferenceMapTraits<Map>::ConstPointer MapPointer; |
443 |
441 |
444 /// The const value type of the iterator. |
442 public: |
445 typedef typename Map::ConstValue ConstValue; |
443 |
446 /// The const reference type of the iterator. |
444 typedef MapValue Value; |
447 typedef typename Map::ConstReference ConstReference; |
445 typedef MapReference Reference; |
448 /// The pointer type of the iterator. |
446 typedef MapPointer Pointer; |
449 typedef typename Map::ConstPointer ConstPointer; |
|
450 |
|
451 private: |
|
452 |
|
453 const Map* map; |
|
454 |
|
455 public: |
|
456 |
447 |
457 /// Default constructor. |
448 /// Default constructor. |
458 MapConstValueIterator() {} |
449 MapConstValueIterator() {} |
459 |
450 |
460 /// Constructor to create const iterator from a non const. |
451 /// Map and ItemIt initialized iterator. |
461 MapConstValueIterator(const MapValueIterator<Map>& pit) { |
452 MapConstValueIterator(const Map& _map, const ItemIt& _it) |
462 Base::it = pit.Base::it; |
453 : Parent(_it), map(&_map) {} |
463 map = pit.map; |
454 |
464 } |
|
465 |
|
466 /// Map and KeyIt initialized iterator. |
|
467 MapConstValueIterator(const Map& pmap, const KeyIt& pit) |
|
468 : Base(pit), map(&pmap) {} |
|
469 |
455 |
470 /// The pre increment operator of the iterator. |
456 /// The pre increment operator of the iterator. |
471 MapConstValueIterator& operator++() { |
457 MapConstValueIterator& operator++() { |
472 Base::increment(); |
458 Parent::increment(); |
473 return *this; |
459 return *this; |
474 } |
460 } |
475 |
461 |
476 /// The post increment operator of the iterator. |
462 /// The post increment operator of the iterator. |
477 MapConstValueIterator operator++(int) { |
463 MapConstValueIterator operator++(int) { |
478 MapConstValueIterator tmp(*this); |
464 MapConstValueIterator tmp(*this); |
479 Base::increment(); |
465 Parent::increment(); |
480 return tmp; |
466 return tmp; |
481 } |
467 } |
482 |
468 |
483 /// The dereferencing operator of the iterator. |
469 /// The dereferencing operator of the iterator. |
484 ConstReference operator*() const { |
470 Reference operator*() const { |
485 return (*map)[Base::it]; |
471 return (*map)[Parent::it]; |
486 } |
472 } |
487 |
473 |
488 /// The arrow operator of the iterator. |
474 /// The arrow operator of the iterator. |
489 ConstPointer operator->() const { |
475 Pointer operator->() const { |
490 return &(operator*()); |
476 return &(operator*()); |
491 } |
477 } |
492 |
478 |
493 public: |
479 protected: |
494 // STL compatibility typedefs. |
480 |
495 typedef std::input_iterator_tag iterator_category; |
481 const Map* map; |
496 typedef int difference_type; |
482 |
497 typedef Value value_type; |
483 public: |
498 typedef ConstReference reference; |
484 // STL compatibility typedefs. |
499 typedef ConstPointer pointer; |
485 typedef std::forward_iterator_tag iterator_category; |
|
486 typedef int difference_type; |
|
487 typedef Value value_type; |
|
488 typedef Reference reference; |
|
489 typedef Pointer pointer; |
500 }; |
490 }; |
501 |
491 |
502 |
492 |
503 /** This class makes from a map an iteratable set |
493 /** This class makes from a map an iteratable set |
504 * which contains all the keys of the map. |
494 * which contains all the keys of the map. |
505 */ |
495 */ |
506 template <typename Map> |
496 template <typename _Graph, typename _Item> |
507 class MapConstKeySet { |
497 class MapConstKeySet { |
508 |
498 |
509 const Map* map; |
499 public: |
510 |
500 |
511 public: |
501 typedef _Graph Graph; |
512 |
|
513 /// The key type of the iterator. |
502 /// The key type of the iterator. |
514 typedef typename Map::Key Key; |
503 typedef _Item Item; |
515 /// The iterator to iterate on the keys. |
504 /// The iterator to iterate on the keys. |
516 typedef typename Map::KeyIt KeyIt; |
505 |
517 |
506 protected: |
518 |
507 |
519 /// The value type of the iterator. |
508 typedef typename ItemSetTraits<_Graph, _Item>::ItemIt ItemIt; |
520 typedef typename Map::Value Value; |
509 |
|
510 public: |
|
511 |
|
512 /// The map initialized const key set. |
|
513 MapConstKeySet(const Graph& _graph) : graph(&_graph) {} |
|
514 |
|
515 /// The const iterator of the set. |
|
516 typedef MapConstKeyIterator<_Graph, _Item> ConstIterator; |
|
517 |
|
518 typedef typename ConstIterator::Value Value; |
521 /// The reference type of the iterator. |
519 /// The reference type of the iterator. |
522 typedef typename Map::Reference Reference; |
520 typedef typename ConstIterator::Reference ConstReference; |
523 /// The pointer type of the iterator. |
521 /// The pointer type of the iterator. |
524 typedef typename Map::Pointer Pointer; |
522 typedef typename ConstIterator::Pointer ConstPointer; |
525 |
|
526 /// The const value type of the iterator. |
|
527 typedef typename Map::ConstValue ConstValue; |
|
528 /// The const reference type of the iterator. |
|
529 typedef typename Map::ConstReference ConstReference; |
|
530 /// The pointer type of the iterator. |
|
531 typedef typename Map::ConstPointer ConstPointer; |
|
532 |
|
533 /// The map initialized const key set. |
|
534 MapConstKeySet(const Map& pmap) : map(&pmap) {} |
|
535 |
|
536 /// The const iterator of the set. |
|
537 typedef MapKeyIterator<Map> ConstIterator; |
|
538 |
523 |
539 /// It gives back the const iterator pointed to the first element. |
524 /// It gives back the const iterator pointed to the first element. |
540 ConstIterator begin() const { |
525 ConstIterator begin() const { |
541 return ConstIterator(KeyIt(*map->getGraph())); |
526 return ConstIterator(ItemIt(*graph)); |
542 } |
527 } |
543 |
528 |
544 /// It gives back the const iterator pointed to the first ivalid element. |
529 /// It gives back the const iterator pointed to the first ivalid element. |
545 ConstIterator end() const { |
530 ConstIterator end() const { |
546 return ConstIterator(KeyIt(INVALID)); |
531 return ConstIterator(ItemIt(INVALID)); |
547 } |
532 } |
|
533 |
|
534 protected: |
|
535 |
|
536 const Graph* graph; |
548 |
537 |
549 public: |
538 public: |
550 // STL compatibility typedefs. |
539 // STL compatibility typedefs. |
551 typedef Value value_type; |
540 typedef Value value_type; |
552 typedef ConstIterator const_iterator; |
541 typedef ConstIterator const_iterator; |