src/hugo/default_map_factory.h
author alpar
Mon, 06 Sep 2004 17:12:00 +0000
changeset 810 e9fbc747ca47
parent 798 6d1abeb62dd3
permissions -rw-r--r--
Kruskal alg. (src/hugo/kruskal.h, src/test/kruskal_test.cc) is (almost) done.
- Some input adaptor is still missing.
- The class and function names should be revised.
- Docs still needs some improvement.
deba@798
     1
// -*- c++ -*-
deba@798
     2
#ifndef DEFAULT_MAP_FACTORY_H
deba@798
     3
#define DEFAULT_MAP_FACTORY_H
deba@798
     4
deba@798
     5
deba@798
     6
#include <hugo/array_map_factory.h>
deba@798
     7
#include <hugo/vector_map_factory.h>
deba@798
     8
deba@799
     9
///\ingroup graphmapfactory
deba@799
    10
///\file
deba@799
    11
///\brief Graph maps that construates and destruates
deba@799
    12
///their elements dynamically.
deba@799
    13
deba@798
    14
namespace hugo {
deba@798
    15
deba@799
    16
/// \addtogroup graphmapfactory
deba@799
    17
/// @{
deba@799
    18
deba@798
    19
#define DEFAULT_MAP_BODY(Factory, Val) \
deba@798
    20
  { \
deba@798
    21
    typedef typename Factory<MapRegistry>::template Map<Val> MapImpl; \
deba@798
    22
  \
deba@798
    23
  public: \
deba@798
    24
  \
deba@798
    25
    typedef typename MapRegistry::Graph Graph; \
deba@799
    26
    typedef typename MapRegistry::KeyType KeyType; \
deba@798
    27
    typedef typename MapRegistry::KeyIt KeyIt; \
deba@798
    28
    typedef Val Value; \
deba@798
    29
  \
deba@798
    30
    typedef typename MapRegistry::MapBase MapBase; \
deba@798
    31
  \
deba@798
    32
    DefaultMap() : MapImpl() {} \
deba@798
    33
  \
deba@798
    34
    DefaultMap(const Graph& g, MapRegistry& r) : MapImpl(g, r) {} \
deba@798
    35
  \
deba@798
    36
    DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
deba@798
    37
      : MapImpl(g, r, v) {} \
deba@798
    38
  \
deba@798
    39
    DefaultMap(const DefaultMap& copy) \
deba@798
    40
      : MapImpl(static_cast<const MapImpl&>(copy)) {} \
deba@798
    41
  \
deba@798
    42
    template <typename CMap> DefaultMap(const CMap& copy) : MapImpl(copy) {} \
deba@798
    43
  \
deba@798
    44
    DefaultMap& operator=(const DefaultMap& copy) { \
deba@798
    45
      MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
deba@798
    46
      return *this; \
deba@798
    47
    } \
deba@798
    48
  \
deba@798
    49
    template <typename CMap> DefaultMap& operator=(const CMap& copy) { \
deba@798
    50
      MapImpl::operator=(copy); \
deba@798
    51
      return *this; \
deba@798
    52
    } \
deba@798
    53
  \
deba@798
    54
  };
deba@798
    55
deba@798
    56
deba@798
    57
  template <typename MapRegistry, typename Type>
deba@798
    58
  class DefaultMap : public ArrayMapFactory<MapRegistry>::template Map<Type> 
deba@798
    59
  DEFAULT_MAP_BODY(ArrayMapFactory, Type);
deba@798
    60
deba@798
    61
  template <typename MapRegistry>
deba@798
    62
  class DefaultMap<MapRegistry, bool> 
deba@798
    63
    : public VectorMapFactory<MapRegistry>::template Map<bool> 
deba@798
    64
  DEFAULT_MAP_BODY(VectorMapFactory, bool);
deba@798
    65
deba@798
    66
  template <typename MapRegistry>
deba@798
    67
  class DefaultMap<MapRegistry, char> 
deba@798
    68
    : public VectorMapFactory<MapRegistry>::template Map<char> 
deba@798
    69
  DEFAULT_MAP_BODY(VectorMapFactory, char);
deba@798
    70
deba@798
    71
  template <typename MapRegistry>
deba@798
    72
  class DefaultMap<MapRegistry, int> 
deba@798
    73
    : public VectorMapFactory<MapRegistry>::template Map<int> 
deba@798
    74
  DEFAULT_MAP_BODY(VectorMapFactory, int);
deba@798
    75
deba@798
    76
  template <typename MapRegistry>
deba@798
    77
  class DefaultMap<MapRegistry, short> 
deba@798
    78
    : public VectorMapFactory<MapRegistry>::template Map<short> 
deba@798
    79
  DEFAULT_MAP_BODY(VectorMapFactory, short);
deba@798
    80
deba@798
    81
  template <typename MapRegistry>
deba@798
    82
  class DefaultMap<MapRegistry, long> 
deba@798
    83
    : public VectorMapFactory<MapRegistry>::template Map<long> 
deba@798
    84
  DEFAULT_MAP_BODY(VectorMapFactory, long);
deba@798
    85
deba@798
    86
  template <typename MapRegistry>
deba@798
    87
  class DefaultMap<MapRegistry, float> 
deba@798
    88
    : public VectorMapFactory<MapRegistry>::template Map<float> 
deba@798
    89
  DEFAULT_MAP_BODY(VectorMapFactory, float);
deba@798
    90
deba@798
    91
  template <typename MapRegistry>
deba@798
    92
  class DefaultMap<MapRegistry, double> 
deba@798
    93
    : public VectorMapFactory<MapRegistry>::template Map<double> 
deba@798
    94
  DEFAULT_MAP_BODY(VectorMapFactory, double);
deba@798
    95
deba@798
    96
  template <typename MapRegistry>
deba@798
    97
  class DefaultMap<MapRegistry, long double> 
deba@798
    98
    : public VectorMapFactory<MapRegistry>::template Map<long double> 
deba@798
    99
  DEFAULT_MAP_BODY(VectorMapFactory, long double);
deba@798
   100
deba@798
   101
  template <typename MapRegistry, typename Type>
deba@798
   102
  class DefaultMap<MapRegistry, Type*>
deba@798
   103
    : public VectorMapFactory<MapRegistry>::template Map<Type*> 
deba@798
   104
  DEFAULT_MAP_BODY(VectorMapFactory, Type*);
deba@798
   105
deba@799
   106
deba@799
   107
  /** The DefaultMapFactory template class is a factory class
deba@799
   108
   *  to create maps for the edge and nodes. This map factory
deba@799
   109
   *  uses the VectorMapFactory if the ValueType is a primitive
deba@799
   110
   *  type and the ArrayMapFactory for the other cases.
deba@799
   111
   *
deba@799
   112
   *  The template parameter is the MapRegistry that the maps
deba@799
   113
   *  will belong to.
deba@799
   114
   */
deba@799
   115
deba@798
   116
  template <typename MapRegistry>
deba@798
   117
  class DefaultMapFactory {
deba@798
   118
		
deba@798
   119
  public:
deba@799
   120
    /// The graph type of the maps. 
deba@798
   121
    typedef typename MapRegistry::Graph Graph;
deba@799
   122
    /// The key type of the maps.
deba@799
   123
    typedef typename MapRegistry::KeyType KeyType;
deba@799
   124
    /// The iterator to iterate on the keys.
deba@798
   125
    typedef typename MapRegistry::KeyIt KeyIt;
deba@798
   126
deba@799
   127
    /// The MapBase of the Map which imlements the core regisitry function.
deba@798
   128
    typedef typename MapRegistry::MapBase MapBase;
deba@799
   129
		
deba@798
   130
deba@799
   131
    /** The template Map type.
deba@799
   132
     */
deba@798
   133
    template <typename V> 
deba@798
   134
    class Map : public DefaultMap<MapRegistry, V> {
deba@798
   135
deba@798
   136
      typedef DefaultMap<MapRegistry, V> MapImpl;
deba@798
   137
deba@798
   138
    public:
deba@798
   139
      
deba@798
   140
      typedef V Value;
deba@798
   141
deba@799
   142
      /** Default constructor for the map.
deba@799
   143
       */
deba@798
   144
      Map() : MapImpl() {}
deba@798
   145
deba@799
   146
      /** Graph and Registry initialized map constructor.
deba@799
   147
       */
deba@798
   148
      Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
deba@798
   149
deba@799
   150
      /** Constructor to use default value to initialize the map. 
deba@799
   151
       */
deba@798
   152
      Map(const Graph& g, MapRegistry& r, const Value& v) : MapImpl(g, r, v) {}
deba@798
   153
deba@799
   154
      /** Constructor to copy a map of the same map type.
deba@799
   155
       */
deba@798
   156
      Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {}
deba@798
   157
deba@799
   158
      /** Constructor to copy a map of an other map type.
deba@799
   159
       */
deba@798
   160
      template <typename CMap> Map(const CMap& copy) : MapImpl(copy) {}
deba@798
   161
deba@799
   162
      /** Assign operator to copy a map of the same map type.
deba@799
   163
       */
deba@798
   164
      Map& operator=(const Map& copy) {
deba@798
   165
	MapImpl::operator=(static_cast<const MapImpl&>(copy));
deba@798
   166
	return *this;
deba@798
   167
      }
deba@798
   168
deba@799
   169
      /** Assign operator to copy a map an other map type.
deba@799
   170
       */
deba@798
   171
      template <typename CMap> Map& operator=(const CMap& copy) {
deba@798
   172
	MapImpl::operator=(copy);
deba@798
   173
	return *this;
deba@798
   174
      }
deba@798
   175
deba@798
   176
    };
deba@798
   177
deba@798
   178
  };
deba@798
   179
}
deba@798
   180
deba@798
   181
#endif