src/hugo/default_map_factory.h
changeset 821 283a7fe3a00e
parent 798 6d1abeb62dd3
equal deleted inserted replaced
0:733272dbe480 1:92041f6c8cb5
     4 
     4 
     5 
     5 
     6 #include <hugo/array_map_factory.h>
     6 #include <hugo/array_map_factory.h>
     7 #include <hugo/vector_map_factory.h>
     7 #include <hugo/vector_map_factory.h>
     8 
     8 
       
     9 ///\ingroup graphmapfactory
       
    10 ///\file
       
    11 ///\brief Graph maps that construates and destruates
       
    12 ///their elements dynamically.
       
    13 
     9 namespace hugo {
    14 namespace hugo {
       
    15 
       
    16 /// \addtogroup graphmapfactory
       
    17 /// @{
    10 
    18 
    11 #define DEFAULT_MAP_BODY(Factory, Val) \
    19 #define DEFAULT_MAP_BODY(Factory, Val) \
    12   { \
    20   { \
    13     typedef typename Factory<MapRegistry>::template Map<Val> MapImpl; \
    21     typedef typename Factory<MapRegistry>::template Map<Val> MapImpl; \
    14   \
    22   \
    15   public: \
    23   public: \
    16   \
    24   \
    17     typedef typename MapRegistry::Graph Graph; \
    25     typedef typename MapRegistry::Graph Graph; \
    18     typedef typename MapRegistry::Key Key; \
    26     typedef typename MapRegistry::KeyType KeyType; \
    19     typedef typename MapRegistry::KeyIt KeyIt; \
    27     typedef typename MapRegistry::KeyIt KeyIt; \
    20     typedef Val Value; \
    28     typedef Val Value; \
    21   \
    29   \
    22     typedef typename MapRegistry::MapBase MapBase; \
    30     typedef typename MapRegistry::MapBase MapBase; \
    23   \
    31   \
    93   template <typename MapRegistry, typename Type>
   101   template <typename MapRegistry, typename Type>
    94   class DefaultMap<MapRegistry, Type*>
   102   class DefaultMap<MapRegistry, Type*>
    95     : public VectorMapFactory<MapRegistry>::template Map<Type*> 
   103     : public VectorMapFactory<MapRegistry>::template Map<Type*> 
    96   DEFAULT_MAP_BODY(VectorMapFactory, Type*);
   104   DEFAULT_MAP_BODY(VectorMapFactory, Type*);
    97 
   105 
       
   106 
       
   107   /** The DefaultMapFactory template class is a factory class
       
   108    *  to create maps for the edge and nodes. This map factory
       
   109    *  uses the VectorMapFactory if the ValueType is a primitive
       
   110    *  type and the ArrayMapFactory for the other cases.
       
   111    *
       
   112    *  The template parameter is the MapRegistry that the maps
       
   113    *  will belong to.
       
   114    */
       
   115 
    98   template <typename MapRegistry>
   116   template <typename MapRegistry>
    99   class DefaultMapFactory {
   117   class DefaultMapFactory {
   100 		
   118 		
   101   public:
   119   public:
   102 		
   120     /// The graph type of the maps. 
   103     typedef typename MapRegistry::Graph Graph;
   121     typedef typename MapRegistry::Graph Graph;
   104     typedef typename MapRegistry::Key Key;
   122     /// The key type of the maps.
       
   123     typedef typename MapRegistry::KeyType KeyType;
       
   124     /// The iterator to iterate on the keys.
   105     typedef typename MapRegistry::KeyIt KeyIt;
   125     typedef typename MapRegistry::KeyIt KeyIt;
   106 
   126 
       
   127     /// The MapBase of the Map which imlements the core regisitry function.
   107     typedef typename MapRegistry::MapBase MapBase;
   128     typedef typename MapRegistry::MapBase MapBase;
       
   129 		
   108 
   130 
       
   131     /** The template Map type.
       
   132      */
   109     template <typename V> 
   133     template <typename V> 
   110     class Map : public DefaultMap<MapRegistry, V> {
   134     class Map : public DefaultMap<MapRegistry, V> {
   111 
   135 
   112       typedef DefaultMap<MapRegistry, V> MapImpl;
   136       typedef DefaultMap<MapRegistry, V> MapImpl;
   113 
   137 
   114     public:
   138     public:
   115       
   139       
   116       typedef V Value;
   140       typedef V Value;
   117 
   141 
       
   142       /** Default constructor for the map.
       
   143        */
   118       Map() : MapImpl() {}
   144       Map() : MapImpl() {}
   119 
   145 
       
   146       /** Graph and Registry initialized map constructor.
       
   147        */
   120       Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
   148       Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
   121 
   149 
       
   150       /** Constructor to use default value to initialize the map. 
       
   151        */
   122       Map(const Graph& g, MapRegistry& r, const Value& v) : MapImpl(g, r, v) {}
   152       Map(const Graph& g, MapRegistry& r, const Value& v) : MapImpl(g, r, v) {}
   123 
   153 
       
   154       /** Constructor to copy a map of the same map type.
       
   155        */
   124       Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {}
   156       Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {}
   125 
   157 
       
   158       /** Constructor to copy a map of an other map type.
       
   159        */
   126       template <typename CMap> Map(const CMap& copy) : MapImpl(copy) {}
   160       template <typename CMap> Map(const CMap& copy) : MapImpl(copy) {}
   127 
   161 
       
   162       /** Assign operator to copy a map of the same map type.
       
   163        */
   128       Map& operator=(const Map& copy) {
   164       Map& operator=(const Map& copy) {
   129 	MapImpl::operator=(static_cast<const MapImpl&>(copy));
   165 	MapImpl::operator=(static_cast<const MapImpl&>(copy));
   130 	return *this;
   166 	return *this;
   131       }
   167       }
   132 
   168 
       
   169       /** Assign operator to copy a map an other map type.
       
   170        */
   133       template <typename CMap> Map& operator=(const CMap& copy) {
   171       template <typename CMap> Map& operator=(const CMap& copy) {
   134 	MapImpl::operator=(copy);
   172 	MapImpl::operator=(copy);
   135 	return *this;
   173 	return *this;
   136       }
   174       }
   137 
   175