As initial value of a new map expression with ()+-/* operators can be given. These operators work on numbers, or on maps. If maps are given, then the new value for a given graph element will be calculated using the value from the given maps that belong to that graph element.
2 * lemon/concept/matrix_maps.h - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Research Group on Combinatorial Optimization, 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_MATRIX_MAPS_H
18 #define LEMON_CONCEPT_MATRIX_MAPS_H
20 #include <lemon/utility.h>
21 #include <lemon/concept_check.h>
25 ///\brief MatrixMap concepts checking classes for testing and documenting.
31 /// \addtogroup concept
34 /// Readable matrix map concept
35 template <typename K1, typename K2, typename V>
39 /// Map's first key type.
41 /// Map's second key type.
43 /// \brief Map's value type.
44 /// (The type of objects associated with the pairs of keys).
47 // \bug Value don't need to be default constructible.
48 /// Returns the value associated with a key.
49 Value operator()(const FirstKey&, const SecondKey&) const {
53 template <typename _ReadMatrixMap>
57 Value val = m(first_key, second_key);
58 val = m(first_key, second_key);
59 typename _ReadMatrixMap::Value own_val =
60 m(own_first_key, own_second_key);
61 own_val = m(own_first_key, own_second_key);
62 ignore_unused_variable_warning(val);
63 ignore_unused_variable_warning(own_val);
67 SecondKey& second_key;
68 typename _ReadMatrixMap::FirstKey& own_first_key;
69 typename _ReadMatrixMap::SecondKey& own_second_key;
76 /// Writable map concept
77 template <typename K1, typename K2, typename V>
78 class WriteMatrixMap {
80 /// Map's first key type.
82 /// Map's second key type.
84 /// \brief Map's value type.
85 /// (The type of objects associated with the pairs of keys).
88 /// Sets the value associated with the pair of keys.
89 void set(const FirstKey&, const SecondKey& ,const Value&) {}
91 template <typename _WriteMatrixMap>
94 // No constraints for constructor.
95 m.set(first_key, second_key, val);
96 m.set(own_first_key, own_second_key, own_val);
100 typename _WriteMatrixMap::Value own_val;
102 SecondKey& second_key;
103 typename _WriteMatrixMap::FirstKey& own_first_key;
104 typename _WriteMatrixMap::SecondKey& own_second_key;
110 ///Read/Writable map concept
111 template<typename K1, typename K2, typename V>
112 class ReadWriteMatrixMap
113 : public ReadMatrixMap<K1, K2, V>, public WriteMatrixMap<K1, K2, V> {
115 /// Map's first key type.
117 /// Map's second key type.
118 typedef K2 SecondKey;
119 /// \brief Map's value type.
120 /// (The type of objects associated with the pairs of keys).
123 /// Returns the value associated with a pair of keys.
124 Value operator()(const FirstKey&, const SecondKey&) const {
127 /// Sets the value associated with the pair of keys.
128 void set(const FirstKey&, const SecondKey& ,const Value&) {}
130 template<typename _ReadWriteMatrixMap>
133 checkConcept<ReadMatrixMap<K1, K2, V>, _ReadWriteMatrixMap >();
134 checkConcept<WriteMatrixMap<K1, K2, V>, _ReadWriteMatrixMap >();
140 ///Dereferable matrix map concept
141 template<typename K1, typename K2, typename V, typename R, typename CR>
142 class ReferenceMatrixMap : public ReadWriteMatrixMap<K1, K2, V>
145 /// Tag for reference maps.
146 typedef True ReferenceMapTag;
147 /// Map's first key type.
149 /// Map's second key type.
150 typedef K1 SecondKey;
151 /// Map's value type. (The type of objects associated with the keys).
153 /// Map's reference type.
155 /// Map's const reference type.
156 typedef CR ConstReference;
162 ///Returns a reference to the value associated to a pair of keys.
163 Reference operator()(const FirstKey&, const SecondKey&) {
166 ///Returns a const reference to the value associated to a pair of keys.
167 ConstReference operator()(const FirstKey&, const SecondKey&) const {
170 /// Sets the value associated with the pair of keys.
171 void set(const FirstKey&, const SecondKey& ,const Value&) {}
173 // \todo rethink this concept
174 template<typename _ReferenceMatrixMap>
175 struct ReferenceMapConcept {
178 checkConcept<ReadWriteMatrixMap, _ReferenceMatrixMap >();
179 m(first_key, second_key) = val;
180 val = m(first_key, second_key);
181 m(first_key, second_key) = ref;
182 ref = m(first_key, second_key);
183 m(own_first_key, own_second_key) = own_val;
184 own_val = m(own_first_key, own_second_key);
185 m(own_first_key, own_second_key) = own_ref;
186 own_ref = m(own_first_key, own_second_key);
189 typename _ReferenceMatrixMap::Key& own_first_key;
190 typename _ReferenceMatrixMap::Key& own_second_key;
191 typename _ReferenceMatrixMap::Value& own_val;
192 typename _ReferenceMatrixMap::Reference& own_ref;
194 SecondKey& second_key;
197 _ReferenceMatrixMap& m;
203 } //namespace concept
205 #endif // LEMON_CONCEPT_MATRIX_MAPS_H