diff -r 6d1abeb62dd3 -r 3393abe30678 src/hugo/array_map_factory.h --- a/src/hugo/array_map_factory.h Fri Sep 03 15:11:17 2004 +0000 +++ b/src/hugo/array_map_factory.h Fri Sep 03 15:32:03 2004 +0000 @@ -12,33 +12,68 @@ ///their elements dynamically. namespace hugo { - + + /// \addtogroup graphmapfactory /// @{ + + /** The ArrayMapFactory template class is a factory class + * to create maps for the edge and nodes. This map factory + * uses the allocators to implement the container function. + * + * The template parameter is the MapRegistry that the maps + * will belong to. + */ - ///. - template class ArrayMapFactory { + template + class ArrayMapFactory { public: + /// The graph type of the maps. typedef typename MapRegistry::Graph Graph; + /// The key type of the maps. typedef typename MapRegistry::KeyType KeyType; + /// The iterator to iterate on the keys. typedef typename MapRegistry::KeyIt KeyIt; + /// The MapBase of the Map which imlements the core regisitry function. typedef typename MapRegistry::MapBase MapBase; + /** The template Map type. + */ template > class Map : public MapBase { public: + /// The value type of the map. + typedef V ValueType; + + /// The value type of the map. typedef V Value; - typedef V ValueType; + /// The reference type of the map; + typedef Value& Reference; + /// The pointer type of the map; + typedef Value* Pointer; + + /// The const value type of the map. + typedef const Value ConstValue; + /// The const reference type of the map; + typedef const Value& ConstReference; + /// The pointer type of the map; + typedef const Value* ConstPointer; + + typedef A Allocator; + /** Default constructor for the map. + */ Map() : values(0), capacity(0) {} + /** Graph and Registry initialized map constructor. + */ Map(const Graph& g, MapRegistry& r) : MapBase(g, r) { allocate_memory(); for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { @@ -47,6 +82,8 @@ } } + /** Constructor to use default value to initialize the map. + */ Map(const Graph& g, MapRegistry& r, const Value& v) : MapBase(g, r) { allocate_memory(); for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { @@ -55,6 +92,8 @@ } } + /** Constructor to copy a map of the same map type. + */ Map(const Map& copy) : MapBase(*copy.graph, *copy.registry) { capacity = copy.capacity; if (capacity == 0) return; @@ -65,6 +104,8 @@ } } + /** Constructor to copy a map of an other map type. + */ template Map(const CMap& copy) : MapBase(copy), capacity(0), values(0) { if (MapBase::getGraph()) { @@ -75,6 +116,8 @@ } } + /** Assign operator to copy a map of the same map type. + */ Map& operator=(const Map& copy) { if (© == this) return *this; if (capacity != 0) { @@ -91,6 +134,8 @@ return *this; } + /** Assign operator to copy a map an other map type. + */ template Map& operator=(const CMap& copy) { if (MapBase::getGraph()) { MapBase::destroy(); @@ -105,6 +150,8 @@ return *this; } + /** The destructor of the map. + */ virtual ~Map() { if (capacity != 0) { MapBase::destroy(); @@ -113,26 +160,34 @@ } + /** + * The subscript operator. The map can be subscripted by the + * actual keys of the graph. + */ Value& operator[](const KeyType& key) { int id = MapBase::getGraph()->id(key); return values[id]; } + /** + * The const subscript operator. The map can be subscripted by the + * actual keys of the graph. + */ const Value& operator[](const KeyType& key) const { int id = MapBase::getGraph()->id(key); return values[id]; } - const Value& get(const KeyType& key) const { - int id = MapBase::getGraph()->id(key); - return values[id]; - } - + /** Setter function of the map. Equivalent with map[key] = val. + * This is a compatibility feature with the not dereferable maps. + */ void set(const KeyType& key, const Value& val) { int id = MapBase::getGraph()->id(key); values[id] = val; } + /** Add a new key to the map. It called by the map registry. + */ void add(const KeyType& key) { int id = MapBase::getGraph()->id(key); if (id >= capacity) { @@ -155,11 +210,15 @@ allocator.construct(&(values[id]), Value()); } + /** Erase a key from the map. It called by the map registry. + */ void erase(const KeyType& key) { int id = MapBase::getGraph()->id(key); allocator.destroy(&(values[id])); } + /** Clear the data structure. + */ void clear() { if (capacity != 0) { MapBase::destroy(); @@ -168,6 +227,9 @@ } } + /** Compatible iterator with the stl maps' iterators. + * It iterates on pairs of a key and a value. + */ class iterator { friend class Map; friend class const_iterator; @@ -371,9 +433,8 @@ Allocator allocator; }; }; - + /// @} - }