Changes in lemon/concepts/maps.h [74:9394072da54f:94:a4688e4138ec] in lemon
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/concepts/maps.h
r74 r94 30 30 31 31 namespace concepts { 32 32 33 33 /// \addtogroup concept 34 34 /// @{ … … 43 43 public: 44 44 /// The key type of the map. 45 typedef K Key; 46 /// The value type of the map. (The type of objects associated with the keys). 47 typedef T Value; 48 49 /// Returns the value associated with a key. 50 51 /// Returns the value associated with a key. 52 /// \bug Value shouldn't need to be default constructible. 53 /// 54 Value operator[](const Key &) const {return Value();} 45 typedef K Key; 46 /// The value type of the map. (The type of objects associated with the keys). 47 typedef T Value; 48 49 /// Returns the value associated with the given key. 50 Value operator[](const Key &) const { 51 return *static_cast<Value *>(0); 52 } 55 53 56 54 template<typename _ReadMap> … … 59 57 Value val = m[key]; 60 58 val = m[key]; 61 typename _ReadMap::Value own_val = m[own_key]; 62 own_val = m[own_key]; 63 64 ignore_unused_variable_warning(val); 65 ignore_unused_variable_warning(own_val); 66 ignore_unused_variable_warning(key); 67 } 68 Key& key; 69 typename _ReadMap::Key& own_key; 70 _ReadMap& m; 71 }; 72 73 }; 74 75 76 /// Writable map concept 77 78 /// Writable map concept. 79 /// 80 template<typename K, typename T> 81 class WriteMap 82 { 83 public: 84 /// The key type of the map. 85 typedef K Key; 86 /// The value type of the map. (The type of objects associated with the keys). 87 typedef T Value; 88 89 /// Sets the value associated with a key. 90 void set(const Key &,const Value &) {} 91 92 ///Default constructor 93 WriteMap() {} 94 95 template <typename _WriteMap> 96 struct Constraints { 97 void constraints() { 98 // No constraints for constructor. 99 m.set(key, val); 100 m.set(own_key, own_val); 59 typename _ReadMap::Value own_val = m[own_key]; 60 own_val = m[own_key]; 61 101 62 ignore_unused_variable_warning(key); 102 63 ignore_unused_variable_warning(val); … … 104 65 ignore_unused_variable_warning(own_val); 105 66 } 106 107 Value& val; 108 typename _WriteMap::Value own_val; 109 Key& key; 110 typename _WriteMap::Key& own_key; 67 const Key& key; 68 const typename _ReadMap::Key& own_key; 69 const _ReadMap& m; 70 }; 71 72 }; 73 74 75 /// Writable map concept 76 77 /// Writable map concept. 78 /// 79 template<typename K, typename T> 80 class WriteMap 81 { 82 public: 83 /// The key type of the map. 84 typedef K Key; 85 /// The value type of the map. (The type of objects associated with the keys). 86 typedef T Value; 87 88 /// Sets the value associated with the given key. 89 void set(const Key &, const Value &) {} 90 91 /// Default constructor. 92 WriteMap() {} 93 94 template <typename _WriteMap> 95 struct Constraints { 96 void constraints() { 97 m.set(key, val); 98 m.set(own_key, own_val); 99 100 ignore_unused_variable_warning(key); 101 ignore_unused_variable_warning(val); 102 ignore_unused_variable_warning(own_key); 103 ignore_unused_variable_warning(own_val); 104 } 105 const Key& key; 106 const Value& val; 107 const typename _WriteMap::Key& own_key; 108 const typename _WriteMap::Value own_val; 111 109 _WriteMap& m; 112 113 110 }; 114 111 }; 115 112 116 113 /// Read/writable map concept 117 114 118 115 /// Read/writable map concept. 119 116 /// … … 124 121 public: 125 122 /// The key type of the map. 126 typedef K Key; 127 /// The value type of the map. (The type of objects associated with the keys). 128 typedef T Value; 129 130 /// Returns the value associated with a key. 131 Value operator[](const Key &) const {return Value();} 132 /// Sets the value associated with a key. 133 void set(const Key & ,const Value &) {} 123 typedef K Key; 124 /// The value type of the map. (The type of objects associated with the keys). 125 typedef T Value; 126 127 /// Returns the value associated with the given key. 128 Value operator[](const Key &) const { 129 return *static_cast<Value *>(0); 130 } 131 132 /// Sets the value associated with the given key. 133 void set(const Key &, const Value &) {} 134 134 135 135 template<typename _ReadWriteMap> … … 141 141 }; 142 142 }; 143 144 143 144 145 145 /// Dereferable map concept 146 146 147 147 /// Dereferable map concept. 148 148 /// 149 /// \todo Rethink this concept.150 149 template<typename K, typename T, typename R, typename CR> 151 150 class ReferenceMap : public ReadWriteMap<K,T> … … 155 154 typedef True ReferenceMapTag; 156 155 /// The key type of the map. 157 typedef K Key; 156 typedef K Key; 158 157 /// The value type of the map. (The type of objects associated with the keys). 159 158 typedef T Value; … … 163 162 typedef CR ConstReference; 164 163 165 protected: 166 Value tmp; 167 public: 168 169 ///Returns a reference to the value associated with a key. 170 Reference operator[](const Key &) { return tmp; } 171 ///Returns a const reference to the value associated with a key. 172 ConstReference operator[](const Key &) const { return tmp; } 173 /// Sets the value associated with a key. 164 public: 165 166 /// Returns a reference to the value associated with the given key. 167 Reference operator[](const Key &) { 168 return *static_cast<Value *>(0); 169 } 170 171 /// Returns a const reference to the value associated with the given key. 172 ConstReference operator[](const Key &) const { 173 return *static_cast<Value *>(0); 174 } 175 176 /// Sets the value associated with the given key. 174 177 void set(const Key &k,const Value &t) { operator[](k)=t; } 175 178 … … 178 181 void constraints() { 179 182 checkConcept<ReadWriteMap<K, T>, _ReferenceMap >(); 183 ref = m[key]; 180 184 m[key] = val; 181 val = m[key];182 185 m[key] = ref; 183 ref = m[key]; 186 m[key] = cref; 187 own_ref = m[own_key]; 184 188 m[own_key] = own_val; 185 own_val = m[own_key];186 189 m[own_key] = own_ref; 187 own_ref = m[own_key]; 188 } 189 190 typename _ReferenceMap::Key& own_key; 190 m[own_key] = own_cref; 191 m[key] = m[own_key]; 192 m[own_key] = m[key]; 193 } 194 const Key& key; 195 Value& val; 196 Reference ref; 197 ConstReference cref; 198 const typename _ReferenceMap::Key& own_key; 191 199 typename _ReferenceMap::Value& own_val; 192 200 typename _ReferenceMap::Reference own_ref; 193 Key& key; 194 Value& val; 195 Reference ref; 201 typename _ReferenceMap::ConstReference own_cref; 196 202 _ReferenceMap& m; 197 203 };
Note: See TracChangeset
for help on using the changeset viewer.