diff -r aa19ca32d9b0 -r ca95f8b5c931 src/lemon/concept/maps.h --- a/src/lemon/concept/maps.h Sat Nov 13 17:47:44 2004 +0000 +++ b/src/lemon/concept/maps.h Sat Nov 13 21:37:54 2004 +0000 @@ -40,11 +40,28 @@ /// Map's value type. (The type of objects associated with the keys). typedef T Value; + // \bug Value don't need to be default constructible. /// Returns the value associated with a key. - Value operator[](const Key &k) const {return Value();} + Value operator[](const Key &) const {return Value();} - ///Default constructor - ReadMap() {} + template + struct Constraints { + + void constraints() { + Value val = m[key]; + val = m[key]; + typename _ReadMap::Value own_val = m[own_key]; + own_val = m[own_key]; + + ignore_unused_variable_warning(val); + ignore_unused_variable_warning(own_val); + ignore_unused_variable_warning(key); + } + Key& key; + typename _ReadMap::Key& own_key; + _ReadMap& m; + }; + }; @@ -63,6 +80,26 @@ ///Default constructor WriteMap() {} + + template + struct Constraints { + void constraints() { + // No constraints for constructor. + m.set(key, val); + m.set(own_key, own_val); + ignore_unused_variable(key); + ignore_unused_variable(val); + ignore_unused_variable(own_key); + ignore_unused_variable(own_val); + } + + Value& val; + typename _WriteMap::Value own_val; + Key& key; + typename _WriteMap::Key& own_key; + WriteMap& m; + + }; }; ///Read/Writable map concept @@ -81,13 +118,18 @@ /// Sets the value associated with a key. void set(const Key &k,const Value &t) {} - ///Default constructor - ReadWriteMap() {} + template + struct Constraints { + void constraints() { + checkConcept, _ReadWriteMap >(); + checkConcept, _ReadWriteMap >(); + } + }; }; ///Dereferable map concept - template + template class ReferenceMap : public ReadWriteMap { public: @@ -95,13 +137,14 @@ typedef K Key; /// Map's value type. (The type of objects associated with the keys). typedef T Value; + /// Map's reference type. + typedef R Reference; + /// Map's const reference type. + typedef CR ConstReference; protected: Value tmp; public: - typedef Value& Reference; - /// Map's const reference type. - typedef const Value& ConstReference; ///Returns a reference to the value associated to a key. Reference operator[](const Key &i) { return tmp; } @@ -111,134 +154,32 @@ /// Sets the value associated with a key. void set(const Key &k,const Value &t) { operator[](k)=t; } - ///Default constructor - ReferenceMap() {} + // \todo rethink this concept + template + struct ReferenceMapConcept { + + void constraints() { + checkConcept(); + m[key] = val; + val = m[key]; + m[key] = ref; + ref = m[key]; + m[own_key] = own_val; + own_val = m[own_key]; + m[own_key] = own_ref; + own_ref = m[own_key]; + } + + typename _ReferenceMap::Key& own_key; + typename _ReferenceMap::Value& own_val; + typename _ReferenceMap::Reference& own_ref; + Key& key; + Value& val; + Reference& ref; + ReferenceMap& m; + }; }; - - template - class GraphMap : public ReadWriteMap { - // I really, really don't like the idea that every graph should have - // reference maps! --klao - - private: - // We state explicitly that graph maps have no default constructor? - GraphMap(); - - public: - explicit GraphMap(Graph const&) {} - // value for initializing - GraphMap(Graph const&, T) {} - - // this probably should be required: - GraphMap(GraphMap const&) {} - GraphMap& operator=(GraphMap const&) { return *this; } - - // but this is a absolute no-op! We should provide a more generic - // graph-map-copy operation. - // - // template - // GraphMap(GraphMap const&); - // - // template - // GraphMap& operator=(const GraphMap&); - }; - - - /**************** Concept-checking classes ****************/ - - template - struct ReadMapConcept { - typedef typename ReadMap::Key Key; - typedef typename ReadMap::Value Value; - - void constraints() { - // No constraints for constructor. - - // What are the requirement for the Value? - // CopyConstructible? Assignable? None of these? - Value v = m[k]; - v = m[k]; - - // FIXME: - ignore_unused_variable_warning(v); - } - - ReadMap m; - Key k; - }; - - template - struct WriteMapConcept { - typedef typename WriteMap::Key Key; - typedef typename WriteMap::Value Value; - - void constraints() { - // No constraints for constructor. - - m.set(k, v); - } - - WriteMap m; - Key k; - Value v; - }; - - template - struct ReadWriteMapConcept { - void constraints() { - function_requires< ReadMapConcept >(); - function_requires< WriteMapConcept >(); - } - }; - - template - struct ReferenceMapConcept { - typedef typename ReferenceMap::Key Key; - typedef typename ReferenceMap::Value Value; - typedef typename ReferenceMap::Reference Reference; - - // What for is this? - typedef typename ReferenceMap::ConstReference ConstReference; - - void constraints() { - function_requires< ReadWriteMapConcept >(); - - m[k] = v; - // Or should we require real reference? - // Like this: - // Value &vv = m[k]; - // ignore_unused_variable_warning(vv); - } - - ReferenceMap m; - Key k; - Value v; - }; - - /// \todo GraphMapConceptCheck - - template - struct GraphMapConcept { - void constraints() { - function_requires< ReadWriteMapConcept >(); - // Construction with a graph parameter - GraphMap a(g); - // Ctor with a graph and a default value parameter - GraphMap a2(g,t); - // Copy ctor. Do we need it? - GraphMap b=c; - // Copy operator. Do we need it? - a=b; - - ignore_unused_variable_warning(a2); - } - const GraphMap &c; - const Graph &g; - const typename GraphMap::Value &t; - }; - - // @} } //namespace concept