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