Changeset 844:9bf990cb066d in lemon-0.x for src/hugo/map_iterator.h
- Timestamp:
- 09/13/04 22:05:13 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1143
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/hugo/map_iterator.h
r830 r844 2 2 #ifndef MAP_ITERATOR_H 3 3 #define MAP_ITERATOR_H 4 5 #include <iterator> 4 6 5 7 #include <hugo/extended_pair.h> … … 23 25 24 26 public: 27 25 28 /// The key type of the iterator. 26 29 typedef typename Map::KeyType KeyType; … … 80 83 friend class MapConstIterator<Map>; 81 84 82 public: 85 86 public: 87 88 /// The iterator base class. 89 typedef MapIteratorBase<Map> Base; 83 90 84 91 /// The key type of the iterator. … … 102 109 103 110 public: 111 112 /// The value type of the iterator. 113 typedef extended_pair<KeyType, const KeyType&, 114 ValueType, const ValueType&> PairValueType; 104 115 105 116 /// The reference type of the iterator. … … 112 123 /// Constructor to initalize the iterators returned 113 124 /// by the begin() and end(). 114 MapIterator(Map& pmap, const KeyIt& pit) 115 : MapIteratorBase<Map>(pit), map(&pmap) {} 125 MapIterator(Map& pmap, const KeyIt& pit) : Base(pit), map(&pmap) {} 116 126 117 127 /// Dereference operator for the iterator. 118 128 PairReferenceType operator*() { 119 return PairReferenceType( it, (*map)[it]);129 return PairReferenceType(Base::it, (*map)[Base::it]); 120 130 } 121 131 … … 133 143 /// Arrow operator for the iterator. 134 144 PairPointerType operator->() { 135 return PairPointerType( it, ((*map)[it]));145 return PairPointerType(Base::it, ((*map)[Base::it])); 136 146 } 137 147 138 148 /// The pre increment operator of the iterator. 139 149 MapIterator& operator++() { 140 increment();150 Base::increment(); 141 151 return *this; 142 152 } … … 144 154 /// The post increment operator of the iterator. 145 155 MapIterator operator++(int) { 146 MapIterator tmp( it);147 increment();156 MapIterator tmp(*this); 157 Base::increment(); 148 158 return tmp; 149 159 } … … 151 161 private: 152 162 Map* map; 163 164 public: 165 // STL compatibility typedefs. 166 typedef std::forward_iterator_tag iterator_category; 167 typedef int difference_type; 168 typedef PairValueType value_type; 169 typedef PairReferenceType reference; 170 typedef PairPointerType pointer; 153 171 }; 154 172 … … 160 178 161 179 public: 180 181 /// The iterator base class. 182 typedef MapIteratorBase<Map> Base; 162 183 163 184 /// The key type of the iterator. … … 188 209 /// by the begin() and end(). 189 210 MapConstIterator(const Map& pmap, const KeyIt& pit) 190 : MapIteratorBase<Map>(pit), map(&pmap) {}211 : Base(pit), map(&pmap) {} 191 212 192 213 /// Constructor to create const iterator from a non const. 193 214 MapConstIterator(const MapIterator<Map>& pit) { 194 it = pit.it;215 Base::it = pit.Base::it; 195 216 map = pit.map; 196 217 } 218 219 /// The value type of the iterator. 220 typedef extended_pair<KeyType, const KeyType&, 221 ValueType, const ValueType&> PairValueType; 197 222 198 223 /// The reference type of map. … … 202 227 /// Dereference operator for the iterator. 203 228 PairReferenceType operator*() { 204 return PairReferenceType( it, (*map)[it]);229 return PairReferenceType(Base::it, (*map)[Base::it]); 205 230 } 206 231 … … 218 243 /// Arrow operator for the iterator. 219 244 PairPointerType operator->() { 220 return PairPointerType( it, ((*map)[it]));245 return PairPointerType(Base::it, (*map)[Base::it]); 221 246 } 222 247 223 248 /// The pre increment operator of the iterator. 224 249 MapConstIterator& operator++() { 225 increment();250 Base::increment(); 226 251 return *this; 227 252 } … … 229 254 /// The post increment operator of the iterator. 230 255 MapConstIterator operator++(int) { 231 MapConstIterator <Map> tmp(it);232 increment();256 MapConstIterator tmp(*this); 257 Base::increment(); 233 258 return tmp; 234 259 } … … 236 261 private: 237 262 const Map* map; 263 264 public: 265 // STL compatibility typedefs. 266 typedef std::input_iterator_tag iterator_category; 267 typedef int difference_type; 268 typedef PairValueType value_type; 269 typedef PairReferenceType reference; 270 typedef PairPointerType pointer; 238 271 }; 239 272 … … 246 279 public: 247 280 281 /// The iterator base class. 282 typedef MapIteratorBase<Map> Base; 283 248 284 /// The key type of the iterator. 249 285 typedef typename Map::KeyType KeyType; … … 257 293 258 294 /// KeyIt initialized iterator. 259 MapKeyIterator(const KeyIt& pit) : MapIteratorBase<Map>(pit) {}295 MapKeyIterator(const KeyIt& pit) : Base(pit) {} 260 296 261 297 /// The pre increment operator of the iterator. 262 298 MapKeyIterator& operator++() { 263 increment();299 Base::increment(); 264 300 return *this; 265 301 } … … 268 304 MapKeyIterator operator++(int) { 269 305 MapKeyIterator tmp(*this); 270 increment();306 Base::increment(); 271 307 return tmp; 272 308 } … … 274 310 /// The dereferencing operator of the iterator. 275 311 KeyType operator*() const { 276 return static_cast<KeyType>(it); 277 } 312 return static_cast<KeyType>(Base::it); 313 } 314 315 public: 316 // STL compatibility typedefs. 317 typedef std::input_iterator_tag iterator_category; 318 typedef int difference_type; 319 typedef KeyType value_type; 320 typedef const KeyType& reference; 321 typedef const KeyType* pointer; 278 322 }; 279 323 280 324 template <typename Map> class MapConstValueIterator; 281 325 326 /** MapValueIterator creates an stl compatible iterator 327 * for the values. 328 */ 282 329 template <typename Map> 283 330 class MapValueIterator : public MapIteratorBase<Map> { … … 286 333 287 334 public: 335 336 /// The iterator base class. 337 typedef MapIteratorBase<Map> Base; 288 338 289 339 /// The key type of the iterator. … … 318 368 /// Map and KeyIt initialized iterator. 319 369 MapValueIterator(Map& pmap, const KeyIt& pit) 320 : MapIteratorBase<Map>(pit), map(&pmap) {}370 : Base(pit), map(&pmap) {} 321 371 322 372 323 373 /// The pre increment operator of the iterator. 324 374 MapValueIterator& operator++() { 325 increment();375 Base::increment(); 326 376 return *this; 327 377 } … … 330 380 MapValueIterator operator++(int) { 331 381 MapValueIterator tmp(*this); 332 increment();382 Base::increment(); 333 383 return tmp; 334 384 } … … 336 386 /// The dereferencing operator of the iterator. 337 387 ReferenceType operator*() const { 338 return (*map)[ it];388 return (*map)[Base::it]; 339 389 } 340 390 … … 344 394 } 345 395 346 }; 347 396 public: 397 // STL compatibility typedefs. 398 typedef std::forward_iterator_tag iterator_category; 399 typedef int difference_type; 400 typedef ValueType value_type; 401 typedef ReferenceType reference; 402 typedef PointerType pointer; 403 }; 404 405 /** MapValueIterator creates an stl compatible iterator 406 * for the const values. 407 */ 348 408 349 409 template <typename Map> … … 352 412 public: 353 413 354 /// The key type of the iterator. 355 typedef typename Map::KeyType KeyType; 356 /// The iterator to iterate on the keys. 357 typedef typename Map::KeyIt KeyIt; 358 414 /// The iterator base class. 415 typedef MapIteratorBase<Map> Base; 416 417 /// The key type of the iterator. 418 typedef typename Map::KeyType KeyType; 419 /// The iterator to iterate on the keys. 420 typedef typename Map::KeyIt KeyIt; 359 421 360 422 /// The value type of the iterator. … … 383 445 /// Constructor to create const iterator from a non const. 384 446 MapConstValueIterator(const MapValueIterator<Map>& pit) { 385 it = pit.it;447 Base::it = pit.Base::it; 386 448 map = pit.map; 387 449 } … … 389 451 /// Map and KeyIt initialized iterator. 390 452 MapConstValueIterator(const Map& pmap, const KeyIt& pit) 391 : MapIteratorBase<Map>(pit), map(&pmap) {}453 : Base(pit), map(&pmap) {} 392 454 393 455 /// The pre increment operator of the iterator. 394 456 MapConstValueIterator& operator++() { 395 increment();457 Base::increment(); 396 458 return *this; 397 459 } … … 400 462 MapConstValueIterator operator++(int) { 401 463 MapConstValueIterator tmp(*this); 402 increment();464 Base::increment(); 403 465 return tmp; 404 466 } … … 406 468 /// The dereferencing operator of the iterator. 407 469 ConstReferenceType operator*() const { 408 return (*map)[ it];470 return (*map)[Base::it]; 409 471 } 410 472 … … 414 476 } 415 477 478 public: 479 // STL compatibility typedefs. 480 typedef std::input_iterator_tag iterator_category; 481 typedef int difference_type; 482 typedef ValueType value_type; 483 typedef ConstReferenceType reference; 484 typedef ConstPointerType pointer; 416 485 }; 417 486 … … 431 500 /// The iterator to iterate on the keys. 432 501 typedef typename Map::KeyIt KeyIt; 502 503 504 /// The value type of the iterator. 505 typedef typename Map::ValueType ValueType; 506 /// The reference type of the iterator. 507 typedef typename Map::ReferenceType ReferenceType; 508 /// The pointer type of the iterator. 509 typedef typename Map::PointerType PointerType; 510 511 /// The const value type of the iterator. 512 typedef typename Map::ConstValueType ConstValueType; 513 /// The const reference type of the iterator. 514 typedef typename Map::ConstReferenceType ConstReferenceType; 515 /// The pointer type of the iterator. 516 typedef typename Map::ConstPointerType ConstPointerType; 433 517 434 518 /// The map initialized const key set. … … 447 531 return ConstIterator(KeyIt(INVALID)); 448 532 } 533 534 public: 535 // STL compatibility typedefs. 536 typedef ValueType value_type; 537 typedef ConstIterator const_iterator; 538 typedef ConstReferenceType const_reference; 539 typedef ConstPointerType const_pointer; 540 typedef int difference_type; 449 541 }; 450 542 … … 465 557 typedef typename Map::KeyIt KeyIt; 466 558 559 560 /// The value type of the iterator. 561 typedef typename Map::ValueType ValueType; 562 /// The reference type of the iterator. 563 typedef typename Map::ReferenceType ReferenceType; 564 /// The pointer type of the iterator. 565 typedef typename Map::PointerType PointerType; 566 567 /// The const value type of the iterator. 568 typedef typename Map::ConstValueType ConstValueType; 569 /// The const reference type of the iterator. 570 typedef typename Map::ConstReferenceType ConstReferenceType; 571 /// The pointer type of the iterator. 572 typedef typename Map::ConstPointerType ConstPointerType; 573 467 574 /// The map initialized const value set. 468 575 MapConstValueSet(const Map& pmap) : map(&pmap) {} … … 480 587 return ConstIterator(*map, KeyIt(INVALID)); 481 588 } 589 590 public: 591 // STL compatibility typedefs. 592 typedef ValueType value_type; 593 typedef ConstIterator const_iterator; 594 typedef ConstReferenceType const_reference; 595 typedef ConstPointerType const_pointer; 596 typedef int difference_type; 482 597 }; 483 598 … … 499 614 typedef typename Map::KeyIt KeyIt; 500 615 616 617 /// The value type of the iterator. 618 typedef typename Map::ValueType ValueType; 619 /// The reference type of the iterator. 620 typedef typename Map::ReferenceType ReferenceType; 621 /// The pointer type of the iterator. 622 typedef typename Map::PointerType PointerType; 623 624 /// The const value type of the iterator. 625 typedef typename Map::ConstValueType ConstValueType; 626 /// The const reference type of the iterator. 627 typedef typename Map::ConstReferenceType ConstReferenceType; 628 /// The pointer type of the iterator. 629 typedef typename Map::ConstPointerType ConstPointerType; 630 501 631 /// The map initialized value set. 502 632 MapValueSet(Map& pmap) : map(&pmap) {} … … 528 658 } 529 659 660 public: 661 // STL compatibility typedefs. 662 typedef ValueType value_type; 663 typedef Iterator iterator; 664 typedef ConstIterator const_iterator; 665 typedef ReferenceType reference; 666 typedef ConstReferenceType const_reference; 667 typedef PointerType pointer; 668 typedef ConstPointerType const_pointer; 669 typedef int difference_type; 670 530 671 }; 531 672
Note: See TracChangeset
for help on using the changeset viewer.