alpar@906
|
1 |
/* -*- C++ -*-
|
alpar@906
|
2 |
* src/hugo/map_iterator.h - Part of HUGOlib, a generic C++ optimization library
|
alpar@906
|
3 |
*
|
alpar@906
|
4 |
* Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@906
|
5 |
* (Egervary Combinatorial Optimization Research Group, EGRES).
|
alpar@906
|
6 |
*
|
alpar@906
|
7 |
* Permission to use, modify and distribute this software is granted
|
alpar@906
|
8 |
* provided that this copyright notice appears in all copies. For
|
alpar@906
|
9 |
* precise terms see the accompanying LICENSE file.
|
alpar@906
|
10 |
*
|
alpar@906
|
11 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@906
|
12 |
* express or implied, and with no claim as to its suitability for any
|
alpar@906
|
13 |
* purpose.
|
alpar@906
|
14 |
*
|
alpar@906
|
15 |
*/
|
alpar@906
|
16 |
|
marci@901
|
17 |
#ifndef HUGO_MAP_ITERATOR_H
|
marci@901
|
18 |
#define HUGO_MAP_ITERATOR_H
|
deba@822
|
19 |
|
deba@844
|
20 |
#include <iterator>
|
deba@844
|
21 |
|
deba@822
|
22 |
#include <hugo/extended_pair.h>
|
deba@822
|
23 |
|
deba@830
|
24 |
///\ingroup graphmaps
|
deba@830
|
25 |
///\file
|
deba@830
|
26 |
///\brief Iterators on the maps.
|
deba@830
|
27 |
|
deba@822
|
28 |
namespace hugo {
|
deba@822
|
29 |
|
deba@830
|
30 |
/// \addtogroup graphmaps
|
deba@830
|
31 |
/// @{
|
deba@830
|
32 |
|
deba@830
|
33 |
/** The base class all of the map iterators.
|
deba@830
|
34 |
* The class defines the typedefs of the iterators,
|
deba@830
|
35 |
* simple step functions and equality operators.
|
deba@830
|
36 |
*/
|
deba@822
|
37 |
|
deba@822
|
38 |
template <typename Map>
|
deba@830
|
39 |
class MapIteratorBase {
|
deba@822
|
40 |
|
deba@830
|
41 |
public:
|
deba@844
|
42 |
|
deba@830
|
43 |
/// The key type of the iterator.
|
deba@830
|
44 |
typedef typename Map::KeyType KeyType;
|
deba@830
|
45 |
/// The iterator to iterate on the keys.
|
deba@830
|
46 |
typedef typename Map::KeyIt KeyIt;
|
deba@830
|
47 |
|
deba@830
|
48 |
/// The value type of the iterator.
|
deba@830
|
49 |
typedef typename Map::ValueType ValueType;
|
deba@830
|
50 |
/// The reference type of the iterator.
|
deba@830
|
51 |
typedef typename Map::ReferenceType ReferenceType;
|
deba@830
|
52 |
/// The pointer type of the iterator.
|
deba@830
|
53 |
typedef typename Map::PointerType PointerType;
|
deba@830
|
54 |
|
deba@830
|
55 |
/// The const value type of the iterator.
|
deba@830
|
56 |
typedef typename Map::ConstValueType ConstValueType;
|
deba@830
|
57 |
/// The const reference type of the iterator.
|
deba@830
|
58 |
typedef typename Map::ConstReferenceType ConstReferenceType;
|
deba@830
|
59 |
/// The pointer type of the iterator.
|
deba@830
|
60 |
typedef typename Map::ConstPointerType ConstPointerType;
|
deba@830
|
61 |
|
deba@830
|
62 |
protected:
|
deba@830
|
63 |
|
deba@830
|
64 |
KeyIt it;
|
deba@830
|
65 |
|
deba@830
|
66 |
/// Default constructor.
|
deba@830
|
67 |
MapIteratorBase() {}
|
deba@830
|
68 |
|
deba@830
|
69 |
/// KeyIt initialized MapIteratorBase constructor.
|
deba@830
|
70 |
MapIteratorBase(const KeyIt pit) : it(pit) {}
|
deba@830
|
71 |
|
deba@830
|
72 |
public:
|
deba@830
|
73 |
|
deba@830
|
74 |
/// Stepping forward in the map.
|
deba@830
|
75 |
void increment() {
|
deba@830
|
76 |
++it;
|
deba@830
|
77 |
}
|
deba@830
|
78 |
|
deba@830
|
79 |
/// The equality operator of the map.
|
deba@830
|
80 |
bool operator==(const MapIteratorBase& pit) const {
|
deba@830
|
81 |
return pit.it == it;
|
deba@830
|
82 |
}
|
deba@830
|
83 |
|
deba@830
|
84 |
/// The not-equality operator of the map.
|
deba@830
|
85 |
bool operator!=(const MapIteratorBase& pit) const {
|
deba@830
|
86 |
return !(*this == pit);
|
deba@830
|
87 |
}
|
deba@830
|
88 |
};
|
deba@830
|
89 |
|
deba@830
|
90 |
template <typename Map> class MapConstIterator;
|
deba@822
|
91 |
|
deba@822
|
92 |
/** Compatible iterator with the stl maps' iterators.
|
deba@830
|
93 |
* It iterates on pairs of a key and a value.
|
deba@822
|
94 |
*/
|
deba@822
|
95 |
template <typename Map>
|
deba@830
|
96 |
class MapIterator : public MapIteratorBase<Map> {
|
deba@830
|
97 |
|
deba@822
|
98 |
friend class MapConstIterator<Map>;
|
deba@822
|
99 |
|
deba@844
|
100 |
|
deba@822
|
101 |
public:
|
deba@822
|
102 |
|
deba@844
|
103 |
/// The iterator base class.
|
deba@844
|
104 |
typedef MapIteratorBase<Map> Base;
|
deba@844
|
105 |
|
deba@822
|
106 |
/// The key type of the iterator.
|
deba@822
|
107 |
typedef typename Map::KeyType KeyType;
|
deba@822
|
108 |
/// The iterator to iterate on the keys.
|
deba@822
|
109 |
typedef typename Map::KeyIt KeyIt;
|
deba@822
|
110 |
|
deba@822
|
111 |
/// The value type of the iterator.
|
deba@822
|
112 |
typedef typename Map::ValueType ValueType;
|
deba@822
|
113 |
/// The reference type of the iterator.
|
deba@822
|
114 |
typedef typename Map::ReferenceType ReferenceType;
|
deba@822
|
115 |
/// The pointer type of the iterator.
|
deba@822
|
116 |
typedef typename Map::PointerType PointerType;
|
deba@822
|
117 |
|
deba@822
|
118 |
/// The const value type of the iterator.
|
deba@822
|
119 |
typedef typename Map::ConstValueType ConstValueType;
|
deba@822
|
120 |
/// The const reference type of the iterator.
|
deba@822
|
121 |
typedef typename Map::ConstReferenceType ConstReferenceType;
|
deba@822
|
122 |
/// The pointer type of the iterator.
|
deba@822
|
123 |
typedef typename Map::ConstPointerType ConstPointerType;
|
deba@822
|
124 |
|
deba@822
|
125 |
public:
|
deba@822
|
126 |
|
deba@844
|
127 |
/// The value type of the iterator.
|
deba@844
|
128 |
typedef extended_pair<KeyType, const KeyType&,
|
deba@844
|
129 |
ValueType, const ValueType&> PairValueType;
|
deba@844
|
130 |
|
deba@830
|
131 |
/// The reference type of the iterator.
|
deba@822
|
132 |
typedef extended_pair<const KeyType&, const KeyType&,
|
deba@822
|
133 |
ReferenceType, ReferenceType> PairReferenceType;
|
deba@822
|
134 |
|
deba@830
|
135 |
/// Default constructor.
|
deba@830
|
136 |
MapIterator() {}
|
deba@830
|
137 |
|
deba@830
|
138 |
/// Constructor to initalize the iterators returned
|
deba@830
|
139 |
/// by the begin() and end().
|
deba@844
|
140 |
MapIterator(Map& pmap, const KeyIt& pit) : Base(pit), map(&pmap) {}
|
deba@830
|
141 |
|
deba@830
|
142 |
/// Dereference operator for the iterator.
|
deba@822
|
143 |
PairReferenceType operator*() {
|
deba@844
|
144 |
return PairReferenceType(Base::it, (*map)[Base::it]);
|
deba@822
|
145 |
}
|
deba@822
|
146 |
|
deba@830
|
147 |
/// The pointer type of the iterator.
|
deba@822
|
148 |
class PairPointerType {
|
deba@822
|
149 |
friend class MapIterator;
|
deba@822
|
150 |
private:
|
deba@822
|
151 |
PairReferenceType data;
|
deba@822
|
152 |
PairPointerType(const KeyType& key, ReferenceType val)
|
deba@822
|
153 |
: data(key, val) {}
|
deba@822
|
154 |
public:
|
deba@822
|
155 |
PairReferenceType* operator->() {return &data;}
|
deba@822
|
156 |
};
|
deba@822
|
157 |
|
deba@830
|
158 |
/// Arrow operator for the iterator.
|
deba@822
|
159 |
PairPointerType operator->() {
|
deba@844
|
160 |
return PairPointerType(Base::it, ((*map)[Base::it]));
|
deba@822
|
161 |
}
|
deba@830
|
162 |
|
deba@830
|
163 |
/// The pre increment operator of the iterator.
|
deba@822
|
164 |
MapIterator& operator++() {
|
deba@844
|
165 |
Base::increment();
|
deba@822
|
166 |
return *this;
|
deba@822
|
167 |
}
|
deba@822
|
168 |
|
deba@830
|
169 |
/// The post increment operator of the iterator.
|
deba@822
|
170 |
MapIterator operator++(int) {
|
deba@844
|
171 |
MapIterator tmp(*this);
|
deba@844
|
172 |
Base::increment();
|
deba@822
|
173 |
return tmp;
|
deba@822
|
174 |
}
|
deba@822
|
175 |
|
deba@822
|
176 |
private:
|
deba@822
|
177 |
Map* map;
|
deba@844
|
178 |
|
deba@844
|
179 |
public:
|
deba@844
|
180 |
// STL compatibility typedefs.
|
deba@844
|
181 |
typedef std::forward_iterator_tag iterator_category;
|
deba@844
|
182 |
typedef int difference_type;
|
deba@844
|
183 |
typedef PairValueType value_type;
|
deba@844
|
184 |
typedef PairReferenceType reference;
|
deba@844
|
185 |
typedef PairPointerType pointer;
|
deba@822
|
186 |
};
|
deba@822
|
187 |
|
deba@822
|
188 |
/** Compatible iterator with the stl maps' iterators.
|
deba@822
|
189 |
* It iterates on pairs of a key and a value.
|
deba@822
|
190 |
*/
|
deba@822
|
191 |
template <typename Map>
|
deba@830
|
192 |
class MapConstIterator : public MapIteratorBase<Map> {
|
deba@830
|
193 |
|
deba@822
|
194 |
public:
|
deba@822
|
195 |
|
deba@844
|
196 |
/// The iterator base class.
|
deba@844
|
197 |
typedef MapIteratorBase<Map> Base;
|
deba@844
|
198 |
|
deba@822
|
199 |
/// The key type of the iterator.
|
deba@822
|
200 |
typedef typename Map::KeyType KeyType;
|
deba@822
|
201 |
/// The iterator to iterate on the keys.
|
deba@822
|
202 |
typedef typename Map::KeyIt KeyIt;
|
deba@822
|
203 |
|
deba@822
|
204 |
/// The value type of the iterator.
|
deba@822
|
205 |
typedef typename Map::ValueType ValueType;
|
deba@822
|
206 |
/// The reference type of the iterator.
|
deba@822
|
207 |
typedef typename Map::ReferenceType ReferenceType;
|
deba@822
|
208 |
/// The pointer type of the iterator.
|
deba@822
|
209 |
typedef typename Map::PointerType PointerType;
|
deba@822
|
210 |
|
deba@822
|
211 |
/// The const value type of the iterator.
|
deba@822
|
212 |
typedef typename Map::ConstValueType ConstValueType;
|
deba@822
|
213 |
/// The const reference type of the iterator.
|
deba@822
|
214 |
typedef typename Map::ConstReferenceType ConstReferenceType;
|
deba@822
|
215 |
/// The pointer type of the iterator.
|
deba@822
|
216 |
typedef typename Map::ConstPointerType ConstPointerType;
|
deba@822
|
217 |
|
deba@822
|
218 |
public:
|
deba@822
|
219 |
|
deba@830
|
220 |
/// Default constructor.
|
deba@822
|
221 |
MapConstIterator() {}
|
deba@822
|
222 |
|
deba@830
|
223 |
/// Constructor to initalize the the iterators returned
|
deba@830
|
224 |
/// by the begin() and end().
|
deba@830
|
225 |
MapConstIterator(const Map& pmap, const KeyIt& pit)
|
deba@844
|
226 |
: Base(pit), map(&pmap) {}
|
deba@830
|
227 |
|
deba@830
|
228 |
/// Constructor to create const iterator from a non const.
|
deba@830
|
229 |
MapConstIterator(const MapIterator<Map>& pit) {
|
deba@844
|
230 |
Base::it = pit.Base::it;
|
deba@830
|
231 |
map = pit.map;
|
deba@830
|
232 |
}
|
deba@830
|
233 |
|
deba@844
|
234 |
/// The value type of the iterator.
|
deba@844
|
235 |
typedef extended_pair<KeyType, const KeyType&,
|
deba@844
|
236 |
ValueType, const ValueType&> PairValueType;
|
deba@844
|
237 |
|
deba@830
|
238 |
/// The reference type of map.
|
deba@822
|
239 |
typedef extended_pair<const KeyType&, const KeyType&,
|
deba@822
|
240 |
ConstReferenceType, ConstReferenceType> PairReferenceType;
|
deba@822
|
241 |
|
deba@830
|
242 |
/// Dereference operator for the iterator.
|
deba@822
|
243 |
PairReferenceType operator*() {
|
deba@844
|
244 |
return PairReferenceType(Base::it, (*map)[Base::it]);
|
deba@822
|
245 |
}
|
deba@822
|
246 |
|
deba@830
|
247 |
/// The pointer type of the iterator.
|
deba@822
|
248 |
class PairPointerType {
|
deba@822
|
249 |
friend class MapConstIterator;
|
deba@822
|
250 |
private:
|
deba@822
|
251 |
PairReferenceType data;
|
deba@822
|
252 |
PairPointerType(const KeyType& key, ConstReferenceType val)
|
deba@822
|
253 |
: data(key, val) {}
|
deba@822
|
254 |
public:
|
deba@822
|
255 |
PairReferenceType* operator->() {return &data;}
|
deba@822
|
256 |
};
|
deba@822
|
257 |
|
deba@830
|
258 |
/// Arrow operator for the iterator.
|
deba@822
|
259 |
PairPointerType operator->() {
|
deba@844
|
260 |
return PairPointerType(Base::it, (*map)[Base::it]);
|
deba@822
|
261 |
}
|
deba@822
|
262 |
|
deba@830
|
263 |
/// The pre increment operator of the iterator.
|
deba@822
|
264 |
MapConstIterator& operator++() {
|
deba@844
|
265 |
Base::increment();
|
deba@822
|
266 |
return *this;
|
deba@822
|
267 |
}
|
deba@822
|
268 |
|
deba@830
|
269 |
/// The post increment operator of the iterator.
|
deba@822
|
270 |
MapConstIterator operator++(int) {
|
deba@844
|
271 |
MapConstIterator tmp(*this);
|
deba@844
|
272 |
Base::increment();
|
deba@822
|
273 |
return tmp;
|
deba@822
|
274 |
}
|
deba@822
|
275 |
|
deba@830
|
276 |
private:
|
deba@830
|
277 |
const Map* map;
|
deba@844
|
278 |
|
deba@844
|
279 |
public:
|
deba@844
|
280 |
// STL compatibility typedefs.
|
deba@844
|
281 |
typedef std::input_iterator_tag iterator_category;
|
deba@844
|
282 |
typedef int difference_type;
|
deba@844
|
283 |
typedef PairValueType value_type;
|
deba@844
|
284 |
typedef PairReferenceType reference;
|
deba@844
|
285 |
typedef PairPointerType pointer;
|
deba@830
|
286 |
};
|
deba@830
|
287 |
|
deba@830
|
288 |
/** The class makes the KeyIt to an stl compatible iterator
|
deba@830
|
289 |
* with dereferencing operator.
|
deba@830
|
290 |
*/
|
deba@830
|
291 |
template <typename Map>
|
deba@830
|
292 |
class MapKeyIterator : public MapIteratorBase<Map> {
|
deba@830
|
293 |
|
deba@830
|
294 |
public:
|
deba@830
|
295 |
|
deba@844
|
296 |
/// The iterator base class.
|
deba@844
|
297 |
typedef MapIteratorBase<Map> Base;
|
deba@844
|
298 |
|
deba@830
|
299 |
/// The key type of the iterator.
|
deba@830
|
300 |
typedef typename Map::KeyType KeyType;
|
deba@830
|
301 |
/// The iterator to iterate on the keys.
|
deba@830
|
302 |
typedef typename Map::KeyIt KeyIt;
|
deba@830
|
303 |
|
deba@830
|
304 |
public:
|
deba@830
|
305 |
|
deba@830
|
306 |
/// Default constructor.
|
deba@830
|
307 |
MapKeyIterator() {}
|
deba@830
|
308 |
|
deba@830
|
309 |
/// KeyIt initialized iterator.
|
deba@844
|
310 |
MapKeyIterator(const KeyIt& pit) : Base(pit) {}
|
deba@830
|
311 |
|
deba@830
|
312 |
/// The pre increment operator of the iterator.
|
deba@830
|
313 |
MapKeyIterator& operator++() {
|
deba@844
|
314 |
Base::increment();
|
deba@830
|
315 |
return *this;
|
deba@822
|
316 |
}
|
deba@822
|
317 |
|
deba@830
|
318 |
/// The post increment operator of the iterator.
|
deba@830
|
319 |
MapKeyIterator operator++(int) {
|
deba@830
|
320 |
MapKeyIterator tmp(*this);
|
deba@844
|
321 |
Base::increment();
|
deba@830
|
322 |
return tmp;
|
deba@822
|
323 |
}
|
deba@830
|
324 |
|
deba@830
|
325 |
/// The dereferencing operator of the iterator.
|
deba@830
|
326 |
KeyType operator*() const {
|
deba@844
|
327 |
return static_cast<KeyType>(Base::it);
|
deba@822
|
328 |
}
|
deba@844
|
329 |
|
deba@844
|
330 |
public:
|
deba@844
|
331 |
// STL compatibility typedefs.
|
deba@844
|
332 |
typedef std::input_iterator_tag iterator_category;
|
deba@844
|
333 |
typedef int difference_type;
|
deba@844
|
334 |
typedef KeyType value_type;
|
deba@844
|
335 |
typedef const KeyType& reference;
|
deba@844
|
336 |
typedef const KeyType* pointer;
|
deba@830
|
337 |
};
|
deba@830
|
338 |
|
deba@830
|
339 |
template <typename Map> class MapConstValueIterator;
|
deba@830
|
340 |
|
deba@844
|
341 |
/** MapValueIterator creates an stl compatible iterator
|
deba@844
|
342 |
* for the values.
|
deba@844
|
343 |
*/
|
deba@830
|
344 |
template <typename Map>
|
deba@830
|
345 |
class MapValueIterator : public MapIteratorBase<Map> {
|
deba@830
|
346 |
|
deba@830
|
347 |
friend class MapConstValueIterator<Map>;
|
deba@830
|
348 |
|
deba@830
|
349 |
public:
|
deba@830
|
350 |
|
deba@844
|
351 |
/// The iterator base class.
|
deba@844
|
352 |
typedef MapIteratorBase<Map> Base;
|
deba@844
|
353 |
|
deba@830
|
354 |
/// The key type of the iterator.
|
deba@830
|
355 |
typedef typename Map::KeyType KeyType;
|
deba@830
|
356 |
/// The iterator to iterate on the keys.
|
deba@830
|
357 |
typedef typename Map::KeyIt KeyIt;
|
deba@830
|
358 |
|
deba@830
|
359 |
|
deba@830
|
360 |
/// The value type of the iterator.
|
deba@830
|
361 |
typedef typename Map::ValueType ValueType;
|
deba@830
|
362 |
/// The reference type of the iterator.
|
deba@830
|
363 |
typedef typename Map::ReferenceType ReferenceType;
|
deba@830
|
364 |
/// The pointer type of the iterator.
|
deba@830
|
365 |
typedef typename Map::PointerType PointerType;
|
deba@830
|
366 |
|
deba@830
|
367 |
/// The const value type of the iterator.
|
deba@830
|
368 |
typedef typename Map::ConstValueType ConstValueType;
|
deba@830
|
369 |
/// The const reference type of the iterator.
|
deba@830
|
370 |
typedef typename Map::ConstReferenceType ConstReferenceType;
|
deba@830
|
371 |
/// The pointer type of the iterator.
|
deba@830
|
372 |
typedef typename Map::ConstPointerType ConstPointerType;
|
deba@830
|
373 |
|
deba@822
|
374 |
private:
|
deba@830
|
375 |
|
deba@830
|
376 |
Map* map;
|
deba@830
|
377 |
|
deba@830
|
378 |
public:
|
deba@830
|
379 |
|
deba@830
|
380 |
/// Default constructor.
|
deba@830
|
381 |
MapValueIterator() {}
|
deba@830
|
382 |
|
deba@830
|
383 |
/// Map and KeyIt initialized iterator.
|
deba@830
|
384 |
MapValueIterator(Map& pmap, const KeyIt& pit)
|
deba@844
|
385 |
: Base(pit), map(&pmap) {}
|
deba@830
|
386 |
|
deba@830
|
387 |
|
deba@830
|
388 |
/// The pre increment operator of the iterator.
|
deba@830
|
389 |
MapValueIterator& operator++() {
|
deba@844
|
390 |
Base::increment();
|
deba@830
|
391 |
return *this;
|
deba@830
|
392 |
}
|
deba@830
|
393 |
|
deba@830
|
394 |
/// The post increment operator of the iterator.
|
deba@830
|
395 |
MapValueIterator operator++(int) {
|
deba@830
|
396 |
MapValueIterator tmp(*this);
|
deba@844
|
397 |
Base::increment();
|
deba@830
|
398 |
return tmp;
|
deba@830
|
399 |
}
|
deba@830
|
400 |
|
deba@830
|
401 |
/// The dereferencing operator of the iterator.
|
deba@830
|
402 |
ReferenceType operator*() const {
|
deba@844
|
403 |
return (*map)[Base::it];
|
deba@830
|
404 |
}
|
deba@830
|
405 |
|
deba@830
|
406 |
/// The arrow operator of the iterator.
|
deba@830
|
407 |
PointerType operator->() const {
|
deba@830
|
408 |
return &(operator*());
|
deba@830
|
409 |
}
|
deba@830
|
410 |
|
deba@844
|
411 |
public:
|
deba@844
|
412 |
// STL compatibility typedefs.
|
deba@844
|
413 |
typedef std::forward_iterator_tag iterator_category;
|
deba@844
|
414 |
typedef int difference_type;
|
deba@844
|
415 |
typedef ValueType value_type;
|
deba@844
|
416 |
typedef ReferenceType reference;
|
deba@844
|
417 |
typedef PointerType pointer;
|
deba@830
|
418 |
};
|
deba@830
|
419 |
|
deba@844
|
420 |
/** MapValueIterator creates an stl compatible iterator
|
deba@844
|
421 |
* for the const values.
|
deba@844
|
422 |
*/
|
deba@830
|
423 |
|
deba@830
|
424 |
template <typename Map>
|
deba@830
|
425 |
class MapConstValueIterator : public MapIteratorBase<Map> {
|
deba@830
|
426 |
|
deba@830
|
427 |
public:
|
deba@830
|
428 |
|
deba@844
|
429 |
/// The iterator base class.
|
deba@844
|
430 |
typedef MapIteratorBase<Map> Base;
|
deba@844
|
431 |
|
deba@830
|
432 |
/// The key type of the iterator.
|
deba@830
|
433 |
typedef typename Map::KeyType KeyType;
|
deba@830
|
434 |
/// The iterator to iterate on the keys.
|
deba@830
|
435 |
typedef typename Map::KeyIt KeyIt;
|
deba@830
|
436 |
|
deba@830
|
437 |
/// The value type of the iterator.
|
deba@830
|
438 |
typedef typename Map::ValueType ValueType;
|
deba@830
|
439 |
/// The reference type of the iterator.
|
deba@830
|
440 |
typedef typename Map::ReferenceType ReferenceType;
|
deba@830
|
441 |
/// The pointer type of the iterator.
|
deba@830
|
442 |
typedef typename Map::PointerType PointerType;
|
deba@830
|
443 |
|
deba@830
|
444 |
/// The const value type of the iterator.
|
deba@830
|
445 |
typedef typename Map::ConstValueType ConstValueType;
|
deba@830
|
446 |
/// The const reference type of the iterator.
|
deba@830
|
447 |
typedef typename Map::ConstReferenceType ConstReferenceType;
|
deba@830
|
448 |
/// The pointer type of the iterator.
|
deba@830
|
449 |
typedef typename Map::ConstPointerType ConstPointerType;
|
deba@830
|
450 |
|
deba@830
|
451 |
private:
|
deba@830
|
452 |
|
deba@822
|
453 |
const Map* map;
|
deba@830
|
454 |
|
deba@830
|
455 |
public:
|
deba@830
|
456 |
|
deba@830
|
457 |
/// Default constructor.
|
deba@830
|
458 |
MapConstValueIterator() {}
|
deba@830
|
459 |
|
deba@830
|
460 |
/// Constructor to create const iterator from a non const.
|
deba@830
|
461 |
MapConstValueIterator(const MapValueIterator<Map>& pit) {
|
deba@844
|
462 |
Base::it = pit.Base::it;
|
deba@830
|
463 |
map = pit.map;
|
deba@830
|
464 |
}
|
deba@830
|
465 |
|
deba@830
|
466 |
/// Map and KeyIt initialized iterator.
|
deba@830
|
467 |
MapConstValueIterator(const Map& pmap, const KeyIt& pit)
|
deba@844
|
468 |
: Base(pit), map(&pmap) {}
|
deba@830
|
469 |
|
deba@830
|
470 |
/// The pre increment operator of the iterator.
|
deba@830
|
471 |
MapConstValueIterator& operator++() {
|
deba@844
|
472 |
Base::increment();
|
deba@830
|
473 |
return *this;
|
deba@830
|
474 |
}
|
deba@830
|
475 |
|
deba@830
|
476 |
/// The post increment operator of the iterator.
|
deba@830
|
477 |
MapConstValueIterator operator++(int) {
|
deba@830
|
478 |
MapConstValueIterator tmp(*this);
|
deba@844
|
479 |
Base::increment();
|
deba@830
|
480 |
return tmp;
|
deba@830
|
481 |
}
|
deba@830
|
482 |
|
deba@830
|
483 |
/// The dereferencing operator of the iterator.
|
deba@830
|
484 |
ConstReferenceType operator*() const {
|
deba@844
|
485 |
return (*map)[Base::it];
|
deba@830
|
486 |
}
|
deba@830
|
487 |
|
deba@830
|
488 |
/// The arrow operator of the iterator.
|
deba@830
|
489 |
ConstPointerType operator->() const {
|
deba@830
|
490 |
return &(operator*());
|
deba@830
|
491 |
}
|
deba@830
|
492 |
|
deba@844
|
493 |
public:
|
deba@844
|
494 |
// STL compatibility typedefs.
|
deba@844
|
495 |
typedef std::input_iterator_tag iterator_category;
|
deba@844
|
496 |
typedef int difference_type;
|
deba@844
|
497 |
typedef ValueType value_type;
|
deba@844
|
498 |
typedef ConstReferenceType reference;
|
deba@844
|
499 |
typedef ConstPointerType pointer;
|
deba@822
|
500 |
};
|
deba@822
|
501 |
|
deba@830
|
502 |
|
deba@830
|
503 |
/** This class makes from a map an iteratable set
|
deba@830
|
504 |
* which contains all the keys of the map.
|
deba@830
|
505 |
*/
|
deba@830
|
506 |
template <typename Map>
|
deba@830
|
507 |
class MapConstKeySet {
|
deba@830
|
508 |
|
deba@830
|
509 |
const Map* map;
|
deba@830
|
510 |
|
deba@830
|
511 |
public:
|
deba@830
|
512 |
|
deba@830
|
513 |
/// The key type of the iterator.
|
deba@830
|
514 |
typedef typename Map::KeyType KeyType;
|
deba@830
|
515 |
/// The iterator to iterate on the keys.
|
deba@830
|
516 |
typedef typename Map::KeyIt KeyIt;
|
deba@830
|
517 |
|
deba@844
|
518 |
|
deba@844
|
519 |
/// The value type of the iterator.
|
deba@844
|
520 |
typedef typename Map::ValueType ValueType;
|
deba@844
|
521 |
/// The reference type of the iterator.
|
deba@844
|
522 |
typedef typename Map::ReferenceType ReferenceType;
|
deba@844
|
523 |
/// The pointer type of the iterator.
|
deba@844
|
524 |
typedef typename Map::PointerType PointerType;
|
deba@844
|
525 |
|
deba@844
|
526 |
/// The const value type of the iterator.
|
deba@844
|
527 |
typedef typename Map::ConstValueType ConstValueType;
|
deba@844
|
528 |
/// The const reference type of the iterator.
|
deba@844
|
529 |
typedef typename Map::ConstReferenceType ConstReferenceType;
|
deba@844
|
530 |
/// The pointer type of the iterator.
|
deba@844
|
531 |
typedef typename Map::ConstPointerType ConstPointerType;
|
deba@844
|
532 |
|
deba@830
|
533 |
/// The map initialized const key set.
|
deba@830
|
534 |
MapConstKeySet(const Map& pmap) : map(&pmap) {}
|
deba@830
|
535 |
|
deba@830
|
536 |
/// The const iterator of the set.
|
deba@830
|
537 |
typedef MapKeyIterator<Map> ConstIterator;
|
deba@830
|
538 |
|
deba@830
|
539 |
/// It gives back the const iterator pointed to the first element.
|
deba@830
|
540 |
ConstIterator begin() const {
|
deba@830
|
541 |
return ConstIterator(KeyIt(*map->getGraph()));
|
deba@830
|
542 |
}
|
deba@830
|
543 |
|
deba@830
|
544 |
/// It gives back the const iterator pointed to the first ivalid element.
|
deba@830
|
545 |
ConstIterator end() const {
|
deba@830
|
546 |
return ConstIterator(KeyIt(INVALID));
|
deba@830
|
547 |
}
|
deba@844
|
548 |
|
deba@844
|
549 |
public:
|
deba@844
|
550 |
// STL compatibility typedefs.
|
deba@844
|
551 |
typedef ValueType value_type;
|
deba@844
|
552 |
typedef ConstIterator const_iterator;
|
deba@844
|
553 |
typedef ConstReferenceType const_reference;
|
deba@844
|
554 |
typedef ConstPointerType const_pointer;
|
deba@844
|
555 |
typedef int difference_type;
|
deba@830
|
556 |
};
|
deba@830
|
557 |
|
deba@830
|
558 |
/** This class makes from a map an iteratable set
|
deba@830
|
559 |
* which contains all the values of the map.
|
deba@830
|
560 |
* The values cannot be modified.
|
deba@830
|
561 |
*/
|
deba@830
|
562 |
template <typename Map>
|
deba@830
|
563 |
class MapConstValueSet {
|
deba@830
|
564 |
|
deba@830
|
565 |
const Map* map;
|
deba@830
|
566 |
|
deba@830
|
567 |
public:
|
deba@830
|
568 |
|
deba@830
|
569 |
/// The key type of the iterator.
|
deba@830
|
570 |
typedef typename Map::KeyType KeyType;
|
deba@830
|
571 |
/// The iterator to iterate on the keys.
|
deba@830
|
572 |
typedef typename Map::KeyIt KeyIt;
|
deba@830
|
573 |
|
deba@844
|
574 |
|
deba@844
|
575 |
/// The value type of the iterator.
|
deba@844
|
576 |
typedef typename Map::ValueType ValueType;
|
deba@844
|
577 |
/// The reference type of the iterator.
|
deba@844
|
578 |
typedef typename Map::ReferenceType ReferenceType;
|
deba@844
|
579 |
/// The pointer type of the iterator.
|
deba@844
|
580 |
typedef typename Map::PointerType PointerType;
|
deba@844
|
581 |
|
deba@844
|
582 |
/// The const value type of the iterator.
|
deba@844
|
583 |
typedef typename Map::ConstValueType ConstValueType;
|
deba@844
|
584 |
/// The const reference type of the iterator.
|
deba@844
|
585 |
typedef typename Map::ConstReferenceType ConstReferenceType;
|
deba@844
|
586 |
/// The pointer type of the iterator.
|
deba@844
|
587 |
typedef typename Map::ConstPointerType ConstPointerType;
|
deba@844
|
588 |
|
deba@830
|
589 |
/// The map initialized const value set.
|
deba@830
|
590 |
MapConstValueSet(const Map& pmap) : map(&pmap) {}
|
deba@830
|
591 |
|
deba@830
|
592 |
/// The const iterator of the set.
|
deba@830
|
593 |
typedef MapConstValueIterator<Map> ConstIterator;
|
deba@830
|
594 |
|
deba@830
|
595 |
/// It gives back the const iterator pointed to the first element.
|
deba@830
|
596 |
ConstIterator begin() const {
|
deba@830
|
597 |
return ConstIterator(*map, KeyIt(*map->getGraph()));
|
deba@830
|
598 |
}
|
deba@830
|
599 |
|
deba@830
|
600 |
/// It gives back the const iterator pointed to the first invalid element.
|
deba@830
|
601 |
ConstIterator end() const {
|
deba@830
|
602 |
return ConstIterator(*map, KeyIt(INVALID));
|
deba@830
|
603 |
}
|
deba@844
|
604 |
|
deba@844
|
605 |
public:
|
deba@844
|
606 |
// STL compatibility typedefs.
|
deba@844
|
607 |
typedef ValueType value_type;
|
deba@844
|
608 |
typedef ConstIterator const_iterator;
|
deba@844
|
609 |
typedef ConstReferenceType const_reference;
|
deba@844
|
610 |
typedef ConstPointerType const_pointer;
|
deba@844
|
611 |
typedef int difference_type;
|
deba@830
|
612 |
};
|
deba@830
|
613 |
|
deba@830
|
614 |
|
deba@830
|
615 |
/** This class makes from a map an iteratable set
|
deba@830
|
616 |
* which contains all the values of the map.
|
deba@830
|
617 |
* The values can be modified.
|
deba@830
|
618 |
*/
|
deba@830
|
619 |
template <typename Map>
|
deba@830
|
620 |
class MapValueSet {
|
deba@830
|
621 |
|
deba@830
|
622 |
Map* map;
|
deba@830
|
623 |
|
deba@830
|
624 |
public:
|
deba@830
|
625 |
|
deba@830
|
626 |
/// The key type of the iterator.
|
deba@830
|
627 |
typedef typename Map::KeyType KeyType;
|
deba@830
|
628 |
/// The iterator to iterate on the keys.
|
deba@830
|
629 |
typedef typename Map::KeyIt KeyIt;
|
deba@830
|
630 |
|
deba@844
|
631 |
|
deba@844
|
632 |
/// The value type of the iterator.
|
deba@844
|
633 |
typedef typename Map::ValueType ValueType;
|
deba@844
|
634 |
/// The reference type of the iterator.
|
deba@844
|
635 |
typedef typename Map::ReferenceType ReferenceType;
|
deba@844
|
636 |
/// The pointer type of the iterator.
|
deba@844
|
637 |
typedef typename Map::PointerType PointerType;
|
deba@844
|
638 |
|
deba@844
|
639 |
/// The const value type of the iterator.
|
deba@844
|
640 |
typedef typename Map::ConstValueType ConstValueType;
|
deba@844
|
641 |
/// The const reference type of the iterator.
|
deba@844
|
642 |
typedef typename Map::ConstReferenceType ConstReferenceType;
|
deba@844
|
643 |
/// The pointer type of the iterator.
|
deba@844
|
644 |
typedef typename Map::ConstPointerType ConstPointerType;
|
deba@844
|
645 |
|
deba@830
|
646 |
/// The map initialized value set.
|
deba@830
|
647 |
MapValueSet(Map& pmap) : map(&pmap) {}
|
deba@830
|
648 |
|
deba@830
|
649 |
/// The const iterator of the set.
|
deba@830
|
650 |
typedef MapConstValueIterator<Map> ConstIterator;
|
deba@830
|
651 |
|
deba@830
|
652 |
/// It gives back the const iterator pointed to the first element.
|
deba@830
|
653 |
ConstIterator begin() const {
|
deba@830
|
654 |
return ConstIterator(*map, KeyIt(*map->getGraph()));
|
deba@830
|
655 |
}
|
deba@830
|
656 |
|
deba@830
|
657 |
/// It gives back the const iterator pointed to the first invalid element.
|
deba@830
|
658 |
ConstIterator end() const {
|
deba@830
|
659 |
return ConstIterator(*map, KeyIt(INVALID));
|
deba@830
|
660 |
}
|
deba@830
|
661 |
|
deba@830
|
662 |
/// The iterator of the set.
|
deba@830
|
663 |
typedef MapValueIterator<Map> Iterator;
|
deba@830
|
664 |
|
deba@830
|
665 |
/// It gives back the iterator pointed to the first element.
|
deba@830
|
666 |
Iterator begin() {
|
deba@830
|
667 |
return Iterator(*map, KeyIt(*map->getGraph()));
|
deba@830
|
668 |
}
|
deba@830
|
669 |
|
deba@830
|
670 |
/// It gives back the iterator pointed to the first invalid element.
|
deba@830
|
671 |
Iterator end() {
|
deba@830
|
672 |
return Iterator(*map, KeyIt(INVALID));
|
deba@830
|
673 |
}
|
deba@830
|
674 |
|
deba@844
|
675 |
public:
|
deba@844
|
676 |
// STL compatibility typedefs.
|
deba@844
|
677 |
typedef ValueType value_type;
|
deba@844
|
678 |
typedef Iterator iterator;
|
deba@844
|
679 |
typedef ConstIterator const_iterator;
|
deba@844
|
680 |
typedef ReferenceType reference;
|
deba@844
|
681 |
typedef ConstReferenceType const_reference;
|
deba@844
|
682 |
typedef PointerType pointer;
|
deba@844
|
683 |
typedef ConstPointerType const_pointer;
|
deba@844
|
684 |
typedef int difference_type;
|
deba@844
|
685 |
|
deba@830
|
686 |
};
|
deba@830
|
687 |
|
deba@830
|
688 |
/// @}
|
deba@830
|
689 |
|
deba@822
|
690 |
}
|
deba@822
|
691 |
|
deba@822
|
692 |
#endif
|