1.1 --- a/src/hugo/array_map_factory.h Fri Sep 03 15:11:17 2004 +0000
1.2 +++ b/src/hugo/array_map_factory.h Fri Sep 03 15:32:03 2004 +0000
1.3 @@ -12,33 +12,68 @@
1.4 ///their elements dynamically.
1.5
1.6 namespace hugo {
1.7 -
1.8 +
1.9 +
1.10 /// \addtogroup graphmapfactory
1.11 /// @{
1.12 +
1.13 + /** The ArrayMapFactory template class is a factory class
1.14 + * to create maps for the edge and nodes. This map factory
1.15 + * uses the allocators to implement the container function.
1.16 + *
1.17 + * The template parameter is the MapRegistry that the maps
1.18 + * will belong to.
1.19 + */
1.20
1.21 - ///.
1.22 - template <typename MapRegistry> class ArrayMapFactory {
1.23 + template <typename MapRegistry>
1.24 + class ArrayMapFactory {
1.25
1.26 public:
1.27
1.28 + /// The graph type of the maps.
1.29 typedef typename MapRegistry::Graph Graph;
1.30 + /// The key type of the maps.
1.31 typedef typename MapRegistry::KeyType KeyType;
1.32 + /// The iterator to iterate on the keys.
1.33 typedef typename MapRegistry::KeyIt KeyIt;
1.34
1.35 + /// The MapBase of the Map which imlements the core regisitry function.
1.36 typedef typename MapRegistry::MapBase MapBase;
1.37
1.38 + /** The template Map type.
1.39 + */
1.40 template <typename V, typename A = std::allocator<V> >
1.41 class Map : public MapBase {
1.42
1.43 public:
1.44
1.45 + /// The value type of the map.
1.46 + typedef V ValueType;
1.47 +
1.48 + /// The value type of the map.
1.49 typedef V Value;
1.50 - typedef V ValueType;
1.51 + /// The reference type of the map;
1.52 + typedef Value& Reference;
1.53 + /// The pointer type of the map;
1.54 + typedef Value* Pointer;
1.55 +
1.56 + /// The const value type of the map.
1.57 + typedef const Value ConstValue;
1.58 + /// The const reference type of the map;
1.59 + typedef const Value& ConstReference;
1.60 + /// The pointer type of the map;
1.61 + typedef const Value* ConstPointer;
1.62 +
1.63 +
1.64 typedef A Allocator;
1.65
1.66
1.67 + /** Default constructor for the map.
1.68 + */
1.69 Map() : values(0), capacity(0) {}
1.70
1.71 + /** Graph and Registry initialized map constructor.
1.72 + */
1.73 Map(const Graph& g, MapRegistry& r) : MapBase(g, r) {
1.74 allocate_memory();
1.75 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
1.76 @@ -47,6 +82,8 @@
1.77 }
1.78 }
1.79
1.80 + /** Constructor to use default value to initialize the map.
1.81 + */
1.82 Map(const Graph& g, MapRegistry& r, const Value& v) : MapBase(g, r) {
1.83 allocate_memory();
1.84 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
1.85 @@ -55,6 +92,8 @@
1.86 }
1.87 }
1.88
1.89 + /** Constructor to copy a map of the same map type.
1.90 + */
1.91 Map(const Map& copy) : MapBase(*copy.graph, *copy.registry) {
1.92 capacity = copy.capacity;
1.93 if (capacity == 0) return;
1.94 @@ -65,6 +104,8 @@
1.95 }
1.96 }
1.97
1.98 + /** Constructor to copy a map of an other map type.
1.99 + */
1.100 template <typename CMap> Map(const CMap& copy)
1.101 : MapBase(copy), capacity(0), values(0) {
1.102 if (MapBase::getGraph()) {
1.103 @@ -75,6 +116,8 @@
1.104 }
1.105 }
1.106
1.107 + /** Assign operator to copy a map of the same map type.
1.108 + */
1.109 Map& operator=(const Map& copy) {
1.110 if (© == this) return *this;
1.111 if (capacity != 0) {
1.112 @@ -91,6 +134,8 @@
1.113 return *this;
1.114 }
1.115
1.116 + /** Assign operator to copy a map an other map type.
1.117 + */
1.118 template <typename CMap> Map& operator=(const CMap& copy) {
1.119 if (MapBase::getGraph()) {
1.120 MapBase::destroy();
1.121 @@ -105,6 +150,8 @@
1.122 return *this;
1.123 }
1.124
1.125 + /** The destructor of the map.
1.126 + */
1.127 virtual ~Map() {
1.128 if (capacity != 0) {
1.129 MapBase::destroy();
1.130 @@ -113,26 +160,34 @@
1.131 }
1.132
1.133
1.134 + /**
1.135 + * The subscript operator. The map can be subscripted by the
1.136 + * actual keys of the graph.
1.137 + */
1.138 Value& operator[](const KeyType& key) {
1.139 int id = MapBase::getGraph()->id(key);
1.140 return values[id];
1.141 }
1.142
1.143 + /**
1.144 + * The const subscript operator. The map can be subscripted by the
1.145 + * actual keys of the graph.
1.146 + */
1.147 const Value& operator[](const KeyType& key) const {
1.148 int id = MapBase::getGraph()->id(key);
1.149 return values[id];
1.150 }
1.151
1.152 - const Value& get(const KeyType& key) const {
1.153 - int id = MapBase::getGraph()->id(key);
1.154 - return values[id];
1.155 - }
1.156 -
1.157 + /** Setter function of the map. Equivalent with map[key] = val.
1.158 + * This is a compatibility feature with the not dereferable maps.
1.159 + */
1.160 void set(const KeyType& key, const Value& val) {
1.161 int id = MapBase::getGraph()->id(key);
1.162 values[id] = val;
1.163 }
1.164
1.165 + /** Add a new key to the map. It called by the map registry.
1.166 + */
1.167 void add(const KeyType& key) {
1.168 int id = MapBase::getGraph()->id(key);
1.169 if (id >= capacity) {
1.170 @@ -155,11 +210,15 @@
1.171 allocator.construct(&(values[id]), Value());
1.172 }
1.173
1.174 + /** Erase a key from the map. It called by the map registry.
1.175 + */
1.176 void erase(const KeyType& key) {
1.177 int id = MapBase::getGraph()->id(key);
1.178 allocator.destroy(&(values[id]));
1.179 }
1.180
1.181 + /** Clear the data structure.
1.182 + */
1.183 void clear() {
1.184 if (capacity != 0) {
1.185 MapBase::destroy();
1.186 @@ -168,6 +227,9 @@
1.187 }
1.188 }
1.189
1.190 + /** Compatible iterator with the stl maps' iterators.
1.191 + * It iterates on pairs of a key and a value.
1.192 + */
1.193 class iterator {
1.194 friend class Map;
1.195 friend class const_iterator;
1.196 @@ -371,9 +433,8 @@
1.197 Allocator allocator;
1.198 };
1.199 };
1.200 -
1.201 +
1.202 /// @}
1.203 -
1.204
1.205 }
1.206