Changeset 1669:66ae78d29f1e in lemon-0.x for lemon/bits
- Timestamp:
- 08/31/05 15:29:32 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2185
- Location:
- lemon/bits
- Files:
-
- 3 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 -
lemon/bits/default_map.h
r1587 r1669 29 29 namespace lemon { 30 30 31 /// \addtogroup graphmapfactory 32 /// @{ 33 34 /** The ArrayMap template class is graph map structure what 35 * automatically updates the map when a key is added to or erased from 36 * the map. This map uses the VectorMap if the Value is a primitive 37 * type and the ArrayMap for the other cases. 38 * 39 * The template parameter is the MapRegistry that the maps 40 * will belong to and the Value. 41 */ 42 43 31 /// \addtogroup graphmapfactory 32 /// @{ 44 33 45 34 template <typename _Graph, typename _Item, typename _Value> … … 136 125 }; 137 126 138 139 127 /// \e 140 128 template < 141 129 typename _Graph, … … 153 141 DefaultMap(const Graph& _g) : Parent(_g) {} 154 142 DefaultMap(const Graph& _g, const Value& _v) : Parent(_g, _v) {} 155 }; 156 157 158 143 144 }; 145 146 147 /// \e 159 148 template <typename _Base> 160 class DefaultMappableGraphExtender : public _Base {149 class MappableGraphExtender : public _Base { 161 150 public: 162 151 163 typedef DefaultMappableGraphExtender<_Base> Graph;152 typedef MappableGraphExtender<_Base> Graph; 164 153 typedef _Base Parent; 165 154 … … 175 164 : public IterableMapExtender<DefaultMap<Graph, Node, _Value> > { 176 165 public: 177 typedef DefaultMappableGraphExtender Graph;166 typedef MappableGraphExtender Graph; 178 167 typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent; 179 168 … … 182 171 NodeMap(const Graph& _g, const _Value& _v) 183 172 : Parent(_g, _v) {} 173 174 /// \brief Template assign operator. 175 /// 176 /// The given parameter should be conform to the ReadMap 177 /// concecpt and could be indiced by the current item set of 178 /// the NodeMap. In this case the value for each item 179 /// is assigned by the value of the given ReadMap. 180 template <typename CMap> 181 NodeMap& operator=(const CMap& cmap) { 182 checkConcept<concept::ReadMap<Node, _Value>, CMap>(); 183 const typename Parent::Graph* graph = Parent::getGraph(); 184 Node it; 185 for (graph->first(it); it != INVALID; graph->next(it)) { 186 Parent::set(it, cmap[it]); 187 } 188 return *this; 189 } 190 184 191 }; 185 192 … … 188 195 : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > { 189 196 public: 190 typedef DefaultMappableGraphExtender Graph;197 typedef MappableGraphExtender Graph; 191 198 typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent; 192 199 … … 195 202 EdgeMap(const Graph& _g, const _Value& _v) 196 203 : Parent(_g, _v) {} 204 205 template <typename CMap> 206 EdgeMap& operator=(const CMap& cmap) { 207 checkConcept<concept::ReadMap<Edge, _Value>, CMap>(); 208 const typename Parent::Graph* graph = Parent::getGraph(); 209 Edge it; 210 for (graph->first(it); it != INVALID; graph->next(it)) { 211 Parent::set(it, cmap[it]); 212 } 213 return *this; 214 } 197 215 }; 198 216 199 217 }; 200 218 219 /// \e 201 220 template <typename _Base> 202 221 class MappableUndirGraphExtender : 203 public DefaultMappableGraphExtender<_Base> {222 public MappableGraphExtender<_Base> { 204 223 public: 205 224 206 225 typedef MappableUndirGraphExtender Graph; 207 typedef DefaultMappableGraphExtender<_Base> Parent;226 typedef MappableGraphExtender<_Base> Parent; 208 227 209 228 typedef typename Parent::UndirEdge UndirEdge; … … 221 240 UndirEdgeMap(const Graph& _g, const _Value& _v) 222 241 : Parent(_g, _v) {} 242 243 template <typename CMap> 244 UndirEdgeMap& operator=(const CMap& cmap) { 245 checkConcept<concept::ReadMap<UndirEdge, _Value>, CMap>(); 246 const typename Parent::Graph* graph = Parent::getGraph(); 247 UndirEdge it; 248 for (graph->first(it); it != INVALID; graph->next(it)) { 249 Parent::set(it, cmap[it]); 250 } 251 return *this; 252 } 223 253 }; 224 254 … … 226 256 }; 227 257 258 /// @} 228 259 } 229 260 -
lemon/bits/vector_map.h
r1587 r1669 24 24 #include <lemon/bits/map_iterator.h> 25 25 #include <lemon/bits/alteration_notifier.h> 26 27 ///\ingroup graphmapfactory 26 #include <lemon/concept_check.h> 27 #include <lemon/concept/maps.h> 28 29 /// \ingroup graphmapfactory 30 /// 28 31 ///\file 29 32 ///\brief Vector based graph maps. 30 33 31 34 namespace lemon { 32 33 /// \addtogroup graphmapfactory 34 /// @{ 35 35 36 /// \ingroup graphmapfactory 37 /// 38 /// \brief Graph map based on the std::vector storage. 39 /// 36 40 /// The VectorMap template class is graph map structure what 37 41 /// automatically updates the map when a key is added to or erased from … … 118 122 } 119 123 120 using Parent::attach;121 using Parent::detach;122 using Parent::attached;123 124 /** Assign operator to copy a map of the same map type.125 */126 VectorMap& operator=(const VectorMap& copy) {127 if (© == this) return *this;128 129 if (graph != copy.graph) {130 if (attached()) {131 detach();132 }133 if (copy.attached()) {134 attach(*copy.getRegistry());135 }136 }137 container = copy.container;138 139 return *this;140 }141 142 143 124 virtual ~VectorMap() { 144 125 if (attached()) { … … 147 128 } 148 129 130 131 private: 132 133 VectorMap& operator=(const VectorMap&); 134 135 protected: 136 137 using Parent::attach; 138 using Parent::detach; 139 using Parent::attached; 140 149 141 const Graph* getGraph() const { 150 142 return graph; 151 143 } 144 145 public: 152 146 153 147 /// The subcript operator. … … 174 168 /// It the same as operator[](key) = value expression. 175 169 /// 176 177 170 void set(const Key& key, const Value& value) { 178 171 (*this)[key] = value; 179 172 } 180 173 181 /// Adds a new key to the map. 182 174 protected: 175 176 /// \brief Adds a new key to the map. 177 /// 183 178 /// It adds a new key to the map. It called by the observer registry 184 179 /// and it overrides the add() member function of the observer base. … … 221 216 }; 222 217 223 224 template <typename _Base>225 class VectorMappableGraphExtender : public _Base {226 public:227 228 typedef VectorMappableGraphExtender<_Base> Graph;229 typedef _Base Parent;230 231 typedef typename Parent::Node Node;232 typedef typename Parent::NodeIt NodeIt;233 typedef typename Parent::NodeIdMap NodeIdMap;234 typedef typename Parent::NodeNotifier NodeObserverRegistry;235 236 typedef typename Parent::Edge Edge;237 typedef typename Parent::EdgeIt EdgeIt;238 typedef typename Parent::EdgeIdMap EdgeIdMap;239 typedef typename Parent::EdgeNotifier EdgeObserverRegistry;240 241 242 template <typename _Value>243 class NodeMap :244 public IterableMapExtender<VectorMap<Graph, Node, _Value> > {245 public:246 typedef VectorMappableGraphExtender<_Base> Graph;247 248 typedef typename Graph::Node Node;249 250 typedef IterableMapExtender<VectorMap<Graph, Node, _Value> > Parent;251 252 //typedef typename Parent::Graph Graph;253 typedef typename Parent::Value Value;254 255 NodeMap(const Graph& g)256 : Parent(g) {}257 NodeMap(const Graph& g, const Value& v)258 : Parent(g, v) {}259 260 };261 262 template <typename _Value>263 class EdgeMap264 : public IterableMapExtender<VectorMap<Graph, Edge, _Value> > {265 public:266 typedef VectorMappableGraphExtender<_Base> Graph;267 268 typedef typename Graph::Edge Edge;269 270 typedef IterableMapExtender<VectorMap<Graph, Edge, _Value> > Parent;271 272 //typedef typename Parent::Graph Graph;273 typedef typename Parent::Value Value;274 275 EdgeMap(const Graph& g)276 : Parent(g) {}277 EdgeMap(const Graph& g, const Value& v)278 : Parent(g, v) {}279 280 };281 282 };283 284 /// @}285 286 218 } 287 219
Note: See TracChangeset
for help on using the changeset viewer.