src/hugo/default_map.h
author deba
Fri, 17 Sep 2004 07:02:16 +0000
changeset 877 66dd225ca128
child 891 74589d20dbc3
permissions -rw-r--r--
Fix maps in the GraphWrappers.
     1 // -*- c++ -*-
     2 #ifndef DEFAULT_MAP_H
     3 #define DEFAULT_MAP_H
     4 
     5 
     6 #include <hugo/array_map.h>
     7 #include <hugo/vector_map.h>
     8 
     9 ///\ingroup graphmaps
    10 ///\file
    11 ///\brief Graph maps that construates and destruates
    12 ///their elements dynamically.
    13 
    14 namespace hugo {
    15 
    16 /// \addtogroup graphmaps
    17 /// @{
    18 
    19   /** The ArrayMap template class is graph map structure what
    20    *  automatically updates the map when a key is added to or erased from
    21    *  the map. This map uses the VectorMap if the ValueType is a primitive
    22    *  type and the ArrayMap for the other cases.
    23    *
    24    *  The template parameter is the MapRegistry that the maps
    25    *  will belong to and the ValueType.
    26    */
    27 
    28 
    29   /** Macro to implement the DefaultMap.
    30    */
    31 #define DEFAULT_MAP_BODY(DynMap, Value) \
    32   { \
    33     typedef DynMap<MapRegistry, Value> MapImpl; \
    34   \
    35   public: \
    36   \
    37     typedef typename MapRegistry::Graph Graph; \
    38   \
    39     DefaultMap() : MapImpl() {} \
    40   \
    41     DefaultMap(const Graph& g, MapRegistry& r) : MapImpl(g, r) {} \
    42   \
    43     DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
    44       : MapImpl(g, r, v) {} \
    45   \
    46     DefaultMap(const DefaultMap& copy) \
    47       : MapImpl(static_cast<const MapImpl&>(copy)) {} \
    48   \
    49     template <typename CMap> DefaultMap(const CMap& copy) : MapImpl(copy) {} \
    50   \
    51     DefaultMap& operator=(const DefaultMap& copy) { \
    52       MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
    53       return *this; \
    54     } \
    55   \
    56     template <typename CMap> DefaultMap& operator=(const CMap& copy) { \
    57       MapImpl::operator=(copy); \
    58       return *this; \
    59     } \
    60   \
    61   };
    62 
    63 
    64   template <typename MapRegistry, typename Type>
    65   class DefaultMap : public ArrayMap<MapRegistry, Type> 
    66   DEFAULT_MAP_BODY(ArrayMap, Type);
    67 
    68   template <typename MapRegistry>
    69   class DefaultMap<MapRegistry, bool> 
    70     : public VectorMap<MapRegistry, bool> 
    71   DEFAULT_MAP_BODY(VectorMap, bool);
    72 
    73   template <typename MapRegistry>
    74   class DefaultMap<MapRegistry, char> 
    75     : public VectorMap<MapRegistry, char> 
    76   DEFAULT_MAP_BODY(VectorMap, char);
    77 
    78   template <typename MapRegistry>
    79   class DefaultMap<MapRegistry, int> 
    80     : public VectorMap<MapRegistry, int> 
    81   DEFAULT_MAP_BODY(VectorMap, int);
    82 
    83   template <typename MapRegistry>
    84   class DefaultMap<MapRegistry, short> 
    85     : public VectorMap<MapRegistry, short> 
    86   DEFAULT_MAP_BODY(VectorMap, short);
    87 
    88   template <typename MapRegistry>
    89   class DefaultMap<MapRegistry, long> 
    90     : public VectorMap<MapRegistry, long> 
    91   DEFAULT_MAP_BODY(VectorMap, long);
    92 
    93   template <typename MapRegistry>
    94   class DefaultMap<MapRegistry, float> 
    95     : public VectorMap<MapRegistry, float> 
    96   DEFAULT_MAP_BODY(VectorMap, float);
    97 
    98   template <typename MapRegistry>
    99   class DefaultMap<MapRegistry, double> 
   100     : public VectorMap<MapRegistry, double> 
   101   DEFAULT_MAP_BODY(VectorMap, double);
   102 
   103   template <typename MapRegistry>
   104   class DefaultMap<MapRegistry, long double> 
   105     : public VectorMap<MapRegistry, long double> 
   106   DEFAULT_MAP_BODY(VectorMap, long double);
   107 
   108   template <typename MapRegistry, typename Type>
   109   class DefaultMap<MapRegistry, Type*>
   110     : public VectorMap<MapRegistry, Type*> 
   111   DEFAULT_MAP_BODY(VectorMap, Type*);
   112 
   113 }
   114 
   115 #endif