alpar@2260
|
1 |
/* -*- C++ -*-
|
alpar@2260
|
2 |
*
|
alpar@2260
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
alpar@2260
|
4 |
*
|
alpar@2553
|
5 |
* Copyright (C) 2003-2008
|
alpar@2260
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@2260
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@2260
|
8 |
*
|
alpar@2260
|
9 |
* Permission to use, modify and distribute this software is granted
|
alpar@2260
|
10 |
* provided that this copyright notice appears in all copies. For
|
alpar@2260
|
11 |
* precise terms see the accompanying LICENSE file.
|
alpar@2260
|
12 |
*
|
alpar@2260
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@2260
|
14 |
* express or implied, and with no claim as to its suitability for any
|
alpar@2260
|
15 |
* purpose.
|
alpar@2260
|
16 |
*
|
alpar@2260
|
17 |
*/
|
alpar@2260
|
18 |
|
alpar@2260
|
19 |
#ifndef LEMON_CONCEPT_MATRIX_MAPS_H
|
alpar@2260
|
20 |
#define LEMON_CONCEPT_MATRIX_MAPS_H
|
alpar@2260
|
21 |
|
alpar@2260
|
22 |
#include <lemon/bits/utility.h>
|
alpar@2260
|
23 |
#include <lemon/concept_check.h>
|
alpar@2260
|
24 |
|
alpar@2260
|
25 |
///\ingroup concept
|
alpar@2260
|
26 |
///\file
|
alpar@2260
|
27 |
///\brief MatrixMap concepts checking classes for testing and documenting.
|
alpar@2260
|
28 |
|
alpar@2260
|
29 |
namespace lemon {
|
alpar@2260
|
30 |
|
alpar@2260
|
31 |
namespace concepts {
|
alpar@2260
|
32 |
|
alpar@2260
|
33 |
/// \addtogroup concept
|
alpar@2260
|
34 |
/// @{
|
alpar@2260
|
35 |
|
alpar@2260
|
36 |
/// Readable matrix map concept
|
alpar@2260
|
37 |
template <typename K1, typename K2, typename V>
|
alpar@2260
|
38 |
class ReadMatrixMap
|
alpar@2260
|
39 |
{
|
alpar@2260
|
40 |
public:
|
alpar@2260
|
41 |
/// Map's first key type.
|
alpar@2260
|
42 |
typedef K1 FirstKey;
|
alpar@2260
|
43 |
/// Map's second key type.
|
alpar@2260
|
44 |
typedef K2 SecondKey;
|
alpar@2260
|
45 |
/// \brief Map's value type.
|
alpar@2260
|
46 |
/// (The type of objects associated with the pairs of keys).
|
alpar@2260
|
47 |
typedef V Value;
|
alpar@2260
|
48 |
|
alpar@2260
|
49 |
// \bug Value don't need to be default constructible.
|
alpar@2260
|
50 |
/// Returns the value associated with a key.
|
alpar@2260
|
51 |
Value operator()(const FirstKey&, const SecondKey&) const {
|
alpar@2260
|
52 |
return Value();
|
alpar@2260
|
53 |
}
|
alpar@2260
|
54 |
|
alpar@2260
|
55 |
template <typename _ReadMatrixMap>
|
alpar@2260
|
56 |
struct Constraints {
|
alpar@2260
|
57 |
|
alpar@2260
|
58 |
void constraints() {
|
alpar@2260
|
59 |
Value val = m(first_key, second_key);
|
alpar@2260
|
60 |
val = m(first_key, second_key);
|
alpar@2260
|
61 |
typename _ReadMatrixMap::Value own_val =
|
alpar@2260
|
62 |
m(own_first_key, own_second_key);
|
alpar@2260
|
63 |
own_val = m(own_first_key, own_second_key);
|
alpar@2260
|
64 |
ignore_unused_variable_warning(val);
|
alpar@2260
|
65 |
ignore_unused_variable_warning(own_val);
|
alpar@2260
|
66 |
}
|
alpar@2260
|
67 |
|
alpar@2260
|
68 |
FirstKey& first_key;
|
alpar@2260
|
69 |
SecondKey& second_key;
|
alpar@2260
|
70 |
typename _ReadMatrixMap::FirstKey& own_first_key;
|
alpar@2260
|
71 |
typename _ReadMatrixMap::SecondKey& own_second_key;
|
alpar@2260
|
72 |
_ReadMatrixMap& m;
|
alpar@2260
|
73 |
};
|
alpar@2260
|
74 |
|
alpar@2260
|
75 |
};
|
alpar@2260
|
76 |
|
alpar@2260
|
77 |
|
alpar@2260
|
78 |
/// Writable map concept
|
alpar@2260
|
79 |
template <typename K1, typename K2, typename V>
|
alpar@2260
|
80 |
class WriteMatrixMap {
|
alpar@2260
|
81 |
public:
|
alpar@2260
|
82 |
/// Map's first key type.
|
alpar@2260
|
83 |
typedef K1 FirstKey;
|
alpar@2260
|
84 |
/// Map's second key type.
|
alpar@2260
|
85 |
typedef K2 SecondKey;
|
alpar@2260
|
86 |
/// \brief Map's value type.
|
alpar@2260
|
87 |
/// (The type of objects associated with the pairs of keys).
|
alpar@2260
|
88 |
typedef V Value;
|
alpar@2260
|
89 |
|
alpar@2260
|
90 |
/// Sets the value associated with the pair of keys.
|
alpar@2260
|
91 |
void set(const FirstKey&, const SecondKey& ,const Value&) {}
|
alpar@2260
|
92 |
|
alpar@2260
|
93 |
template <typename _WriteMatrixMap>
|
alpar@2260
|
94 |
struct Constraints {
|
alpar@2260
|
95 |
void constraints() {
|
alpar@2260
|
96 |
// No constraints for constructor.
|
alpar@2260
|
97 |
m.set(first_key, second_key, val);
|
alpar@2260
|
98 |
m.set(own_first_key, own_second_key, own_val);
|
alpar@2260
|
99 |
}
|
alpar@2260
|
100 |
|
alpar@2260
|
101 |
Value& val;
|
alpar@2260
|
102 |
typename _WriteMatrixMap::Value own_val;
|
alpar@2260
|
103 |
FirstKey& first_key;
|
alpar@2260
|
104 |
SecondKey& second_key;
|
alpar@2260
|
105 |
typename _WriteMatrixMap::FirstKey& own_first_key;
|
alpar@2260
|
106 |
typename _WriteMatrixMap::SecondKey& own_second_key;
|
alpar@2260
|
107 |
_WriteMatrixMap& m;
|
alpar@2260
|
108 |
|
alpar@2260
|
109 |
};
|
alpar@2260
|
110 |
};
|
alpar@2260
|
111 |
|
alpar@2260
|
112 |
///Read/Writable map concept
|
alpar@2260
|
113 |
template<typename K1, typename K2, typename V>
|
alpar@2260
|
114 |
class ReadWriteMatrixMap
|
alpar@2260
|
115 |
: public ReadMatrixMap<K1, K2, V>, public WriteMatrixMap<K1, K2, V> {
|
alpar@2260
|
116 |
public:
|
alpar@2260
|
117 |
/// Map's first key type.
|
alpar@2260
|
118 |
typedef K1 FirstKey;
|
alpar@2260
|
119 |
/// Map's second key type.
|
alpar@2260
|
120 |
typedef K2 SecondKey;
|
alpar@2260
|
121 |
/// \brief Map's value type.
|
alpar@2260
|
122 |
/// (The type of objects associated with the pairs of keys).
|
alpar@2260
|
123 |
typedef V Value;
|
alpar@2260
|
124 |
|
alpar@2260
|
125 |
/// Returns the value associated with a pair of keys.
|
alpar@2260
|
126 |
Value operator()(const FirstKey&, const SecondKey&) const {
|
alpar@2260
|
127 |
return Value();
|
alpar@2260
|
128 |
}
|
alpar@2260
|
129 |
/// Sets the value associated with the pair of keys.
|
alpar@2260
|
130 |
void set(const FirstKey&, const SecondKey& ,const Value&) {}
|
alpar@2260
|
131 |
|
alpar@2260
|
132 |
template<typename _ReadWriteMatrixMap>
|
alpar@2260
|
133 |
struct Constraints {
|
alpar@2260
|
134 |
void constraints() {
|
alpar@2260
|
135 |
checkConcept<ReadMatrixMap<K1, K2, V>, _ReadWriteMatrixMap >();
|
alpar@2260
|
136 |
checkConcept<WriteMatrixMap<K1, K2, V>, _ReadWriteMatrixMap >();
|
alpar@2260
|
137 |
}
|
alpar@2260
|
138 |
};
|
alpar@2260
|
139 |
};
|
alpar@2260
|
140 |
|
alpar@2260
|
141 |
|
alpar@2260
|
142 |
///Dereferable matrix map concept
|
alpar@2260
|
143 |
template<typename K1, typename K2, typename V, typename R, typename CR>
|
alpar@2260
|
144 |
class ReferenceMatrixMap : public ReadWriteMatrixMap<K1, K2, V>
|
alpar@2260
|
145 |
{
|
alpar@2260
|
146 |
public:
|
alpar@2260
|
147 |
/// Tag for reference maps.
|
alpar@2260
|
148 |
typedef True ReferenceMapTag;
|
alpar@2260
|
149 |
/// Map's first key type.
|
alpar@2260
|
150 |
typedef K1 FirstKey;
|
alpar@2260
|
151 |
/// Map's second key type.
|
alpar@2260
|
152 |
typedef K1 SecondKey;
|
alpar@2260
|
153 |
/// Map's value type. (The type of objects associated with the keys).
|
alpar@2260
|
154 |
typedef V Value;
|
alpar@2260
|
155 |
/// Map's reference type.
|
alpar@2260
|
156 |
typedef R Reference;
|
alpar@2260
|
157 |
/// Map's const reference type.
|
alpar@2260
|
158 |
typedef CR ConstReference;
|
alpar@2260
|
159 |
|
alpar@2260
|
160 |
protected:
|
alpar@2260
|
161 |
Value tmp;
|
alpar@2260
|
162 |
public:
|
alpar@2260
|
163 |
|
alpar@2260
|
164 |
///Returns a reference to the value associated to a pair of keys.
|
alpar@2260
|
165 |
Reference operator()(const FirstKey&, const SecondKey&) {
|
alpar@2260
|
166 |
return tmp;
|
alpar@2260
|
167 |
}
|
alpar@2260
|
168 |
///Returns a const reference to the value associated to a pair of keys.
|
alpar@2260
|
169 |
ConstReference operator()(const FirstKey&, const SecondKey&) const {
|
alpar@2260
|
170 |
return tmp;
|
alpar@2260
|
171 |
}
|
alpar@2260
|
172 |
/// Sets the value associated with the pair of keys.
|
alpar@2260
|
173 |
void set(const FirstKey&, const SecondKey& ,const Value&) {}
|
alpar@2260
|
174 |
|
alpar@2260
|
175 |
// \todo rethink this concept
|
alpar@2260
|
176 |
template<typename _ReferenceMatrixMap>
|
alpar@2260
|
177 |
struct ReferenceMapConcept {
|
alpar@2260
|
178 |
|
alpar@2260
|
179 |
void constraints() {
|
alpar@2260
|
180 |
checkConcept<ReadWriteMatrixMap, _ReferenceMatrixMap >();
|
alpar@2260
|
181 |
m(first_key, second_key) = val;
|
alpar@2260
|
182 |
val = m(first_key, second_key);
|
alpar@2260
|
183 |
m(first_key, second_key) = ref;
|
alpar@2260
|
184 |
ref = m(first_key, second_key);
|
alpar@2260
|
185 |
m(own_first_key, own_second_key) = own_val;
|
alpar@2260
|
186 |
own_val = m(own_first_key, own_second_key);
|
alpar@2260
|
187 |
m(own_first_key, own_second_key) = own_ref;
|
alpar@2260
|
188 |
own_ref = m(own_first_key, own_second_key);
|
alpar@2260
|
189 |
}
|
alpar@2260
|
190 |
|
alpar@2260
|
191 |
typename _ReferenceMatrixMap::Key& own_first_key;
|
alpar@2260
|
192 |
typename _ReferenceMatrixMap::Key& own_second_key;
|
alpar@2260
|
193 |
typename _ReferenceMatrixMap::Value& own_val;
|
alpar@2260
|
194 |
typename _ReferenceMatrixMap::Reference& own_ref;
|
alpar@2260
|
195 |
FirstKey& first_key;
|
alpar@2260
|
196 |
SecondKey& second_key;
|
alpar@2260
|
197 |
Value& val;
|
alpar@2260
|
198 |
Reference& ref;
|
alpar@2260
|
199 |
_ReferenceMatrixMap& m;
|
alpar@2260
|
200 |
};
|
alpar@2260
|
201 |
};
|
alpar@2260
|
202 |
|
alpar@2260
|
203 |
// @}
|
alpar@2260
|
204 |
|
alpar@2260
|
205 |
} //namespace concepts
|
alpar@2260
|
206 |
} //namespace lemon
|
alpar@2260
|
207 |
#endif // LEMON_CONCEPT_MATRIX_MAPS_H
|