COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/default_map_factory.h @ 799:3393abe30678

Last change on this file since 799:3393abe30678 was 799:3393abe30678, checked in by Balazs Dezso, 20 years ago
File size: 5.2 KB
Line 
1// -*- c++ -*-
2#ifndef DEFAULT_MAP_FACTORY_H
3#define DEFAULT_MAP_FACTORY_H
4
5
6#include <hugo/array_map_factory.h>
7#include <hugo/vector_map_factory.h>
8
9///\ingroup graphmapfactory
10///\file
11///\brief Graph maps that construates and destruates
12///their elements dynamically.
13
14namespace hugo {
15
16/// \addtogroup graphmapfactory
17/// @{
18
19#define DEFAULT_MAP_BODY(Factory, Val) \
20  { \
21    typedef typename Factory<MapRegistry>::template Map<Val> MapImpl; \
22  \
23  public: \
24  \
25    typedef typename MapRegistry::Graph Graph; \
26    typedef typename MapRegistry::KeyType KeyType; \
27    typedef typename MapRegistry::KeyIt KeyIt; \
28    typedef Val Value; \
29  \
30    typedef typename MapRegistry::MapBase MapBase; \
31  \
32    DefaultMap() : MapImpl() {} \
33  \
34    DefaultMap(const Graph& g, MapRegistry& r) : MapImpl(g, r) {} \
35  \
36    DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
37      : MapImpl(g, r, v) {} \
38  \
39    DefaultMap(const DefaultMap& copy) \
40      : MapImpl(static_cast<const MapImpl&>(copy)) {} \
41  \
42    template <typename CMap> DefaultMap(const CMap& copy) : MapImpl(copy) {} \
43  \
44    DefaultMap& operator=(const DefaultMap& copy) { \
45      MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
46      return *this; \
47    } \
48  \
49    template <typename CMap> DefaultMap& operator=(const CMap& copy) { \
50      MapImpl::operator=(copy); \
51      return *this; \
52    } \
53  \
54  };
55
56
57  template <typename MapRegistry, typename Type>
58  class DefaultMap : public ArrayMapFactory<MapRegistry>::template Map<Type>
59  DEFAULT_MAP_BODY(ArrayMapFactory, Type);
60
61  template <typename MapRegistry>
62  class DefaultMap<MapRegistry, bool>
63    : public VectorMapFactory<MapRegistry>::template Map<bool>
64  DEFAULT_MAP_BODY(VectorMapFactory, bool);
65
66  template <typename MapRegistry>
67  class DefaultMap<MapRegistry, char>
68    : public VectorMapFactory<MapRegistry>::template Map<char>
69  DEFAULT_MAP_BODY(VectorMapFactory, char);
70
71  template <typename MapRegistry>
72  class DefaultMap<MapRegistry, int>
73    : public VectorMapFactory<MapRegistry>::template Map<int>
74  DEFAULT_MAP_BODY(VectorMapFactory, int);
75
76  template <typename MapRegistry>
77  class DefaultMap<MapRegistry, short>
78    : public VectorMapFactory<MapRegistry>::template Map<short>
79  DEFAULT_MAP_BODY(VectorMapFactory, short);
80
81  template <typename MapRegistry>
82  class DefaultMap<MapRegistry, long>
83    : public VectorMapFactory<MapRegistry>::template Map<long>
84  DEFAULT_MAP_BODY(VectorMapFactory, long);
85
86  template <typename MapRegistry>
87  class DefaultMap<MapRegistry, float>
88    : public VectorMapFactory<MapRegistry>::template Map<float>
89  DEFAULT_MAP_BODY(VectorMapFactory, float);
90
91  template <typename MapRegistry>
92  class DefaultMap<MapRegistry, double>
93    : public VectorMapFactory<MapRegistry>::template Map<double>
94  DEFAULT_MAP_BODY(VectorMapFactory, double);
95
96  template <typename MapRegistry>
97  class DefaultMap<MapRegistry, long double>
98    : public VectorMapFactory<MapRegistry>::template Map<long double>
99  DEFAULT_MAP_BODY(VectorMapFactory, long double);
100
101  template <typename MapRegistry, typename Type>
102  class DefaultMap<MapRegistry, Type*>
103    : public VectorMapFactory<MapRegistry>::template Map<Type*>
104  DEFAULT_MAP_BODY(VectorMapFactory, Type*);
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
116  template <typename MapRegistry>
117  class DefaultMapFactory {
118               
119  public:
120    /// The graph type of the maps.
121    typedef typename MapRegistry::Graph Graph;
122    /// The key type of the maps.
123    typedef typename MapRegistry::KeyType KeyType;
124    /// The iterator to iterate on the keys.
125    typedef typename MapRegistry::KeyIt KeyIt;
126
127    /// The MapBase of the Map which imlements the core regisitry function.
128    typedef typename MapRegistry::MapBase MapBase;
129               
130
131    /** The template Map type.
132     */
133    template <typename V>
134    class Map : public DefaultMap<MapRegistry, V> {
135
136      typedef DefaultMap<MapRegistry, V> MapImpl;
137
138    public:
139     
140      typedef V Value;
141
142      /** Default constructor for the map.
143       */
144      Map() : MapImpl() {}
145
146      /** Graph and Registry initialized map constructor.
147       */
148      Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
149
150      /** Constructor to use default value to initialize the map.
151       */
152      Map(const Graph& g, MapRegistry& r, const Value& v) : MapImpl(g, r, v) {}
153
154      /** Constructor to copy a map of the same map type.
155       */
156      Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {}
157
158      /** Constructor to copy a map of an other map type.
159       */
160      template <typename CMap> Map(const CMap& copy) : MapImpl(copy) {}
161
162      /** Assign operator to copy a map of the same map type.
163       */
164      Map& operator=(const Map& copy) {
165        MapImpl::operator=(static_cast<const MapImpl&>(copy));
166        return *this;
167      }
168
169      /** Assign operator to copy a map an other map type.
170       */
171      template <typename CMap> Map& operator=(const CMap& copy) {
172        MapImpl::operator=(copy);
173        return *this;
174      }
175
176    };
177
178  };
179}
180
181#endif
Note: See TracBrowser for help on using the repository browser.