1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2013
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_CONCEPTS_MAPS_H
20 #define LEMON_CONCEPTS_MAPS_H
22 #include <lemon/core.h>
23 #include <lemon/concept_check.h>
25 ///\ingroup map_concepts
27 ///\brief The concept of maps.
33 /// \addtogroup map_concepts
36 /// Readable map concept
38 /// Readable map concept.
40 template<typename K, typename T>
44 /// The key type of the map.
46 /// \brief The value type of the map.
47 /// (The type of objects associated with the keys).
50 /// Returns the value associated with the given key.
51 Value operator[](const Key &) const {
52 return *(static_cast<Value *>(0)+1);
55 template<typename _ReadMap>
60 typename _ReadMap::Value own_val = m[own_key];
63 ::lemon::ignore_unused_variable_warning(key);
64 ::lemon::ignore_unused_variable_warning(val);
65 ::lemon::ignore_unused_variable_warning(own_key);
66 ::lemon::ignore_unused_variable_warning(own_val);
69 const typename _ReadMap::Key& own_key;
77 /// Writable map concept
79 /// Writable map concept.
81 template<typename K, typename T>
85 /// The key type of the map.
87 /// \brief The value type of the map.
88 /// (The type of objects associated with the keys).
91 /// Sets the value associated with the given key.
92 void set(const Key &, const Value &) {}
94 /// Default constructor.
97 template <typename _WriteMap>
101 m.set(own_key, own_val);
103 ::lemon::ignore_unused_variable_warning(key);
104 ::lemon::ignore_unused_variable_warning(val);
105 ::lemon::ignore_unused_variable_warning(own_key);
106 ::lemon::ignore_unused_variable_warning(own_val);
110 const typename _WriteMap::Key& own_key;
111 const typename _WriteMap::Value& own_val;
117 /// Read/writable map concept
119 /// Read/writable map concept.
121 template<typename K, typename T>
122 class ReadWriteMap : public ReadMap<K,T>,
126 /// The key type of the map.
128 /// \brief The value type of the map.
129 /// (The type of objects associated with the keys).
132 /// Returns the value associated with the given key.
133 Value operator[](const Key &) const {
138 /// Sets the value associated with the given key.
139 void set(const Key &, const Value &) {}
141 template<typename _ReadWriteMap>
144 checkConcept<ReadMap<K, T>, _ReadWriteMap >();
145 checkConcept<WriteMap<K, T>, _ReadWriteMap >();
151 /// Dereferable map concept
153 /// Dereferable map concept.
155 template<typename K, typename T, typename R, typename CR>
156 class ReferenceMap : public ReadWriteMap<K,T>
159 /// Tag for reference maps.
160 typedef True ReferenceMapTag;
161 /// The key type of the map.
163 /// \brief The value type of the map.
164 /// (The type of objects associated with the keys).
166 /// The reference type of the map.
168 /// The const reference type of the map.
169 typedef CR ConstReference;
173 /// Returns a reference to the value associated with the given key.
174 Reference operator[](const Key &) {
179 /// Returns a const reference to the value associated with the given key.
180 ConstReference operator[](const Key &) const {
185 /// Sets the value associated with the given key.
186 void set(const Key &k,const Value &t) { operator[](k)=t; }
188 template<typename _ReferenceMap>
190 typename enable_if<typename _ReferenceMap::ReferenceMapTag, void>::type
192 checkConcept<ReadWriteMap<K, T>, _ReferenceMap >();
197 own_ref = m[own_key];
198 m[own_key] = own_val;
199 m[own_key] = own_ref;
200 m[own_key] = own_cref;
208 const typename _ReferenceMap::Key& own_key;
209 typename _ReferenceMap::Value& own_val;
210 typename _ReferenceMap::Reference own_ref;
211 typename _ReferenceMap::ConstReference own_cref;
219 } //namespace concepts