Updated because of the recent changes in simann.h.
2 * src/lemon/skeletons/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_MAPSKELETON_H
18 #define LEMON_MAPSKELETON_H
20 #include <lemon/concept_check.h>
24 ///\brief Map concepts checking classes for testing and documenting.
30 /// \addtogroup skeletons
33 /// Readable map concept
34 template<typename K, typename T>
40 /// Map's value type. (The type of objects associated with the keys).
43 /// Returns the value associated with a key.
44 ValueType operator[](const KeyType &k) const {return ValueType();}
46 ///Default constructor
51 /// Writable map concept
52 template<typename K, typename T>
58 /// Map's value type. (The type of objects associated with the keys).
61 /// Sets the value associated with a key.
62 void set(const KeyType &k,const ValueType &t) {}
64 ///Default constructor
68 ///Read/Writable map concept
69 template<typename K, typename T>
70 class ReadWriteMap : public ReadMap<K,T>,
76 /// Map's value type. (The type of objects associated with the keys).
79 /// Returns the value associated with a key.
80 ValueType operator[](const KeyType &k) const {return ValueType();}
81 /// Sets the value associated with a key.
82 void set(const KeyType &k,const ValueType &t) {}
84 ///Default constructor
89 ///Dereferable map concept
90 template<typename K, typename T>
91 class ReferenceMap : public ReadWriteMap<K,T>
96 /// Map's value type. (The type of objects associated with the keys).
102 typedef ValueType& ReferenceType;
103 /// Map's const reference type.
104 typedef const ValueType& ConstReferenceType;
106 ///Returns a reference to the value associated to a key.
107 ReferenceType operator[](const KeyType &i) { return tmp; }
108 ///Returns a const reference to the value associated to a key.
109 ConstReferenceType operator[](const KeyType &i) const
111 /// Sets the value associated with a key.
112 void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
114 ///Default constructor
119 template<typename Item, typename T, typename Graph>
120 class GraphMap : public ReadWriteMap<Item, T> {
121 // I really, really don't like the idea that every graph should have
122 // reference maps! --klao
125 // We state explicitly that graph maps have no default constructor?
129 explicit GraphMap(Graph const&) {}
130 // value for initializing
131 GraphMap(Graph const&, T) {}
133 // this probably should be required:
134 GraphMap(GraphMap const&) {}
135 GraphMap& operator=(GraphMap const&) { return *this; }
137 // but this is a absolute no-op! We should provide a more generic
138 // graph-map-copy operation.
140 // template<typename TT>
141 // GraphMap(GraphMap<TT> const&);
143 // template<typename TT>
144 // GraphMap& operator=(const GraphMap<TT>&);
148 /**************** Concept-checking classes ****************/
150 template<typename ReadMap>
151 struct ReadMapConcept {
152 typedef typename ReadMap::KeyType KeyType;
153 typedef typename ReadMap::ValueType ValueType;
156 // No constraints for constructor.
158 // What are the requirement for the ValueType?
159 // CopyConstructible? Assignable? None of these?
164 ignore_unused_variable_warning(v);
171 template<typename WriteMap>
172 struct WriteMapConcept {
173 typedef typename WriteMap::KeyType KeyType;
174 typedef typename WriteMap::ValueType ValueType;
177 // No constraints for constructor.
187 template<typename ReadWriteMap>
188 struct ReadWriteMapConcept {
190 function_requires< ReadMapConcept<ReadWriteMap> >();
191 function_requires< WriteMapConcept<ReadWriteMap> >();
195 template<typename ReferenceMap>
196 struct ReferenceMapConcept {
197 typedef typename ReferenceMap::KeyType KeyType;
198 typedef typename ReferenceMap::ValueType ValueType;
199 typedef typename ReferenceMap::ReferenceType ReferenceType;
202 typedef typename ReferenceMap::ConstReferenceType ConstReferenceType;
205 function_requires< ReadWriteMapConcept<ReferenceMap> >();
208 // Or should we require real reference?
210 // ValueType &vv = m[k];
211 // ignore_unused_variable_warning(vv);
219 /// \todo GraphMapConceptCheck
221 template<typename GraphMap, typename Graph>
222 struct GraphMapConcept {
224 function_requires< ReadWriteMapConcept<GraphMap> >();
225 // Construction with a graph parameter
227 // Ctor with a graph and a default value parameter
229 // Copy ctor. Do we need it?
231 // Copy operator. Do we need it?
234 ignore_unused_variable_warning(a2);
238 const typename GraphMap::ValueType &t;
244 } //namespace skeleton
246 #endif // LEMON_MAPSKELETON_H