1.1 --- a/lemon/bits/array_map.h Tue Aug 30 21:19:07 2005 +0000
1.2 +++ b/lemon/bits/array_map.h Wed Aug 31 13:29:32 2005 +0000
1.3 @@ -19,26 +19,27 @@
1.4
1.5 #include <memory>
1.6 #include <lemon/bits/map_iterator.h>
1.7 +#include <lemon/concept_check.h>
1.8 +#include <lemon/concept/maps.h>
1.9
1.10 -///\ingroup graphmapfactory
1.11 -///\file
1.12 -///\brief Graph maps that construates and destruates
1.13 -///their elements dynamically.
1.14 +/// \ingroup graphmapfactory
1.15 +/// \file
1.16 +/// \brief Graph maps that construct and destruct
1.17 +/// their elements dynamically.
1.18
1.19 namespace lemon {
1.20
1.21 -
1.22 - /// \addtogroup graphmapfactory
1.23 - /// @{
1.24 -
1.25 + /// \ingroup graphmapfactory
1.26 + ///
1.27 + /// \brief Graph map based on the array storage.
1.28 + ///
1.29 /// The ArrayMap template class is graph map structure what
1.30 /// automatically updates the map when a key is added to or erased from
1.31 - /// the map. This map factory uses the allocators to implement
1.32 + /// the map. This map uses the allocators to implement
1.33 /// the container functionality.
1.34 ///
1.35 /// The template parameter is the AlterationNotifier that the maps
1.36 /// will belong to and the Value.
1.37 -
1.38
1.39 template <typename _Graph,
1.40 typename _Item,
1.41 @@ -69,7 +70,6 @@
1.42 public:
1.43
1.44 /// Graph and Registry initialized map constructor.
1.45 -
1.46 ArrayMap(const Graph& _g) : graph(&_g) {
1.47 Item it;
1.48 attach(_g.getNotifier(Item()));
1.49 @@ -110,47 +110,33 @@
1.50 }
1.51 }
1.52
1.53 - using Parent::attach;
1.54 - using Parent::detach;
1.55 - using Parent::attached;
1.56 -
1.57 - /// Assign operator to copy a map of the same map type.
1.58 -
1.59 - ArrayMap& operator=(const ArrayMap& copy) {
1.60 - if (© == this) return *this;
1.61 -
1.62 - if (graph != copy.graph) {
1.63 - if (attached()) {
1.64 - clear();
1.65 - detach();
1.66 - }
1.67 - if (copy.attached()) {
1.68 - attach(*copy.getRegistry());
1.69 - }
1.70 - capacity = copy.capacity;
1.71 - if (capacity == 0) return *this;
1.72 - values = allocator.allocate(capacity);
1.73 - }
1.74 -
1.75 - Item it;
1.76 - for (graph->first(it); it != INVALID; graph->next(it)) {
1.77 - int id = graph->id(it);;
1.78 - allocator.construct(&(values[id]), copy.values[id]);
1.79 - }
1.80 -
1.81 - return *this;
1.82 - }
1.83 -
1.84 + /// \brief The destructor of the map.
1.85 + ///
1.86 /// The destructor of the map.
1.87 -
1.88 virtual ~ArrayMap() {
1.89 if (attached()) {
1.90 clear();
1.91 detach();
1.92 }
1.93 }
1.94 -
1.95 -
1.96 +
1.97 + private:
1.98 +
1.99 + ArrayMap& operator=(const ArrayMap&);
1.100 +
1.101 + protected:
1.102 +
1.103 + using Parent::attach;
1.104 + using Parent::detach;
1.105 + using Parent::attached;
1.106 +
1.107 + const Graph* getGraph() {
1.108 + return graph;
1.109 + }
1.110 +
1.111 +
1.112 + public:
1.113 +
1.114 ///The subscript operator. The map can be subscripted by the
1.115 ///actual keys of the graph.
1.116
1.117 @@ -174,7 +160,9 @@
1.118 void set(const Key& key, const Value& val) {
1.119 (*this)[key] = val;
1.120 }
1.121 -
1.122 +
1.123 + protected:
1.124 +
1.125 /// Add a new key to the map. It called by the map registry.
1.126
1.127 void add(const Key& key) {
1.128 @@ -274,10 +262,6 @@
1.129 }
1.130 }
1.131
1.132 - const Graph* getGraph() {
1.133 - return graph;
1.134 - }
1.135 -
1.136 private:
1.137
1.138 void allocate_memory() {
1.139 @@ -301,69 +285,6 @@
1.140
1.141 };
1.142
1.143 - template <typename _Base>
1.144 - class ArrayMappableGraphExtender : public _Base {
1.145 - public:
1.146 -
1.147 - typedef ArrayMappableGraphExtender<_Base> Graph;
1.148 - typedef _Base Parent;
1.149 -
1.150 - typedef typename Parent::Node Node;
1.151 - typedef typename Parent::NodeIt NodeIt;
1.152 - typedef typename Parent::NodeNotifier NodeObserverRegistry;
1.153 -
1.154 - typedef typename Parent::Edge Edge;
1.155 - typedef typename Parent::EdgeIt EdgeIt;
1.156 - typedef typename Parent::EdgeNotifier EdgeObserverRegistry;
1.157 -
1.158 -
1.159 -
1.160 - template <typename _Value>
1.161 - class NodeMap
1.162 - : public IterableMapExtender<ArrayMap<Graph, Node, _Value> > {
1.163 - public:
1.164 - typedef ArrayMappableGraphExtender<_Base> Graph;
1.165 -
1.166 - typedef typename Graph::Node Node;
1.167 - typedef typename Graph::NodeIt NodeIt;
1.168 -
1.169 - typedef IterableMapExtender<ArrayMap<Graph, Node, _Value> > Parent;
1.170 -
1.171 - //typedef typename Parent::Graph Graph;
1.172 - typedef typename Parent::Value Value;
1.173 -
1.174 - NodeMap(const Graph& g)
1.175 - : Parent(g) {}
1.176 - NodeMap(const Graph& g, const Value& v)
1.177 - : Parent(g, v) {}
1.178 -
1.179 - };
1.180 -
1.181 - template <typename _Value>
1.182 - class EdgeMap
1.183 - : public IterableMapExtender<ArrayMap<Graph, Edge, _Value> > {
1.184 - public:
1.185 - typedef ArrayMappableGraphExtender<_Base> Graph;
1.186 -
1.187 - typedef typename Graph::Edge Edge;
1.188 - typedef typename Graph::EdgeIt EdgeIt;
1.189 -
1.190 - typedef IterableMapExtender<ArrayMap<Graph, Edge, _Value> > Parent;
1.191 -
1.192 - //typedef typename Parent::Graph Graph;
1.193 - typedef typename Parent::Value Value;
1.194 -
1.195 - EdgeMap(const Graph& g)
1.196 - : Parent(g) {}
1.197 - EdgeMap(const Graph& g, const Value& v)
1.198 - : Parent(g, v) {}
1.199 -
1.200 - };
1.201 -
1.202 - };
1.203 -
1.204 -/// @}
1.205 -
1.206 }
1.207
1.208 #endif //LEMON_ARRAY_MAP_H