Doc improvements.
2 * src/lemon/concept/maps.h - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Combinatorial Optimization Research Group, 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/concept_check.h>
24 ///\brief Map concepts checking classes for testing and documenting.
30 /// \addtogroup concept
33 /// Readable map concept
34 template<typename K, typename T>
40 /// Map's value type. (The type of objects associated with the keys).
43 // \bug Value don't need to be default constructible.
44 /// Returns the value associated with a key.
45 Value operator[](const Key &) const {return Value();}
47 template<typename _ReadMap>
53 typename _ReadMap::Value own_val = m[own_key];
56 ignore_unused_variable_warning(val);
57 ignore_unused_variable_warning(own_val);
58 ignore_unused_variable_warning(key);
61 typename _ReadMap::Key& own_key;
68 /// Writable map concept
69 template<typename K, typename T>
75 /// Map's value type. (The type of objects associated with the keys).
78 /// Sets the value associated with a key.
79 void set(const Key &k,const Value &t) {}
81 ///Default constructor
84 template <typename _WriteMap>
87 // No constraints for constructor.
89 m.set(own_key, own_val);
90 ignore_unused_variable_warning(key);
91 ignore_unused_variable_warning(val);
92 ignore_unused_variable_warning(own_key);
93 ignore_unused_variable_warning(own_val);
97 typename _WriteMap::Value own_val;
99 typename _WriteMap::Key& own_key;
105 ///Read/Writable map concept
106 template<typename K, typename T>
107 class ReadWriteMap : public ReadMap<K,T>,
113 /// Map's value type. (The type of objects associated with the keys).
116 /// Returns the value associated with a key.
117 Value operator[](const Key &k) const {return Value();}
118 /// Sets the value associated with a key.
119 void set(const Key &k,const Value &t) {}
121 template<typename _ReadWriteMap>
124 checkConcept<ReadMap<K, T>, _ReadWriteMap >();
125 checkConcept<ReadMap<K, T>, _ReadWriteMap >();
131 ///Dereferable map concept
132 template<typename K, typename T, typename R, typename CR>
133 class ReferenceMap : public ReadWriteMap<K,T>
138 /// Map's value type. (The type of objects associated with the keys).
140 /// Map's reference type.
142 /// Map's const reference type.
143 typedef CR ConstReference;
149 ///Returns a reference to the value associated to a key.
150 Reference operator[](const Key &i) { return tmp; }
151 ///Returns a const reference to the value associated to a key.
152 ConstReference operator[](const Key &i) const
154 /// Sets the value associated with a key.
155 void set(const Key &k,const Value &t) { operator[](k)=t; }
157 // \todo rethink this concept
158 template<typename _ReferenceMap>
159 struct ReferenceMapConcept {
162 checkConcept<ReadWriteMap, _ReferenceMap >();
167 m[own_key] = own_val;
168 own_val = m[own_key];
169 m[own_key] = own_ref;
170 own_ref = m[own_key];
173 typename _ReferenceMap::Key& own_key;
174 typename _ReferenceMap::Value& own_val;
175 typename _ReferenceMap::Reference& own_ref;
185 } //namespace concept
187 #endif // LEMON_CONCEPT_MAPS_H