alpar@906
|
1 |
/* -*- C++ -*-
|
alpar@906
|
2 |
*
|
alpar@1956
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
alpar@1956
|
4 |
*
|
alpar@2553
|
5 |
* Copyright (C) 2003-2008
|
alpar@1956
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@1956
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@906
|
8 |
*
|
alpar@906
|
9 |
* Permission to use, modify and distribute this software is granted
|
alpar@906
|
10 |
* provided that this copyright notice appears in all copies. For
|
alpar@906
|
11 |
* precise terms see the accompanying LICENSE file.
|
alpar@906
|
12 |
*
|
alpar@906
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@906
|
14 |
* express or implied, and with no claim as to its suitability for any
|
alpar@906
|
15 |
* purpose.
|
alpar@906
|
16 |
*
|
alpar@906
|
17 |
*/
|
alpar@906
|
18 |
|
deba@1999
|
19 |
#ifndef LEMON_BITS_DEFAULT_MAP_H
|
deba@1999
|
20 |
#define LEMON_BITS_DEFAULT_MAP_H
|
deba@822
|
21 |
|
deba@822
|
22 |
|
deba@1307
|
23 |
#include <lemon/bits/array_map.h>
|
deba@1307
|
24 |
#include <lemon/bits/vector_map.h>
|
deba@2202
|
25 |
#include <lemon/bits/debug_map.h>
|
deba@822
|
26 |
|
deba@1996
|
27 |
///\ingroup graphbits
|
deba@822
|
28 |
///\file
|
deba@1999
|
29 |
///\brief Graph maps that construct and destruct their elements dynamically.
|
deba@822
|
30 |
|
alpar@921
|
31 |
namespace lemon {
|
deba@1966
|
32 |
|
deba@1979
|
33 |
|
deba@2333
|
34 |
#ifndef LEMON_USE_DEBUG_MAP
|
deba@822
|
35 |
|
deba@1966
|
36 |
template <typename _Graph, typename _Item, typename _Value>
|
deba@1966
|
37 |
struct DefaultMapSelector {
|
deba@1966
|
38 |
typedef ArrayMap<_Graph, _Item, _Value> Map;
|
deba@1966
|
39 |
};
|
deba@1966
|
40 |
|
klao@946
|
41 |
// bool
|
deba@1267
|
42 |
template <typename _Graph, typename _Item>
|
deba@1267
|
43 |
struct DefaultMapSelector<_Graph, _Item, bool> {
|
deba@980
|
44 |
typedef VectorMap<_Graph, _Item, bool> Map;
|
klao@946
|
45 |
};
|
deba@822
|
46 |
|
klao@946
|
47 |
// char
|
deba@1267
|
48 |
template <typename _Graph, typename _Item>
|
deba@1267
|
49 |
struct DefaultMapSelector<_Graph, _Item, char> {
|
deba@980
|
50 |
typedef VectorMap<_Graph, _Item, char> Map;
|
klao@946
|
51 |
};
|
deba@822
|
52 |
|
deba@1267
|
53 |
template <typename _Graph, typename _Item>
|
deba@1267
|
54 |
struct DefaultMapSelector<_Graph, _Item, signed char> {
|
deba@980
|
55 |
typedef VectorMap<_Graph, _Item, signed char> Map;
|
klao@946
|
56 |
};
|
deba@822
|
57 |
|
deba@1267
|
58 |
template <typename _Graph, typename _Item>
|
deba@1267
|
59 |
struct DefaultMapSelector<_Graph, _Item, unsigned char> {
|
deba@980
|
60 |
typedef VectorMap<_Graph, _Item, unsigned char> Map;
|
klao@946
|
61 |
};
|
deba@822
|
62 |
|
deba@822
|
63 |
|
klao@946
|
64 |
// int
|
deba@1267
|
65 |
template <typename _Graph, typename _Item>
|
deba@1267
|
66 |
struct DefaultMapSelector<_Graph, _Item, signed int> {
|
deba@980
|
67 |
typedef VectorMap<_Graph, _Item, signed int> Map;
|
klao@946
|
68 |
};
|
deba@822
|
69 |
|
deba@1267
|
70 |
template <typename _Graph, typename _Item>
|
deba@1267
|
71 |
struct DefaultMapSelector<_Graph, _Item, unsigned int> {
|
deba@980
|
72 |
typedef VectorMap<_Graph, _Item, unsigned int> Map;
|
klao@946
|
73 |
};
|
deba@822
|
74 |
|
deba@822
|
75 |
|
klao@946
|
76 |
// short
|
deba@1267
|
77 |
template <typename _Graph, typename _Item>
|
deba@1267
|
78 |
struct DefaultMapSelector<_Graph, _Item, signed short> {
|
deba@980
|
79 |
typedef VectorMap<_Graph, _Item, signed short> Map;
|
klao@946
|
80 |
};
|
deba@822
|
81 |
|
deba@1267
|
82 |
template <typename _Graph, typename _Item>
|
deba@1267
|
83 |
struct DefaultMapSelector<_Graph, _Item, unsigned short> {
|
deba@980
|
84 |
typedef VectorMap<_Graph, _Item, unsigned short> Map;
|
klao@946
|
85 |
};
|
klao@946
|
86 |
|
klao@946
|
87 |
|
klao@946
|
88 |
// long
|
deba@1267
|
89 |
template <typename _Graph, typename _Item>
|
deba@1267
|
90 |
struct DefaultMapSelector<_Graph, _Item, signed long> {
|
deba@980
|
91 |
typedef VectorMap<_Graph, _Item, signed long> Map;
|
klao@946
|
92 |
};
|
klao@946
|
93 |
|
deba@1267
|
94 |
template <typename _Graph, typename _Item>
|
deba@1267
|
95 |
struct DefaultMapSelector<_Graph, _Item, unsigned long> {
|
deba@980
|
96 |
typedef VectorMap<_Graph, _Item, unsigned long> Map;
|
klao@946
|
97 |
};
|
klao@946
|
98 |
|
deba@1965
|
99 |
|
deba@2164
|
100 |
#if defined __GNUC__ && !defined __STRICT_ANSI__
|
deba@1965
|
101 |
|
deba@1965
|
102 |
// long long
|
deba@1965
|
103 |
template <typename _Graph, typename _Item>
|
deba@1965
|
104 |
struct DefaultMapSelector<_Graph, _Item, signed long long> {
|
deba@1965
|
105 |
typedef VectorMap<_Graph, _Item, signed long long> Map;
|
deba@1965
|
106 |
};
|
deba@1965
|
107 |
|
deba@1965
|
108 |
template <typename _Graph, typename _Item>
|
deba@1965
|
109 |
struct DefaultMapSelector<_Graph, _Item, unsigned long long> {
|
deba@1965
|
110 |
typedef VectorMap<_Graph, _Item, unsigned long long> Map;
|
deba@1965
|
111 |
};
|
deba@1965
|
112 |
|
deba@1965
|
113 |
#endif
|
klao@946
|
114 |
|
klao@946
|
115 |
|
klao@946
|
116 |
// float
|
deba@1267
|
117 |
template <typename _Graph, typename _Item>
|
deba@1267
|
118 |
struct DefaultMapSelector<_Graph, _Item, float> {
|
deba@980
|
119 |
typedef VectorMap<_Graph, _Item, float> Map;
|
klao@946
|
120 |
};
|
klao@946
|
121 |
|
klao@946
|
122 |
|
klao@946
|
123 |
// double
|
deba@1267
|
124 |
template <typename _Graph, typename _Item>
|
deba@1267
|
125 |
struct DefaultMapSelector<_Graph, _Item, double> {
|
deba@980
|
126 |
typedef VectorMap<_Graph, _Item, double> Map;
|
klao@946
|
127 |
};
|
klao@946
|
128 |
|
klao@946
|
129 |
|
klao@946
|
130 |
// long double
|
deba@1267
|
131 |
template <typename _Graph, typename _Item>
|
deba@1267
|
132 |
struct DefaultMapSelector<_Graph, _Item, long double> {
|
deba@980
|
133 |
typedef VectorMap<_Graph, _Item, long double> Map;
|
klao@946
|
134 |
};
|
klao@946
|
135 |
|
klao@946
|
136 |
|
klao@946
|
137 |
// pointer
|
deba@1267
|
138 |
template <typename _Graph, typename _Item, typename _Ptr>
|
deba@1267
|
139 |
struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
|
deba@980
|
140 |
typedef VectorMap<_Graph, _Item, _Ptr*> Map;
|
klao@946
|
141 |
};
|
klao@946
|
142 |
|
deba@2202
|
143 |
#else
|
deba@2202
|
144 |
|
deba@2202
|
145 |
template <typename _Graph, typename _Item, typename _Value>
|
deba@2202
|
146 |
struct DefaultMapSelector {
|
deba@2202
|
147 |
typedef DebugMap<_Graph, _Item, _Value> Map;
|
deba@2202
|
148 |
};
|
deba@2202
|
149 |
|
deba@2202
|
150 |
#endif
|
deba@2202
|
151 |
|
deba@1669
|
152 |
/// \e
|
deba@1999
|
153 |
template <typename _Graph, typename _Item, typename _Value>
|
deba@1267
|
154 |
class DefaultMap
|
deba@1267
|
155 |
: public DefaultMapSelector<_Graph, _Item, _Value>::Map {
|
klao@946
|
156 |
public:
|
deba@1267
|
157 |
typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
|
deba@1267
|
158 |
typedef DefaultMap<_Graph, _Item, _Value> Map;
|
klao@946
|
159 |
|
klao@946
|
160 |
typedef typename Parent::Graph Graph;
|
alpar@987
|
161 |
typedef typename Parent::Value Value;
|
klao@946
|
162 |
|
klao@2046
|
163 |
explicit DefaultMap(const Graph& graph) : Parent(graph) {}
|
deba@1999
|
164 |
DefaultMap(const Graph& graph, const Value& value)
|
deba@1999
|
165 |
: Parent(graph, value) {}
|
deba@1669
|
166 |
|
deba@2031
|
167 |
DefaultMap& operator=(const DefaultMap& cmap) {
|
deba@2031
|
168 |
return operator=<DefaultMap>(cmap);
|
deba@2031
|
169 |
}
|
deba@2031
|
170 |
|
deba@2031
|
171 |
template <typename CMap>
|
deba@2031
|
172 |
DefaultMap& operator=(const CMap& cmap) {
|
deba@2031
|
173 |
Parent::operator=(cmap);
|
deba@2031
|
174 |
return *this;
|
deba@2031
|
175 |
}
|
deba@2031
|
176 |
|
klao@946
|
177 |
};
|
klao@946
|
178 |
|
deba@822
|
179 |
}
|
deba@822
|
180 |
|
deba@822
|
181 |
#endif
|