Changeset 1669:66ae78d29f1e in lemon-0.x for lemon/bits/array_map.h
- Timestamp:
- 08/31/05 15:29:32 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2185
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bits/array_map.h
r1613 r1669 20 20 #include <memory> 21 21 #include <lemon/bits/map_iterator.h> 22 23 ///\ingroup graphmapfactory 24 ///\file 25 ///\brief Graph maps that construates and destruates 26 ///their elements dynamically. 22 #include <lemon/concept_check.h> 23 #include <lemon/concept/maps.h> 24 25 /// \ingroup graphmapfactory 26 /// \file 27 /// \brief Graph maps that construct and destruct 28 /// their elements dynamically. 27 29 28 30 namespace lemon { 29 31 30 31 /// \addtogroup graphmapfactory32 /// @{33 32 /// \ingroup graphmapfactory 33 /// 34 /// \brief Graph map based on the array storage. 35 /// 34 36 /// The ArrayMap template class is graph map structure what 35 37 /// automatically updates the map when a key is added to or erased from 36 /// the map. This map factoryuses the allocators to implement38 /// the map. This map uses the allocators to implement 37 39 /// the container functionality. 38 40 /// 39 41 /// The template parameter is the AlterationNotifier that the maps 40 42 /// will belong to and the Value. 41 42 43 43 44 template <typename _Graph, … … 70 71 71 72 /// Graph and Registry initialized map constructor. 72 73 73 ArrayMap(const Graph& _g) : graph(&_g) { 74 74 Item it; … … 111 111 } 112 112 113 using Parent::attach; 114 using Parent::detach; 115 using Parent::attached; 116 117 /// Assign operator to copy a map of the same map type. 118 119 ArrayMap& operator=(const ArrayMap& copy) { 120 if (© == this) return *this; 121 122 if (graph != copy.graph) { 123 if (attached()) { 124 clear(); 125 detach(); 126 } 127 if (copy.attached()) { 128 attach(*copy.getRegistry()); 129 } 130 capacity = copy.capacity; 131 if (capacity == 0) return *this; 132 values = allocator.allocate(capacity); 133 } 134 135 Item it; 136 for (graph->first(it); it != INVALID; graph->next(it)) { 137 int id = graph->id(it);; 138 allocator.construct(&(values[id]), copy.values[id]); 139 } 140 141 return *this; 142 } 143 113 /// \brief The destructor of the map. 114 /// 144 115 /// The destructor of the map. 145 146 116 virtual ~ArrayMap() { 147 117 if (attached()) { … … 150 120 } 151 121 } 152 153 122 123 private: 124 125 ArrayMap& operator=(const ArrayMap&); 126 127 protected: 128 129 using Parent::attach; 130 using Parent::detach; 131 using Parent::attached; 132 133 const Graph* getGraph() { 134 return graph; 135 } 136 137 138 public: 139 154 140 ///The subscript operator. The map can be subscripted by the 155 141 ///actual keys of the graph. … … 175 161 (*this)[key] = val; 176 162 } 177 163 164 protected: 165 178 166 /// Add a new key to the map. It called by the map registry. 179 167 … … 275 263 } 276 264 277 const Graph* getGraph() {278 return graph;279 }280 281 265 private: 282 266 … … 302 286 }; 303 287 304 template <typename _Base>305 class ArrayMappableGraphExtender : public _Base {306 public:307 308 typedef ArrayMappableGraphExtender<_Base> Graph;309 typedef _Base Parent;310 311 typedef typename Parent::Node Node;312 typedef typename Parent::NodeIt NodeIt;313 typedef typename Parent::NodeNotifier NodeObserverRegistry;314 315 typedef typename Parent::Edge Edge;316 typedef typename Parent::EdgeIt EdgeIt;317 typedef typename Parent::EdgeNotifier EdgeObserverRegistry;318 319 320 321 template <typename _Value>322 class NodeMap323 : public IterableMapExtender<ArrayMap<Graph, Node, _Value> > {324 public:325 typedef ArrayMappableGraphExtender<_Base> Graph;326 327 typedef typename Graph::Node Node;328 typedef typename Graph::NodeIt NodeIt;329 330 typedef IterableMapExtender<ArrayMap<Graph, Node, _Value> > Parent;331 332 //typedef typename Parent::Graph Graph;333 typedef typename Parent::Value Value;334 335 NodeMap(const Graph& g)336 : Parent(g) {}337 NodeMap(const Graph& g, const Value& v)338 : Parent(g, v) {}339 340 };341 342 template <typename _Value>343 class EdgeMap344 : public IterableMapExtender<ArrayMap<Graph, Edge, _Value> > {345 public:346 typedef ArrayMappableGraphExtender<_Base> Graph;347 348 typedef typename Graph::Edge Edge;349 typedef typename Graph::EdgeIt EdgeIt;350 351 typedef IterableMapExtender<ArrayMap<Graph, Edge, _Value> > Parent;352 353 //typedef typename Parent::Graph Graph;354 typedef typename Parent::Value Value;355 356 EdgeMap(const Graph& g)357 : Parent(g) {}358 EdgeMap(const Graph& g, const Value& v)359 : Parent(g, v) {}360 361 };362 363 };364 365 /// @}366 367 288 } 368 289
Note: See TracChangeset
for help on using the changeset viewer.