1 /* -*- C++ -*- |
1 /* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 * |
2 * |
3 * This file is a part of LEMON, a generic C++ optimization library |
3 * This file is a part of LEMON, a generic C++ optimization library. |
4 * |
4 * |
5 * Copyright (C) 2003-2008 |
5 * Copyright (C) 2003-2008 |
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 * (Egervary Research Group on Combinatorial Optimization, EGRES). |
7 * (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 * |
8 * |
45 typedef K Key; |
45 typedef K Key; |
46 /// The value type of the map. (The type of objects associated with the keys). |
46 /// The value type of the map. (The type of objects associated with the keys). |
47 typedef T Value; |
47 typedef T Value; |
48 |
48 |
49 /// Returns the value associated with the given key. |
49 /// Returns the value associated with the given key. |
50 Value operator[](const Key &) const { |
50 Value operator[](const Key &) const { |
51 return *static_cast<Value *>(0); |
51 return *static_cast<Value *>(0); |
52 } |
52 } |
53 |
53 |
54 template<typename _ReadMap> |
54 template<typename _ReadMap> |
55 struct Constraints { |
55 struct Constraints { |
56 void constraints() { |
56 void constraints() { |
57 Value val = m[key]; |
57 Value val = m[key]; |
58 val = m[key]; |
58 val = m[key]; |
59 typename _ReadMap::Value own_val = m[own_key]; |
59 typename _ReadMap::Value own_val = m[own_key]; |
60 own_val = m[own_key]; |
60 own_val = m[own_key]; |
61 |
61 |
62 ignore_unused_variable_warning(key); |
62 ignore_unused_variable_warning(key); |
63 ignore_unused_variable_warning(val); |
63 ignore_unused_variable_warning(val); |
64 ignore_unused_variable_warning(own_key); |
64 ignore_unused_variable_warning(own_key); |
65 ignore_unused_variable_warning(own_val); |
65 ignore_unused_variable_warning(own_val); |
66 } |
66 } |
67 const Key& key; |
67 const Key& key; |
68 const typename _ReadMap::Key& own_key; |
68 const typename _ReadMap::Key& own_key; |
69 const _ReadMap& m; |
69 const _ReadMap& m; |
70 }; |
70 }; |
71 |
71 |
72 }; |
72 }; |
73 |
73 |
74 |
74 |
91 /// Default constructor. |
91 /// Default constructor. |
92 WriteMap() {} |
92 WriteMap() {} |
93 |
93 |
94 template <typename _WriteMap> |
94 template <typename _WriteMap> |
95 struct Constraints { |
95 struct Constraints { |
96 void constraints() { |
96 void constraints() { |
97 m.set(key, val); |
97 m.set(key, val); |
98 m.set(own_key, own_val); |
98 m.set(own_key, own_val); |
99 |
99 |
100 ignore_unused_variable_warning(key); |
100 ignore_unused_variable_warning(key); |
101 ignore_unused_variable_warning(val); |
101 ignore_unused_variable_warning(val); |
102 ignore_unused_variable_warning(own_key); |
102 ignore_unused_variable_warning(own_key); |
103 ignore_unused_variable_warning(own_val); |
103 ignore_unused_variable_warning(own_val); |
104 } |
104 } |
105 const Key& key; |
105 const Key& key; |
106 const Value& val; |
106 const Value& val; |
107 const typename _WriteMap::Key& own_key; |
107 const typename _WriteMap::Key& own_key; |
108 const typename _WriteMap::Value& own_val; |
108 const typename _WriteMap::Value& own_val; |
109 _WriteMap& m; |
109 _WriteMap& m; |
110 }; |
110 }; |
111 }; |
111 }; |
112 |
112 |
113 /// Read/writable map concept |
113 /// Read/writable map concept |
114 |
114 |
115 /// Read/writable map concept. |
115 /// Read/writable map concept. |
116 /// |
116 /// |
117 template<typename K, typename T> |
117 template<typename K, typename T> |
118 class ReadWriteMap : public ReadMap<K,T>, |
118 class ReadWriteMap : public ReadMap<K,T>, |
119 public WriteMap<K,T> |
119 public WriteMap<K,T> |
120 { |
120 { |
121 public: |
121 public: |
122 /// The key type of the map. |
122 /// The key type of the map. |
123 typedef K Key; |
123 typedef K Key; |
124 /// The value type of the map. (The type of objects associated with the keys). |
124 /// The value type of the map. (The type of objects associated with the keys). |
125 typedef T Value; |
125 typedef T Value; |
126 |
126 |
127 /// Returns the value associated with the given key. |
127 /// Returns the value associated with the given key. |
128 Value operator[](const Key &) const { |
128 Value operator[](const Key &) const { |
129 return *static_cast<Value *>(0); |
129 return *static_cast<Value *>(0); |
130 } |
130 } |
131 |
131 |
132 /// Sets the value associated with the given key. |
132 /// Sets the value associated with the given key. |
133 void set(const Key &, const Value &) {} |
133 void set(const Key &, const Value &) {} |
134 |
134 |
135 template<typename _ReadWriteMap> |
135 template<typename _ReadWriteMap> |
136 struct Constraints { |
136 struct Constraints { |
137 void constraints() { |
137 void constraints() { |
138 checkConcept<ReadMap<K, T>, _ReadWriteMap >(); |
138 checkConcept<ReadMap<K, T>, _ReadWriteMap >(); |
139 checkConcept<WriteMap<K, T>, _ReadWriteMap >(); |
139 checkConcept<WriteMap<K, T>, _ReadWriteMap >(); |
140 } |
140 } |
141 }; |
141 }; |
142 }; |
142 }; |
143 |
143 |
144 |
144 |
145 /// Dereferable map concept |
145 /// Dereferable map concept |
162 typedef CR ConstReference; |
162 typedef CR ConstReference; |
163 |
163 |
164 public: |
164 public: |
165 |
165 |
166 /// Returns a reference to the value associated with the given key. |
166 /// Returns a reference to the value associated with the given key. |
167 Reference operator[](const Key &) { |
167 Reference operator[](const Key &) { |
168 return *static_cast<Value *>(0); |
168 return *static_cast<Value *>(0); |
169 } |
169 } |
170 |
170 |
171 /// Returns a const reference to the value associated with the given key. |
171 /// Returns a const reference to the value associated with the given key. |
172 ConstReference operator[](const Key &) const { |
172 ConstReference operator[](const Key &) const { |
176 /// Sets the value associated with the given key. |
176 /// Sets the value associated with the given key. |
177 void set(const Key &k,const Value &t) { operator[](k)=t; } |
177 void set(const Key &k,const Value &t) { operator[](k)=t; } |
178 |
178 |
179 template<typename _ReferenceMap> |
179 template<typename _ReferenceMap> |
180 struct Constraints { |
180 struct Constraints { |
181 void constraints() { |
181 void constraints() { |
182 checkConcept<ReadWriteMap<K, T>, _ReferenceMap >(); |
182 checkConcept<ReadWriteMap<K, T>, _ReferenceMap >(); |
183 ref = m[key]; |
183 ref = m[key]; |
184 m[key] = val; |
184 m[key] = val; |
185 m[key] = ref; |
185 m[key] = ref; |
186 m[key] = cref; |
186 m[key] = cref; |
187 own_ref = m[own_key]; |
187 own_ref = m[own_key]; |
188 m[own_key] = own_val; |
188 m[own_key] = own_val; |
189 m[own_key] = own_ref; |
189 m[own_key] = own_ref; |
190 m[own_key] = own_cref; |
190 m[own_key] = own_cref; |
191 m[key] = m[own_key]; |
191 m[key] = m[own_key]; |
192 m[own_key] = m[key]; |
192 m[own_key] = m[key]; |
193 } |
193 } |
194 const Key& key; |
194 const Key& key; |
195 Value& val; |
195 Value& val; |
196 Reference ref; |
196 Reference ref; |
197 ConstReference cref; |
197 ConstReference cref; |
198 const typename _ReferenceMap::Key& own_key; |
198 const typename _ReferenceMap::Key& own_key; |
199 typename _ReferenceMap::Value& own_val; |
199 typename _ReferenceMap::Value& own_val; |
200 typename _ReferenceMap::Reference own_ref; |
200 typename _ReferenceMap::Reference own_ref; |
201 typename _ReferenceMap::ConstReference own_cref; |
201 typename _ReferenceMap::ConstReference own_cref; |
202 _ReferenceMap& m; |
202 _ReferenceMap& m; |
203 }; |
203 }; |
204 }; |
204 }; |
205 |
205 |
206 // @} |
206 // @} |
207 |
207 |