Several bugfices.
2 * lemon/concept/maps.h - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Research Group on Combinatorial Optimization, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
17 #ifndef LEMON_CONCEPT_MAPS_H
18 #define LEMON_CONCEPT_MAPS_H
20 #include <lemon/utility.h>
21 #include <lemon/concept_check.h>
25 ///\brief Map concepts checking classes for testing and documenting.
31 /// \addtogroup concept
34 /// Readable map concept
35 template<typename K, typename T>
41 /// Map's value type. (The type of objects associated with the keys).
44 // \bug Value don't need to be default constructible.
45 /// Returns the value associated with a key.
46 Value operator[](const Key &) const {return Value();}
48 template<typename _ReadMap>
54 typename _ReadMap::Value own_val = m[own_key];
57 ignore_unused_variable_warning(val);
58 ignore_unused_variable_warning(own_val);
59 ignore_unused_variable_warning(key);
62 typename _ReadMap::Key& own_key;
69 /// Writable map concept
70 template<typename K, typename T>
76 /// Map's value type. (The type of objects associated with the keys).
79 /// Sets the value associated with a key.
80 void set(const Key &,const Value &) {}
82 ///Default constructor
85 template <typename _WriteMap>
88 // No constraints for constructor.
90 m.set(own_key, own_val);
91 ignore_unused_variable_warning(key);
92 ignore_unused_variable_warning(val);
93 ignore_unused_variable_warning(own_key);
94 ignore_unused_variable_warning(own_val);
98 typename _WriteMap::Value own_val;
100 typename _WriteMap::Key& own_key;
106 ///Read/Writable map concept
107 template<typename K, typename T>
108 class ReadWriteMap : public ReadMap<K,T>,
114 /// Map's value type. (The type of objects associated with the keys).
117 /// Returns the value associated with a key.
118 Value operator[](const Key &) const {return Value();}
119 /// Sets the value associated with a key.
120 void set(const Key & ,const Value &) {}
122 template<typename _ReadWriteMap>
125 checkConcept<ReadMap<K, T>, _ReadWriteMap >();
126 checkConcept<WriteMap<K, T>, _ReadWriteMap >();
132 ///Dereferable map concept
133 template<typename K, typename T, typename R, typename CR>
134 class ReferenceMap : public ReadWriteMap<K,T>
137 /// Tag for reference maps.
138 typedef True ReferenceMapTag;
141 /// Map's value type. (The type of objects associated with the keys).
143 /// Map's reference type.
145 /// Map's const reference type.
146 typedef CR ConstReference;
152 ///Returns a reference to the value associated to a key.
153 Reference operator[](const Key &) { return tmp; }
154 ///Returns a const reference to the value associated to a key.
155 ConstReference operator[](const Key &) const
157 /// Sets the value associated with a key.
158 void set(const Key &k,const Value &t) { operator[](k)=t; }
160 // \todo rethink this concept
161 template<typename _ReferenceMap>
162 struct ReferenceMapConcept {
165 checkConcept<ReadWriteMap, _ReferenceMap >();
170 m[own_key] = own_val;
171 own_val = m[own_key];
172 m[own_key] = own_ref;
173 own_ref = m[own_key];
176 typename _ReferenceMap::Key& own_key;
177 typename _ReferenceMap::Value& own_val;
178 typename _ReferenceMap::Reference& own_ref;
188 } //namespace concept
190 #endif // LEMON_CONCEPT_MAPS_H