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