# HG changeset patch # User deba # Date 1094225523 0 # Node ID 3393abe306787ab99ed4ffed5fa1e9253a72ed7e # Parent 6d1abeb62dd338bd96c59fc51bdbd19003d8ccba 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; }; }; - + /// @} - } diff -r 6d1abeb62dd3 -r 3393abe30678 src/hugo/default_map_factory.h --- a/src/hugo/default_map_factory.h Fri Sep 03 15:11:17 2004 +0000 +++ b/src/hugo/default_map_factory.h Fri Sep 03 15:32:03 2004 +0000 @@ -6,8 +6,16 @@ #include #include +///\ingroup graphmapfactory +///\file +///\brief Graph maps that construates and destruates +///their elements dynamically. + namespace hugo { +/// \addtogroup graphmapfactory +/// @{ + #define DEFAULT_MAP_BODY(Factory, Val) \ { \ typedef typename Factory::template Map MapImpl; \ @@ -15,7 +23,7 @@ public: \ \ typedef typename MapRegistry::Graph Graph; \ - typedef typename MapRegistry::Key Key; \ + typedef typename MapRegistry::KeyType KeyType; \ typedef typename MapRegistry::KeyIt KeyIt; \ typedef Val Value; \ \ @@ -95,17 +103,33 @@ : public VectorMapFactory::template Map DEFAULT_MAP_BODY(VectorMapFactory, Type*); + + /** The DefaultMapFactory template class is a factory class + * to create maps for the edge and nodes. This map factory + * uses the VectorMapFactory if the ValueType is a primitive + * type and the ArrayMapFactory for the other cases. + * + * The template parameter is the MapRegistry that the maps + * will belong to. + */ + template class DefaultMapFactory { public: - + /// The graph type of the maps. typedef typename MapRegistry::Graph Graph; - typedef typename MapRegistry::Key Key; + /// 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 DefaultMap { @@ -115,21 +139,35 @@ typedef V Value; + /** Default constructor for the map. + */ Map() : MapImpl() {} + /** Graph and Registry initialized map constructor. + */ Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {} + /** Constructor to use default value to initialize the map. + */ Map(const Graph& g, MapRegistry& r, const Value& v) : MapImpl(g, r, v) {} + /** Constructor to copy a map of the same map type. + */ Map(const Map& copy) : MapImpl(static_cast(copy)) {} + /** Constructor to copy a map of an other map type. + */ template Map(const CMap& copy) : MapImpl(copy) {} + /** Assign operator to copy a map of the same map type. + */ Map& operator=(const Map& copy) { MapImpl::operator=(static_cast(copy)); return *this; } + /** Assign operator to copy a map an other map type. + */ template Map& operator=(const CMap& copy) { MapImpl::operator=(copy); return *this; diff -r 6d1abeb62dd3 -r 3393abe30678 src/hugo/vector_map_factory.h --- a/src/hugo/vector_map_factory.h Fri Sep 03 15:11:17 2004 +0000 +++ b/src/hugo/vector_map_factory.h Fri Sep 03 15:32:03 2004 +0000 @@ -128,11 +128,7 @@ * The subscript operator. The map can be subscripted by the * actual keys of the graph. */ -<<<<<<< .mine - Reference operator[](const Key& key) { -======= - typename Container::reference operator[](const KeyType& key) { ->>>>>>> .r1091 + Reference operator[](const KeyType& key) { int id = getGraph()->id(key); return container[id]; } @@ -141,11 +137,7 @@ * The const subscript operator. The map can be subscripted by the * actual keys of the graph. */ -<<<<<<< .mine - ConstReference operator[](const Key& key) const { -======= - typename Container::const_reference operator[](const KeyType& key) const { ->>>>>>> .r1091 + ConstReference operator[](const KeyType& key) const { int id = getGraph()->id(key); return container[id]; } @@ -209,7 +201,7 @@ friend class iterator; private: Reference data; - Pointer(const KeyType& key, Value& val) : data(key, val) {} + Pointer(const KeyType& key, Map::Reference val) : data(key, val) {} public: Reference* operator->() {return &data;} }; @@ -300,7 +292,8 @@ friend class const_iterator; private: Reference data; - Pointer(const KeyType& key, const Value& val) : data(key, val) {} + Pointer(const KeyType& key, Map::ConstReference val) + : data(key, val) {} public: Reference* operator->() {return &data;} };