Doc improvements in maps.h.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2007
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
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.
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
19 #ifndef LEMON_CONCEPT_MAPS_H
20 #define LEMON_CONCEPT_MAPS_H
22 #include <lemon/bits/utility.h>
23 #include <lemon/concept_check.h>
27 ///\brief Map concepts checking classes for testing and documenting.
33 /// \addtogroup concept
36 /// Readable map concept
37 template<typename K, typename T>
43 /// Map's value type. (The type of objects associated with the keys).
46 /// Returns the value associated with a key.
48 /// \bug Value should n't need to be default constructible.
50 Value operator[](const Key &) const {return Value();}
52 template<typename _ReadMap>
58 typename _ReadMap::Value own_val = m[own_key];
61 ignore_unused_variable_warning(val);
62 ignore_unused_variable_warning(own_val);
63 ignore_unused_variable_warning(key);
66 typename _ReadMap::Key& own_key;
73 /// Writable map concept
74 template<typename K, typename T>
80 /// Map's value type. (The type of objects associated with the keys).
83 /// Sets the value associated with a key.
84 void set(const Key &,const Value &) {}
86 ///Default constructor
89 template <typename _WriteMap>
92 // No constraints for constructor.
94 m.set(own_key, own_val);
95 ignore_unused_variable_warning(key);
96 ignore_unused_variable_warning(val);
97 ignore_unused_variable_warning(own_key);
98 ignore_unused_variable_warning(own_val);
102 typename _WriteMap::Value own_val;
104 typename _WriteMap::Key& own_key;
110 ///Read/Writable map concept
111 template<typename K, typename T>
112 class ReadWriteMap : public ReadMap<K,T>,
118 /// Map's value type. (The type of objects associated with the keys).
121 /// Returns the value associated with a key.
122 Value operator[](const Key &) const {return Value();}
123 /// Sets the value associated with a key.
124 void set(const Key & ,const Value &) {}
126 template<typename _ReadWriteMap>
129 checkConcept<ReadMap<K, T>, _ReadWriteMap >();
130 checkConcept<WriteMap<K, T>, _ReadWriteMap >();
136 ///Dereferable map concept
137 template<typename K, typename T, typename R, typename CR>
138 class ReferenceMap : public ReadWriteMap<K,T>
141 /// Tag for reference maps.
142 typedef True ReferenceMapTag;
145 /// Map's value type. (The type of objects associated with the keys).
147 /// Map's reference type.
149 /// Map's const reference type.
150 typedef CR ConstReference;
156 ///Returns a reference to the value associated to a key.
157 Reference operator[](const Key &) { return tmp; }
158 ///Returns a const reference to the value associated to a key.
159 ConstReference operator[](const Key &) const
161 /// Sets the value associated with a key.
162 void set(const Key &k,const Value &t) { operator[](k)=t; }
164 // \todo rethink this concept
165 template<typename _ReferenceMap>
166 struct ReferenceMapConcept {
169 checkConcept<ReadWriteMap, _ReferenceMap >();
174 m[own_key] = own_val;
175 own_val = m[own_key];
176 m[own_key] = own_ref;
177 own_ref = m[own_key];
180 typename _ReferenceMap::Key& own_key;
181 typename _ReferenceMap::Value& own_val;
182 typename _ReferenceMap::Reference& own_ref;
192 } //namespace concepts
194 #endif // LEMON_CONCEPT_MAPS_H