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