alpar@906
|
1 |
/* -*- C++ -*-
|
alpar@921
|
2 |
* src/lemon/default_map.h - Part of LEMON, a generic C++ optimization library
|
alpar@906
|
3 |
*
|
alpar@906
|
4 |
* Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@906
|
5 |
* (Egervary Combinatorial Optimization Research Group, EGRES).
|
alpar@906
|
6 |
*
|
alpar@906
|
7 |
* Permission to use, modify and distribute this software is granted
|
alpar@906
|
8 |
* provided that this copyright notice appears in all copies. For
|
alpar@906
|
9 |
* precise terms see the accompanying LICENSE file.
|
alpar@906
|
10 |
*
|
alpar@906
|
11 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@906
|
12 |
* express or implied, and with no claim as to its suitability for any
|
alpar@906
|
13 |
* purpose.
|
alpar@906
|
14 |
*
|
alpar@906
|
15 |
*/
|
alpar@906
|
16 |
|
alpar@921
|
17 |
#ifndef LEMON_DEFAULT_MAP_H
|
alpar@921
|
18 |
#define LEMON_DEFAULT_MAP_H
|
deba@822
|
19 |
|
deba@822
|
20 |
|
alpar@921
|
21 |
#include <lemon/array_map.h>
|
alpar@921
|
22 |
#include <lemon/vector_map.h>
|
deba@822
|
23 |
|
deba@822
|
24 |
///\ingroup graphmaps
|
deba@822
|
25 |
///\file
|
klao@946
|
26 |
///\brief Graph maps that construct and destruct
|
deba@822
|
27 |
///their elements dynamically.
|
deba@822
|
28 |
|
alpar@921
|
29 |
namespace lemon {
|
deba@822
|
30 |
|
deba@822
|
31 |
/// \addtogroup graphmaps
|
deba@822
|
32 |
/// @{
|
deba@822
|
33 |
|
deba@822
|
34 |
/** The ArrayMap template class is graph map structure what
|
deba@822
|
35 |
* automatically updates the map when a key is added to or erased from
|
deba@822
|
36 |
* the map. This map uses the VectorMap if the ValueType is a primitive
|
deba@822
|
37 |
* type and the ArrayMap for the other cases.
|
deba@822
|
38 |
*
|
deba@822
|
39 |
* The template parameter is the MapRegistry that the maps
|
deba@822
|
40 |
* will belong to and the ValueType.
|
deba@822
|
41 |
*/
|
deba@822
|
42 |
|
deba@822
|
43 |
|
deba@822
|
44 |
|
klao@946
|
45 |
template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap, typename _Value>
|
klao@946
|
46 |
struct DefaultMapSelector {
|
klao@946
|
47 |
typedef ArrayMap<_Graph, _Item, _ItemIt, _IdMap, _Value> Map;
|
klao@946
|
48 |
};
|
deba@822
|
49 |
|
klao@946
|
50 |
// bool
|
klao@946
|
51 |
template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
|
klao@946
|
52 |
struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, bool> {
|
klao@946
|
53 |
typedef VectorMap<_Graph, _Item, _IdMap, bool> Map;
|
klao@946
|
54 |
};
|
deba@822
|
55 |
|
klao@946
|
56 |
// char
|
klao@946
|
57 |
template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
|
klao@946
|
58 |
struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, char> {
|
klao@946
|
59 |
typedef VectorMap<_Graph, _Item, _IdMap, char> Map;
|
klao@946
|
60 |
};
|
deba@822
|
61 |
|
klao@946
|
62 |
template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
|
klao@946
|
63 |
struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed char> {
|
klao@946
|
64 |
typedef VectorMap<_Graph, _Item, _IdMap, signed char> Map;
|
klao@946
|
65 |
};
|
deba@822
|
66 |
|
klao@946
|
67 |
template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
|
klao@946
|
68 |
struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned char> {
|
klao@946
|
69 |
typedef VectorMap<_Graph, _Item, _IdMap, unsigned char> Map;
|
klao@946
|
70 |
};
|
deba@822
|
71 |
|
deba@822
|
72 |
|
klao@946
|
73 |
// int
|
klao@946
|
74 |
template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
|
klao@946
|
75 |
struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed int> {
|
klao@946
|
76 |
typedef VectorMap<_Graph, _Item, _IdMap, signed int> Map;
|
klao@946
|
77 |
};
|
deba@822
|
78 |
|
klao@946
|
79 |
template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
|
klao@946
|
80 |
struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned int> {
|
klao@946
|
81 |
typedef VectorMap<_Graph, _Item, _IdMap, unsigned int> Map;
|
klao@946
|
82 |
};
|
deba@822
|
83 |
|
deba@822
|
84 |
|
klao@946
|
85 |
// short
|
klao@946
|
86 |
template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
|
klao@946
|
87 |
struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed short> {
|
klao@946
|
88 |
typedef VectorMap<_Graph, _Item, _IdMap, signed short> Map;
|
klao@946
|
89 |
};
|
deba@822
|
90 |
|
klao@946
|
91 |
template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
|
klao@946
|
92 |
struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned short> {
|
klao@946
|
93 |
typedef VectorMap<_Graph, _Item, _IdMap, unsigned short> Map;
|
klao@946
|
94 |
};
|
klao@946
|
95 |
|
klao@946
|
96 |
|
klao@946
|
97 |
// long
|
klao@946
|
98 |
template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
|
klao@946
|
99 |
struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed long> {
|
klao@946
|
100 |
typedef VectorMap<_Graph, _Item, _IdMap, signed long> Map;
|
klao@946
|
101 |
};
|
klao@946
|
102 |
|
klao@946
|
103 |
template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
|
klao@946
|
104 |
struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned long> {
|
klao@946
|
105 |
typedef VectorMap<_Graph, _Item, _IdMap, unsigned long> Map;
|
klao@946
|
106 |
};
|
klao@946
|
107 |
|
klao@946
|
108 |
// \todo handling long long type
|
klao@946
|
109 |
|
klao@946
|
110 |
|
klao@946
|
111 |
// float
|
klao@946
|
112 |
template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
|
klao@946
|
113 |
struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, float> {
|
klao@946
|
114 |
typedef VectorMap<_Graph, _Item, _IdMap, float> Map;
|
klao@946
|
115 |
};
|
klao@946
|
116 |
|
klao@946
|
117 |
|
klao@946
|
118 |
// double
|
klao@946
|
119 |
template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
|
klao@946
|
120 |
struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, double> {
|
klao@946
|
121 |
typedef VectorMap<_Graph, _Item, _IdMap, double> Map;
|
klao@946
|
122 |
};
|
klao@946
|
123 |
|
klao@946
|
124 |
|
klao@946
|
125 |
// long double
|
klao@946
|
126 |
template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
|
klao@946
|
127 |
struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, long double> {
|
klao@946
|
128 |
typedef VectorMap<_Graph, _Item, _IdMap, long double> Map;
|
klao@946
|
129 |
};
|
klao@946
|
130 |
|
klao@946
|
131 |
|
klao@946
|
132 |
// pointer
|
klao@946
|
133 |
template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap, typename _Ptr>
|
klao@946
|
134 |
struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Ptr*> {
|
klao@946
|
135 |
typedef VectorMap<_Graph, _Item, _IdMap, _Ptr*> Map;
|
klao@946
|
136 |
};
|
klao@946
|
137 |
|
klao@946
|
138 |
|
klao@946
|
139 |
|
klao@946
|
140 |
template <typename _Graph,
|
klao@946
|
141 |
typename _Item,
|
klao@946
|
142 |
typename _ItemIt,
|
klao@946
|
143 |
typename _IdMap,
|
klao@946
|
144 |
typename _Value>
|
klao@946
|
145 |
class DefaultMap : public DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Value>::Map {
|
klao@946
|
146 |
public:
|
klao@946
|
147 |
typedef typename DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Value>::Map Parent;
|
klao@946
|
148 |
typedef DefaultMap<_Graph, _Item, _ItemIt, _IdMap, bool> Map;
|
klao@946
|
149 |
|
klao@946
|
150 |
typedef typename Parent::Graph Graph;
|
klao@946
|
151 |
typedef typename Parent::Registry Registry;
|
klao@946
|
152 |
typedef typename Parent::ValueType ValueType;
|
klao@946
|
153 |
|
klao@946
|
154 |
DefaultMap(const Graph& _g, Registry& _r) : Parent(_g, _r) {}
|
klao@946
|
155 |
DefaultMap(const Graph& _g, Registry& _r, const ValueType& _v) : Parent(_g, _r, _v) {}
|
klao@946
|
156 |
};
|
klao@946
|
157 |
|
klao@946
|
158 |
|
klao@946
|
159 |
|
klao@946
|
160 |
template <typename _Base>
|
klao@946
|
161 |
class DefaultMappableGraphExtender : public _Base {
|
klao@946
|
162 |
public:
|
klao@946
|
163 |
|
klao@946
|
164 |
typedef DefaultMappableGraphExtender<_Base> Graph;
|
klao@946
|
165 |
typedef _Base Parent;
|
klao@946
|
166 |
|
klao@946
|
167 |
typedef typename Parent::Node Node;
|
klao@946
|
168 |
typedef typename Parent::NodeIt NodeIt;
|
klao@946
|
169 |
typedef typename Parent::NodeIdMap NodeIdMap;
|
klao@946
|
170 |
typedef typename Parent::NodeObserverRegistry NodeObserverRegistry;
|
klao@946
|
171 |
|
klao@946
|
172 |
typedef typename Parent::Edge Edge;
|
klao@946
|
173 |
typedef typename Parent::EdgeIt EdgeIt;
|
klao@946
|
174 |
typedef typename Parent::EdgeIdMap EdgeIdMap;
|
klao@946
|
175 |
typedef typename Parent::EdgeObserverRegistry EdgeObserverRegistry;
|
klao@946
|
176 |
|
klao@946
|
177 |
|
klao@946
|
178 |
|
klao@946
|
179 |
template <typename _Value>
|
klao@946
|
180 |
class NodeMap : public DefaultMap<Graph, Node, NodeIt, NodeIdMap, _Value> {
|
klao@946
|
181 |
public:
|
klao@946
|
182 |
typedef DefaultMappableGraphExtender<_Base> Graph;
|
klao@946
|
183 |
|
klao@946
|
184 |
typedef typename Graph::Node Node;
|
klao@946
|
185 |
typedef typename Graph::NodeIt NodeIt;
|
klao@946
|
186 |
typedef typename Graph::NodeIdMap NodeIdMap;
|
klao@946
|
187 |
|
klao@946
|
188 |
typedef DefaultMap<Graph, Node, NodeIt, NodeIdMap, _Value> Parent;
|
klao@946
|
189 |
|
klao@946
|
190 |
typedef typename Parent::Graph Graph;
|
klao@946
|
191 |
typedef typename Parent::ValueType ValueType;
|
klao@946
|
192 |
|
klao@946
|
193 |
NodeMap(const Graph& g)
|
klao@946
|
194 |
: Parent(g, g.getNodeObserverRegistry()) {}
|
klao@946
|
195 |
NodeMap(const Graph& g, const ValueType& v)
|
klao@946
|
196 |
: Parent(g, g.getNodeObserverRegistry(), v) {}
|
klao@946
|
197 |
|
klao@946
|
198 |
};
|
klao@946
|
199 |
|
klao@946
|
200 |
template <typename _Value>
|
klao@946
|
201 |
class EdgeMap : public DefaultMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> {
|
klao@946
|
202 |
public:
|
klao@946
|
203 |
typedef DefaultMappableGraphExtender<_Base> Graph;
|
klao@946
|
204 |
|
klao@946
|
205 |
typedef typename Graph::Edge Edge;
|
klao@946
|
206 |
typedef typename Graph::EdgeIt EdgeIt;
|
klao@946
|
207 |
typedef typename Graph::EdgeIdMap EdgeIdMap;
|
klao@946
|
208 |
|
klao@946
|
209 |
typedef DefaultMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> Parent;
|
klao@946
|
210 |
|
klao@946
|
211 |
typedef typename Parent::Graph Graph;
|
klao@946
|
212 |
typedef typename Parent::ValueType ValueType;
|
klao@946
|
213 |
|
klao@946
|
214 |
EdgeMap(const Graph& g)
|
klao@946
|
215 |
: Parent(g, g.getEdgeObserverRegistry()) {}
|
klao@946
|
216 |
EdgeMap(const Graph& g, const ValueType& v)
|
klao@946
|
217 |
: Parent(g, g.getEdgeObserverRegistry(), v) {}
|
klao@946
|
218 |
|
klao@946
|
219 |
};
|
klao@946
|
220 |
|
klao@946
|
221 |
};
|
klao@946
|
222 |
|
deba@822
|
223 |
|
deba@822
|
224 |
}
|
deba@822
|
225 |
|
deba@822
|
226 |
#endif
|