Missing header file added.
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 // \bug Value don't need to be default constructible.
47 /// Returns the value associated with a key.
48 Value operator[](const Key &) const {return Value();}
50 template<typename _ReadMap>
56 typename _ReadMap::Value own_val = m[own_key];
59 ignore_unused_variable_warning(val);
60 ignore_unused_variable_warning(own_val);
61 ignore_unused_variable_warning(key);
64 typename _ReadMap::Key& own_key;
71 /// Writable map concept
72 template<typename K, typename T>
78 /// Map's value type. (The type of objects associated with the keys).
81 /// Sets the value associated with a key.
82 void set(const Key &,const Value &) {}
84 ///Default constructor
87 template <typename _WriteMap>
90 // No constraints for constructor.
92 m.set(own_key, own_val);
93 ignore_unused_variable_warning(key);
94 ignore_unused_variable_warning(val);
95 ignore_unused_variable_warning(own_key);
96 ignore_unused_variable_warning(own_val);
100 typename _WriteMap::Value own_val;
102 typename _WriteMap::Key& own_key;
108 ///Read/Writable map concept
109 template<typename K, typename T>
110 class ReadWriteMap : public ReadMap<K,T>,
116 /// Map's value type. (The type of objects associated with the keys).
119 /// Returns the value associated with a key.
120 Value operator[](const Key &) const {return Value();}
121 /// Sets the value associated with a key.
122 void set(const Key & ,const Value &) {}
124 template<typename _ReadWriteMap>
127 checkConcept<ReadMap<K, T>, _ReadWriteMap >();
128 checkConcept<WriteMap<K, T>, _ReadWriteMap >();
134 ///Dereferable map concept
135 template<typename K, typename T, typename R, typename CR>
136 class ReferenceMap : public ReadWriteMap<K,T>
139 /// Tag for reference maps.
140 typedef True ReferenceMapTag;
143 /// Map's value type. (The type of objects associated with the keys).
145 /// Map's reference type.
147 /// Map's const reference type.
148 typedef CR ConstReference;
154 ///Returns a reference to the value associated to a key.
155 Reference operator[](const Key &) { return tmp; }
156 ///Returns a const reference to the value associated to a key.
157 ConstReference operator[](const Key &) const
159 /// Sets the value associated with a key.
160 void set(const Key &k,const Value &t) { operator[](k)=t; }
162 // \todo rethink this concept
163 template<typename _ReferenceMap>
164 struct ReferenceMapConcept {
167 checkConcept<ReadWriteMap, _ReferenceMap >();
172 m[own_key] = own_val;
173 own_val = m[own_key];
174 m[own_key] = own_ref;
175 own_ref = m[own_key];
178 typename _ReferenceMap::Key& own_key;
179 typename _ReferenceMap::Value& own_val;
180 typename _ReferenceMap::Reference& own_ref;
190 } //namespace concepts
192 #endif // LEMON_CONCEPT_MAPS_H