Improved docs.
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_MATRIX_MAPS_H
20 #define LEMON_CONCEPT_MATRIX_MAPS_H
22 #include <lemon/bits/utility.h>
23 #include <lemon/concept_check.h>
27 ///\brief MatrixMap concepts checking classes for testing and documenting.
33 /// \addtogroup concept
36 /// Readable matrix map concept
37 template <typename K1, typename K2, typename V>
41 /// Map's first key type.
43 /// Map's second key type.
45 /// \brief Map's value type.
46 /// (The type of objects associated with the pairs of keys).
49 // \bug Value don't need to be default constructible.
50 /// Returns the value associated with a key.
51 Value operator()(const FirstKey&, const SecondKey&) const {
55 template <typename _ReadMatrixMap>
59 Value val = m(first_key, second_key);
60 val = m(first_key, second_key);
61 typename _ReadMatrixMap::Value own_val =
62 m(own_first_key, own_second_key);
63 own_val = m(own_first_key, own_second_key);
64 ignore_unused_variable_warning(val);
65 ignore_unused_variable_warning(own_val);
69 SecondKey& second_key;
70 typename _ReadMatrixMap::FirstKey& own_first_key;
71 typename _ReadMatrixMap::SecondKey& own_second_key;
78 /// Writable map concept
79 template <typename K1, typename K2, typename V>
80 class WriteMatrixMap {
82 /// Map's first key type.
84 /// Map's second key type.
86 /// \brief Map's value type.
87 /// (The type of objects associated with the pairs of keys).
90 /// Sets the value associated with the pair of keys.
91 void set(const FirstKey&, const SecondKey& ,const Value&) {}
93 template <typename _WriteMatrixMap>
96 // No constraints for constructor.
97 m.set(first_key, second_key, val);
98 m.set(own_first_key, own_second_key, own_val);
102 typename _WriteMatrixMap::Value own_val;
104 SecondKey& second_key;
105 typename _WriteMatrixMap::FirstKey& own_first_key;
106 typename _WriteMatrixMap::SecondKey& own_second_key;
112 ///Read/Writable map concept
113 template<typename K1, typename K2, typename V>
114 class ReadWriteMatrixMap
115 : public ReadMatrixMap<K1, K2, V>, public WriteMatrixMap<K1, K2, V> {
117 /// Map's first key type.
119 /// Map's second key type.
120 typedef K2 SecondKey;
121 /// \brief Map's value type.
122 /// (The type of objects associated with the pairs of keys).
125 /// Returns the value associated with a pair of keys.
126 Value operator()(const FirstKey&, const SecondKey&) const {
129 /// Sets the value associated with the pair of keys.
130 void set(const FirstKey&, const SecondKey& ,const Value&) {}
132 template<typename _ReadWriteMatrixMap>
135 checkConcept<ReadMatrixMap<K1, K2, V>, _ReadWriteMatrixMap >();
136 checkConcept<WriteMatrixMap<K1, K2, V>, _ReadWriteMatrixMap >();
142 ///Dereferable matrix map concept
143 template<typename K1, typename K2, typename V, typename R, typename CR>
144 class ReferenceMatrixMap : public ReadWriteMatrixMap<K1, K2, V>
147 /// Tag for reference maps.
148 typedef True ReferenceMapTag;
149 /// Map's first key type.
151 /// Map's second key type.
152 typedef K1 SecondKey;
153 /// Map's value type. (The type of objects associated with the keys).
155 /// Map's reference type.
157 /// Map's const reference type.
158 typedef CR ConstReference;
164 ///Returns a reference to the value associated to a pair of keys.
165 Reference operator()(const FirstKey&, const SecondKey&) {
168 ///Returns a const reference to the value associated to a pair of keys.
169 ConstReference operator()(const FirstKey&, const SecondKey&) const {
172 /// Sets the value associated with the pair of keys.
173 void set(const FirstKey&, const SecondKey& ,const Value&) {}
175 // \todo rethink this concept
176 template<typename _ReferenceMatrixMap>
177 struct ReferenceMapConcept {
180 checkConcept<ReadWriteMatrixMap, _ReferenceMatrixMap >();
181 m(first_key, second_key) = val;
182 val = m(first_key, second_key);
183 m(first_key, second_key) = ref;
184 ref = m(first_key, second_key);
185 m(own_first_key, own_second_key) = own_val;
186 own_val = m(own_first_key, own_second_key);
187 m(own_first_key, own_second_key) = own_ref;
188 own_ref = m(own_first_key, own_second_key);
191 typename _ReferenceMatrixMap::Key& own_first_key;
192 typename _ReferenceMatrixMap::Key& own_second_key;
193 typename _ReferenceMatrixMap::Value& own_val;
194 typename _ReferenceMatrixMap::Reference& own_ref;
196 SecondKey& second_key;
199 _ReferenceMatrixMap& m;
205 } //namespace concepts
207 #endif // LEMON_CONCEPT_MATRIX_MAPS_H