deba@822: // -*- c++ -*- deba@822: #ifndef MAP_ITERATOR_H deba@822: #define MAP_ITERATOR_H deba@822: deba@822: #include deba@822: deba@822: namespace hugo { deba@822: deba@822: deba@822: template deba@822: class MapIterator; deba@822: deba@822: template deba@822: class MapConstIterator; deba@822: deba@822: /** Compatible iterator with the stl maps' iterators. deba@822: * It iterates on pairs of a key and a value. deba@822: */ deba@822: template deba@822: class MapIterator { deba@822: // friend class Map; deba@822: friend class MapConstIterator; deba@822: deba@822: public: deba@822: deba@822: /// The key type of the iterator. deba@822: typedef typename Map::KeyType KeyType; deba@822: /// The iterator to iterate on the keys. deba@822: typedef typename Map::KeyIt KeyIt; deba@822: deba@822: /// The value type of the iterator. deba@822: typedef typename Map::ValueType ValueType; deba@822: /// The reference type of the iterator. deba@822: typedef typename Map::ReferenceType ReferenceType; deba@822: /// The pointer type of the iterator. deba@822: typedef typename Map::PointerType PointerType; deba@822: deba@822: /// The const value type of the iterator. deba@822: typedef typename Map::ConstValueType ConstValueType; deba@822: /// The const reference type of the iterator. deba@822: typedef typename Map::ConstReferenceType ConstReferenceType; deba@822: /// The pointer type of the iterator. deba@822: typedef typename Map::ConstPointerType ConstPointerType; deba@822: deba@822: public: deba@822: deba@822: /** Constructor to initalize the the iterators returned deba@822: * by the begin() and end(). deba@822: */ deba@822: MapIterator (Map& pmap, const KeyIt& pit) deba@822: : map(&pmap), it(pit) {} deba@822: deba@822: public: deba@822: deba@822: /** Default constructor. deba@822: */ deba@822: MapIterator() {} deba@822: deba@822: typedef extended_pair PairReferenceType; deba@822: deba@822: /** Dereference operator for map. deba@822: */ deba@822: PairReferenceType operator*() { deba@822: return PairReferenceType(it, (*map)[it]); deba@822: } deba@822: deba@822: class PairPointerType { deba@822: friend class MapIterator; deba@822: private: deba@822: PairReferenceType data; deba@822: PairPointerType(const KeyType& key, ReferenceType val) deba@822: : data(key, val) {} deba@822: public: deba@822: PairReferenceType* operator->() {return &data;} deba@822: }; deba@822: deba@822: /** Arrow operator for map. deba@822: */ deba@822: PairPointerType operator->() { deba@822: return PairPointerType(it, ((*map)[it])); deba@822: } deba@822: deba@822: /** The pre increment operator of the map. deba@822: */ deba@822: MapIterator& operator++() { deba@822: ++it; deba@822: return *this; deba@822: } deba@822: deba@822: /** The post increment operator of the map. deba@822: */ deba@822: MapIterator operator++(int) { deba@822: MapIterator tmp(it); deba@822: ++it; deba@822: return tmp; deba@822: } deba@822: deba@822: /** The equality operator of the map. deba@822: */ deba@822: bool operator==(const MapIterator& p_it) const { deba@822: return p_it.it == it; deba@822: } deba@822: deba@822: /** The not-equality operator of the map. deba@822: */ deba@822: bool operator!=(const MapIterator& p_it) const { deba@822: return !(*this == p_it); deba@822: } deba@822: deba@822: /** The equality operator of the map. deba@822: */ deba@822: bool operator==(const MapConstIterator& p_it) const { deba@822: return p_it.it == it; deba@822: } deba@822: deba@822: /** The not-equality operator of the map. deba@822: */ deba@822: bool operator!=(const MapConstIterator& p_it) const { deba@822: return !(*this == p_it); deba@822: } deba@822: deba@822: private: deba@822: Map* map; deba@822: KeyIt it; deba@822: }; deba@822: deba@822: /** Compatible iterator with the stl maps' iterators. deba@822: * It iterates on pairs of a key and a value. deba@822: */ deba@822: template deba@822: class MapConstIterator { deba@822: // friend class Map; deba@822: friend class MapIterator; deba@822: deba@822: public: deba@822: deba@822: /// The key type of the iterator. deba@822: typedef typename Map::KeyType KeyType; deba@822: /// The iterator to iterate on the keys. deba@822: typedef typename Map::KeyIt KeyIt; deba@822: deba@822: /// The value type of the iterator. deba@822: typedef typename Map::ValueType ValueType; deba@822: /// The reference type of the iterator. deba@822: typedef typename Map::ReferenceType ReferenceType; deba@822: /// The pointer type of the iterator. deba@822: typedef typename Map::PointerType PointerType; deba@822: deba@822: /// The const value type of the iterator. deba@822: typedef typename Map::ConstValueType ConstValueType; deba@822: /// The const reference type of the iterator. deba@822: typedef typename Map::ConstReferenceType ConstReferenceType; deba@822: /// The pointer type of the iterator. deba@822: typedef typename Map::ConstPointerType ConstPointerType; deba@822: deba@822: public: deba@822: deba@822: /** Constructor to initalize the the iterators returned deba@822: * by the begin() and end(). deba@822: */ deba@822: deba@822: MapConstIterator (const Map& pmap, const KeyIt& pit) deba@822: : map(&pmap), it(pit) {} deba@822: deba@822: public: deba@822: deba@822: /** Default constructor. deba@822: */ deba@822: MapConstIterator() {} deba@822: deba@822: typedef extended_pair PairReferenceType; deba@822: deba@822: /** Dereference operator for map. deba@822: */ deba@822: PairReferenceType operator*() { deba@822: return PairReferenceType(it, (*map)[it]); deba@822: } deba@822: deba@822: class PairPointerType { deba@822: friend class MapConstIterator; deba@822: private: deba@822: PairReferenceType data; deba@822: PairPointerType(const KeyType& key, ConstReferenceType val) deba@822: : data(key, val) {} deba@822: public: deba@822: PairReferenceType* operator->() {return &data;} deba@822: }; deba@822: deba@822: /** Arrow operator for map. deba@822: */ deba@822: PairPointerType operator->() { deba@822: return PairPointerType(it, ((*map)[it])); deba@822: } deba@822: deba@822: /** The pre increment operator of the map. deba@822: */ deba@822: MapConstIterator& operator++() { deba@822: ++it; deba@822: return *this; deba@822: } deba@822: deba@822: /** The post increment operator of the map. deba@822: */ deba@822: MapConstIterator operator++(int) { deba@822: MapConstIterator tmp(it); deba@822: ++it; deba@822: return tmp; deba@822: } deba@822: deba@822: /** The equality operator of the map. deba@822: */ deba@822: bool operator==(const MapIterator& p_it) const { deba@822: return p_it.it == it; deba@822: } deba@822: deba@822: /** The not-equality operator of the map. deba@822: */ deba@822: bool operator!=(const MapIterator& p_it) const { deba@822: return !(*this == p_it); deba@822: } deba@822: deba@822: /** The equality operator of the map. deba@822: */ deba@822: bool operator==(const MapConstIterator& p_it) const { deba@822: return p_it.it == it; deba@822: } deba@822: deba@822: /** The not-equality operator of the map. deba@822: */ deba@822: bool operator!=(const MapConstIterator& p_it) const { deba@822: return !(*this == p_it); deba@822: } deba@822: deba@822: private: deba@822: const Map* map; deba@822: KeyIt it; deba@822: }; deba@822: deba@822: } deba@822: deba@822: #endif