(none)
authordeba
Fri, 03 Sep 2004 15:32:03 +0000
changeset 7993393abe30678
parent 798 6d1abeb62dd3
child 800 b70a494b4912
(none)
src/hugo/array_map_factory.h
src/hugo/default_map_factory.h
src/hugo/vector_map_factory.h
     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 (&copy == 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  
     2.1 --- a/src/hugo/default_map_factory.h	Fri Sep 03 15:11:17 2004 +0000
     2.2 +++ b/src/hugo/default_map_factory.h	Fri Sep 03 15:32:03 2004 +0000
     2.3 @@ -6,8 +6,16 @@
     2.4  #include <hugo/array_map_factory.h>
     2.5  #include <hugo/vector_map_factory.h>
     2.6  
     2.7 +///\ingroup graphmapfactory
     2.8 +///\file
     2.9 +///\brief Graph maps that construates and destruates
    2.10 +///their elements dynamically.
    2.11 +
    2.12  namespace hugo {
    2.13  
    2.14 +/// \addtogroup graphmapfactory
    2.15 +/// @{
    2.16 +
    2.17  #define DEFAULT_MAP_BODY(Factory, Val) \
    2.18    { \
    2.19      typedef typename Factory<MapRegistry>::template Map<Val> MapImpl; \
    2.20 @@ -15,7 +23,7 @@
    2.21    public: \
    2.22    \
    2.23      typedef typename MapRegistry::Graph Graph; \
    2.24 -    typedef typename MapRegistry::Key Key; \
    2.25 +    typedef typename MapRegistry::KeyType KeyType; \
    2.26      typedef typename MapRegistry::KeyIt KeyIt; \
    2.27      typedef Val Value; \
    2.28    \
    2.29 @@ -95,17 +103,33 @@
    2.30      : public VectorMapFactory<MapRegistry>::template Map<Type*> 
    2.31    DEFAULT_MAP_BODY(VectorMapFactory, Type*);
    2.32  
    2.33 +
    2.34 +  /** The DefaultMapFactory template class is a factory class
    2.35 +   *  to create maps for the edge and nodes. This map factory
    2.36 +   *  uses the VectorMapFactory if the ValueType is a primitive
    2.37 +   *  type and the ArrayMapFactory for the other cases.
    2.38 +   *
    2.39 +   *  The template parameter is the MapRegistry that the maps
    2.40 +   *  will belong to.
    2.41 +   */
    2.42 +
    2.43    template <typename MapRegistry>
    2.44    class DefaultMapFactory {
    2.45  		
    2.46    public:
    2.47 -		
    2.48 +    /// The graph type of the maps. 
    2.49      typedef typename MapRegistry::Graph Graph;
    2.50 -    typedef typename MapRegistry::Key Key;
    2.51 +    /// The key type of the maps.
    2.52 +    typedef typename MapRegistry::KeyType KeyType;
    2.53 +    /// The iterator to iterate on the keys.
    2.54      typedef typename MapRegistry::KeyIt KeyIt;
    2.55  
    2.56 +    /// The MapBase of the Map which imlements the core regisitry function.
    2.57      typedef typename MapRegistry::MapBase MapBase;
    2.58 +		
    2.59  
    2.60 +    /** The template Map type.
    2.61 +     */
    2.62      template <typename V> 
    2.63      class Map : public DefaultMap<MapRegistry, V> {
    2.64  
    2.65 @@ -115,21 +139,35 @@
    2.66        
    2.67        typedef V Value;
    2.68  
    2.69 +      /** Default constructor for the map.
    2.70 +       */
    2.71        Map() : MapImpl() {}
    2.72  
    2.73 +      /** Graph and Registry initialized map constructor.
    2.74 +       */
    2.75        Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
    2.76  
    2.77 +      /** Constructor to use default value to initialize the map. 
    2.78 +       */
    2.79        Map(const Graph& g, MapRegistry& r, const Value& v) : MapImpl(g, r, v) {}
    2.80  
    2.81 +      /** Constructor to copy a map of the same map type.
    2.82 +       */
    2.83        Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {}
    2.84  
    2.85 +      /** Constructor to copy a map of an other map type.
    2.86 +       */
    2.87        template <typename CMap> Map(const CMap& copy) : MapImpl(copy) {}
    2.88  
    2.89 +      /** Assign operator to copy a map of the same map type.
    2.90 +       */
    2.91        Map& operator=(const Map& copy) {
    2.92  	MapImpl::operator=(static_cast<const MapImpl&>(copy));
    2.93  	return *this;
    2.94        }
    2.95  
    2.96 +      /** Assign operator to copy a map an other map type.
    2.97 +       */
    2.98        template <typename CMap> Map& operator=(const CMap& copy) {
    2.99  	MapImpl::operator=(copy);
   2.100  	return *this;
     3.1 --- a/src/hugo/vector_map_factory.h	Fri Sep 03 15:11:17 2004 +0000
     3.2 +++ b/src/hugo/vector_map_factory.h	Fri Sep 03 15:32:03 2004 +0000
     3.3 @@ -128,11 +128,7 @@
     3.4         * The subscript operator. The map can be subscripted by the
     3.5         * actual keys of the graph. 
     3.6         */
     3.7 -<<<<<<< .mine
     3.8 -      Reference operator[](const Key& key) {
     3.9 -=======
    3.10 -      typename Container::reference operator[](const KeyType& key) {
    3.11 ->>>>>>> .r1091
    3.12 +      Reference operator[](const KeyType& key) {
    3.13  	int id = getGraph()->id(key);
    3.14  	return container[id];
    3.15        } 
    3.16 @@ -141,11 +137,7 @@
    3.17         * The const subscript operator. The map can be subscripted by the
    3.18         * actual keys of the graph. 
    3.19         */
    3.20 -<<<<<<< .mine
    3.21 -      ConstReference operator[](const Key& key) const {
    3.22 -=======
    3.23 -      typename Container::const_reference operator[](const KeyType& key) const {
    3.24 ->>>>>>> .r1091
    3.25 +      ConstReference operator[](const KeyType& key) const {
    3.26  	int id = getGraph()->id(key);
    3.27  	return container[id];
    3.28        }
    3.29 @@ -209,7 +201,7 @@
    3.30  	  friend class iterator;
    3.31  	private:
    3.32  	  Reference data;
    3.33 -	  Pointer(const KeyType& key, Value& val) : data(key, val) {}
    3.34 +	  Pointer(const KeyType& key, Map::Reference val) : data(key, val) {}
    3.35  	public:
    3.36  	  Reference* operator->() {return &data;}
    3.37  	};
    3.38 @@ -300,7 +292,8 @@
    3.39  	  friend class const_iterator;
    3.40  	private:
    3.41  	  Reference data;
    3.42 -	  Pointer(const KeyType& key, const Value& val) : data(key, val) {}
    3.43 +	  Pointer(const KeyType& key, Map::ConstReference val) 
    3.44 +	    : data(key, val) {}
    3.45  	public:
    3.46  	  Reference* operator->() {return &data;}
    3.47  	};