Changeset 799:3393abe30678 in lemon-0.x for src
- Timestamp:
- 09/03/04 17:32:03 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1093
- Location:
- src/hugo
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/hugo/array_map_factory.h
r786 r799 13 13 14 14 namespace hugo { 15 15 16 16 17 /// \addtogroup graphmapfactory 17 18 /// @{ 18 19 ///. 20 template <typename MapRegistry> class ArrayMapFactory { 19 20 /** The ArrayMapFactory template class is a factory class 21 * to create maps for the edge and nodes. This map factory 22 * uses the allocators to implement the container function. 23 * 24 * The template parameter is the MapRegistry that the maps 25 * will belong to. 26 */ 27 28 template <typename MapRegistry> 29 class ArrayMapFactory { 21 30 22 31 public: 23 32 33 /// The graph type of the maps. 24 34 typedef typename MapRegistry::Graph Graph; 35 /// The key type of the maps. 25 36 typedef typename MapRegistry::KeyType KeyType; 37 /// The iterator to iterate on the keys. 26 38 typedef typename MapRegistry::KeyIt KeyIt; 27 39 40 /// The MapBase of the Map which imlements the core regisitry function. 28 41 typedef typename MapRegistry::MapBase MapBase; 29 42 43 /** The template Map type. 44 */ 30 45 template <typename V, typename A = std::allocator<V> > 31 46 class Map : public MapBase { … … 33 48 public: 34 49 50 /// The value type of the map. 51 typedef V ValueType; 52 53 /// The value type of the map. 35 54 typedef V Value; 36 typedef V ValueType; 55 /// The reference type of the map; 56 typedef Value& Reference; 57 /// The pointer type of the map; 58 typedef Value* Pointer; 59 60 /// The const value type of the map. 61 typedef const Value ConstValue; 62 /// The const reference type of the map; 63 typedef const Value& ConstReference; 64 /// The pointer type of the map; 65 typedef const Value* ConstPointer; 66 67 37 68 typedef A Allocator; 38 69 39 70 71 /** Default constructor for the map. 72 */ 40 73 Map() : values(0), capacity(0) {} 41 74 75 /** Graph and Registry initialized map constructor. 76 */ 42 77 Map(const Graph& g, MapRegistry& r) : MapBase(g, r) { 43 78 allocate_memory(); … … 48 83 } 49 84 85 /** Constructor to use default value to initialize the map. 86 */ 50 87 Map(const Graph& g, MapRegistry& r, const Value& v) : MapBase(g, r) { 51 88 allocate_memory(); … … 56 93 } 57 94 95 /** Constructor to copy a map of the same map type. 96 */ 58 97 Map(const Map& copy) : MapBase(*copy.graph, *copy.registry) { 59 98 capacity = copy.capacity; … … 66 105 } 67 106 107 /** Constructor to copy a map of an other map type. 108 */ 68 109 template <typename CMap> Map(const CMap& copy) 69 110 : MapBase(copy), capacity(0), values(0) { … … 76 117 } 77 118 119 /** Assign operator to copy a map of the same map type. 120 */ 78 121 Map& operator=(const Map& copy) { 79 122 if (© == this) return *this; … … 92 135 } 93 136 137 /** Assign operator to copy a map an other map type. 138 */ 94 139 template <typename CMap> Map& operator=(const CMap& copy) { 95 140 if (MapBase::getGraph()) { … … 106 151 } 107 152 153 /** The destructor of the map. 154 */ 108 155 virtual ~Map() { 109 156 if (capacity != 0) { … … 114 161 115 162 163 /** 164 * The subscript operator. The map can be subscripted by the 165 * actual keys of the graph. 166 */ 116 167 Value& operator[](const KeyType& key) { 117 168 int id = MapBase::getGraph()->id(key); … … 119 170 } 120 171 172 /** 173 * The const subscript operator. The map can be subscripted by the 174 * actual keys of the graph. 175 */ 121 176 const Value& operator[](const KeyType& key) const { 122 177 int id = MapBase::getGraph()->id(key); … … 124 179 } 125 180 126 const Value& get(const KeyType& key) const { 127 int id = MapBase::getGraph()->id(key); 128 return values[id]; 129 } 130 181 /** Setter function of the map. Equivalent with map[key] = val. 182 * This is a compatibility feature with the not dereferable maps. 183 */ 131 184 void set(const KeyType& key, const Value& val) { 132 185 int id = MapBase::getGraph()->id(key); … … 134 187 } 135 188 189 /** Add a new key to the map. It called by the map registry. 190 */ 136 191 void add(const KeyType& key) { 137 192 int id = MapBase::getGraph()->id(key); … … 156 211 } 157 212 213 /** Erase a key from the map. It called by the map registry. 214 */ 158 215 void erase(const KeyType& key) { 159 216 int id = MapBase::getGraph()->id(key); … … 161 218 } 162 219 220 /** Clear the data structure. 221 */ 163 222 void clear() { 164 223 if (capacity != 0) { … … 169 228 } 170 229 230 /** Compatible iterator with the stl maps' iterators. 231 * It iterates on pairs of a key and a value. 232 */ 171 233 class iterator { 172 234 friend class Map; … … 372 434 }; 373 435 }; 374 436 375 437 /// @} 376 377 438 378 439 } -
src/hugo/default_map_factory.h
r798 r799 7 7 #include <hugo/vector_map_factory.h> 8 8 9 ///\ingroup graphmapfactory 10 ///\file 11 ///\brief Graph maps that construates and destruates 12 ///their elements dynamically. 13 9 14 namespace hugo { 15 16 /// \addtogroup graphmapfactory 17 /// @{ 10 18 11 19 #define DEFAULT_MAP_BODY(Factory, Val) \ … … 16 24 \ 17 25 typedef typename MapRegistry::Graph Graph; \ 18 typedef typename MapRegistry::Key Key; \26 typedef typename MapRegistry::KeyType KeyType; \ 19 27 typedef typename MapRegistry::KeyIt KeyIt; \ 20 28 typedef Val Value; \ … … 96 104 DEFAULT_MAP_BODY(VectorMapFactory, Type*); 97 105 106 107 /** The DefaultMapFactory template class is a factory class 108 * to create maps for the edge and nodes. This map factory 109 * uses the VectorMapFactory if the ValueType is a primitive 110 * type and the ArrayMapFactory for the other cases. 111 * 112 * The template parameter is the MapRegistry that the maps 113 * will belong to. 114 */ 115 98 116 template <typename MapRegistry> 99 117 class DefaultMapFactory { 100 118 101 119 public: 102 120 /// The graph type of the maps. 103 121 typedef typename MapRegistry::Graph Graph; 104 typedef typename MapRegistry::Key Key; 122 /// The key type of the maps. 123 typedef typename MapRegistry::KeyType KeyType; 124 /// The iterator to iterate on the keys. 105 125 typedef typename MapRegistry::KeyIt KeyIt; 106 126 127 /// The MapBase of the Map which imlements the core regisitry function. 107 128 typedef typename MapRegistry::MapBase MapBase; 129 108 130 131 /** The template Map type. 132 */ 109 133 template <typename V> 110 134 class Map : public DefaultMap<MapRegistry, V> { … … 116 140 typedef V Value; 117 141 142 /** Default constructor for the map. 143 */ 118 144 Map() : MapImpl() {} 119 145 146 /** Graph and Registry initialized map constructor. 147 */ 120 148 Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {} 121 149 150 /** Constructor to use default value to initialize the map. 151 */ 122 152 Map(const Graph& g, MapRegistry& r, const Value& v) : MapImpl(g, r, v) {} 123 153 154 /** Constructor to copy a map of the same map type. 155 */ 124 156 Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {} 125 157 158 /** Constructor to copy a map of an other map type. 159 */ 126 160 template <typename CMap> Map(const CMap& copy) : MapImpl(copy) {} 127 161 162 /** Assign operator to copy a map of the same map type. 163 */ 128 164 Map& operator=(const Map& copy) { 129 165 MapImpl::operator=(static_cast<const MapImpl&>(copy)); … … 131 167 } 132 168 169 /** Assign operator to copy a map an other map type. 170 */ 133 171 template <typename CMap> Map& operator=(const CMap& copy) { 134 172 MapImpl::operator=(copy); -
src/hugo/vector_map_factory.h
r798 r799 129 129 * actual keys of the graph. 130 130 */ 131 <<<<<<< .mine 132 Reference operator[](const Key& key) { 133 ======= 134 typename Container::reference operator[](const KeyType& key) { 135 >>>>>>> .r1091 131 Reference operator[](const KeyType& key) { 136 132 int id = getGraph()->id(key); 137 133 return container[id]; … … 142 138 * actual keys of the graph. 143 139 */ 144 <<<<<<< .mine 145 ConstReference operator[](const Key& key) const { 146 ======= 147 typename Container::const_reference operator[](const KeyType& key) const { 148 >>>>>>> .r1091 140 ConstReference operator[](const KeyType& key) const { 149 141 int id = getGraph()->id(key); 150 142 return container[id]; … … 210 202 private: 211 203 Reference data; 212 Pointer(const KeyType& key, Value&val) : data(key, val) {}204 Pointer(const KeyType& key, Map::Reference val) : data(key, val) {} 213 205 public: 214 206 Reference* operator->() {return &data;} … … 301 293 private: 302 294 Reference data; 303 Pointer(const KeyType& key, const Value& val) : data(key, val) {} 295 Pointer(const KeyType& key, Map::ConstReference val) 296 : data(key, val) {} 304 297 public: 305 298 Reference* operator->() {return &data;}
Note: See TracChangeset
for help on using the changeset viewer.