src/hugo/default_map.h
changeset 893 89d5c283a485
parent 822 88226d9fe821
child 897 ef09eee53b09
equal deleted inserted replaced
0:dd9ad1a8160e 1:908fa809fec7
    27 
    27 
    28 
    28 
    29   /** Macro to implement the DefaultMap.
    29   /** Macro to implement the DefaultMap.
    30    */
    30    */
    31 #define DEFAULT_MAP_BODY(DynMap, Value) \
    31 #define DEFAULT_MAP_BODY(DynMap, Value) \
    32   { \
    32 { \
    33     typedef DynMap<MapRegistry, Value> MapImpl; \
    33 \
    34   \
    34 public: \
    35   public: \
    35 \
    36   \
    36 typedef DynMap<MapRegistry, Value> Parent; \
    37     typedef typename MapRegistry::Graph Graph; \
    37 \
    38   \
    38 typedef typename MapRegistry::Graph Graph; \
    39     DefaultMap() : MapImpl() {} \
    39 \
    40   \
    40 DefaultMap() : Parent() {} \
    41     DefaultMap(const Graph& g, MapRegistry& r) : MapImpl(g, r) {} \
    41 DefaultMap(const Graph& g, MapRegistry& r) : Parent(g, r) {} \
    42   \
    42 DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
    43     DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
    43   : Parent(g, r, v) {} \
    44       : MapImpl(g, r, v) {} \
    44 DefaultMap(const DefaultMap& copy) \
    45   \
    45   : Parent(static_cast<const Parent&>(copy)) {} \
    46     DefaultMap(const DefaultMap& copy) \
    46 template <typename TT> \
    47       : MapImpl(static_cast<const MapImpl&>(copy)) {} \
    47 DefaultMap(const DefaultMap<MapRegistry, TT>& copy) { \
    48   \
    48   Parent::MapBase::operator= \
    49     template <typename CMap> DefaultMap(const CMap& copy) : MapImpl(copy) {} \
    49     (static_cast<const typename Parent::MapBase&>(copy)); \
    50   \
    50   if (Parent::getGraph()) { \
    51     DefaultMap& operator=(const DefaultMap& copy) { \
    51     for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
    52       MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
    52       Parent::add(it); \
    53       return *this; \
    53       Parent::operator[](it) = copy[it]; \
    54     } \
    54     } \
    55   \
    55   } \
    56     template <typename CMap> DefaultMap& operator=(const CMap& copy) { \
    56 } \
    57       MapImpl::operator=(copy); \
    57 DefaultMap& operator=(const DefaultMap& copy) { \
    58       return *this; \
    58   Parent::operator=(static_cast<const Parent&>(copy)); \
       
    59   return *this; \
       
    60 } \
       
    61 template <typename TT> \
       
    62 DefaultMap& operator=(const DefaultMap<MapRegistry, TT>& copy) { \
       
    63   Parent::clear(); \
       
    64   Parent::MapBase::operator=(copy); \
       
    65   if (Parent::getGraph()) { \
       
    66     for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
       
    67       Parent::add(it); \
       
    68       Parent::operator[](it) = copy[it]; \
    59     } \
    69     } \
    60   \
    70   } \
    61   };
    71   return *this; \
       
    72 } \
       
    73 };
    62 
    74 
    63 
    75 
    64   template <typename MapRegistry, typename Type>
    76   template <typename MapRegistry, typename Type>
    65   class DefaultMap : public ArrayMap<MapRegistry, Type> 
    77   class DefaultMap : public ArrayMap<MapRegistry, Type> 
    66   DEFAULT_MAP_BODY(ArrayMap, Type);
    78   DEFAULT_MAP_BODY(ArrayMap, Type);