deba@1720: /* -*- C++ -*- deba@1720: * lemon/concept/matrix_maps.h - Part of LEMON, a generic C++ optimization library deba@1720: * deba@1720: * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport deba@1720: * (Egervary Research Group on Combinatorial Optimization, EGRES). deba@1720: * deba@1720: * Permission to use, modify and distribute this software is granted deba@1720: * provided that this copyright notice appears in all copies. For deba@1720: * precise terms see the accompanying LICENSE file. deba@1720: * deba@1720: * This software is provided "AS IS" with no warranty of any kind, deba@1720: * express or implied, and with no claim as to its suitability for any deba@1720: * purpose. deba@1720: * deba@1720: */ deba@1720: deba@1720: #ifndef LEMON_CONCEPT_MATRIX_MAPS_H deba@1720: #define LEMON_CONCEPT_MATRIX_MAPS_H deba@1720: deba@1720: #include deba@1720: #include deba@1720: deba@1720: ///\ingroup concept deba@1720: ///\file deba@1720: ///\brief MatrixMap concepts checking classes for testing and documenting. deba@1720: deba@1720: namespace lemon { deba@1720: deba@1720: namespace concept { deba@1720: deba@1720: /// \addtogroup concept deba@1720: /// @{ deba@1720: deba@1720: /// Readable matrix map concept deba@1720: template deba@1720: class ReadMatrixMap deba@1720: { deba@1720: public: deba@1720: /// Map's first key type. deba@1720: typedef K1 FirstKey; deba@1720: /// Map's second key type. deba@1720: typedef K2 SecondKey; deba@1720: /// \brief Map's value type. deba@1720: /// (The type of objects associated with the pairs of keys). deba@1720: typedef V Value; deba@1720: deba@1720: // \bug Value don't need to be default constructible. deba@1720: /// Returns the value associated with a key. deba@1720: Value operator()(const FirstKey&, const SecondKey&) const { deba@1720: return Value(); deba@1720: } deba@1720: deba@1720: template deba@1720: struct Constraints { deba@1720: deba@1720: void constraints() { deba@1720: Value val = m(first_key, second_key); deba@1720: val = m(first_key, second_key); deba@1720: typename _ReadMatrixMap::Value own_val = deba@1720: m(own_first_key, own_second_key); deba@1720: own_val = m(own_first_key, own_second_key); deba@1720: ignore_unused_variable_warning(val); deba@1720: ignore_unused_variable_warning(own_val); deba@1720: } deba@1720: deba@1720: FirstKey& first_key; deba@1720: SecondKey& second_key; deba@1720: typename _ReadMatrixMap::FirstKey& own_first_key; deba@1720: typename _ReadMatrixMap::SecondKey& own_second_key; deba@1720: _ReadMatrixMap& m; deba@1720: }; deba@1720: deba@1720: }; deba@1720: deba@1720: deba@1720: /// Writable map concept deba@1720: template deba@1720: class WriteMatrixMap { deba@1720: public: deba@1720: /// Map's first key type. deba@1720: typedef K1 FirstKey; deba@1720: /// Map's second key type. deba@1720: typedef K2 SecondKey; deba@1720: /// \brief Map's value type. deba@1720: /// (The type of objects associated with the pairs of keys). deba@1720: typedef V Value; deba@1720: deba@1720: /// Sets the value associated with the pair of keys. deba@1720: void set(const FirstKey&, const SecondKey& ,const Value&) {} deba@1720: deba@1720: template deba@1720: struct Constraints { deba@1720: void constraints() { deba@1720: // No constraints for constructor. deba@1720: m.set(first_key, second_key, val); deba@1720: m.set(own_first_key, own_second_key, own_val); deba@1720: } deba@1720: deba@1720: Value& val; deba@1720: typename _WriteMatrixMap::Value own_val; deba@1720: FirstKey& first_key; deba@1720: SecondKey& second_key; deba@1720: typename _WriteMatrixMap::FirstKey& own_first_key; deba@1720: typename _WriteMatrixMap::SecondKey& own_second_key; deba@1720: _WriteMatrixMap& m; deba@1720: deba@1720: }; deba@1720: }; deba@1720: deba@1720: ///Read/Writable map concept deba@1720: template deba@1720: class ReadWriteMatrixMap deba@1720: : public ReadMatrixMap, public WriteMatrixMap { deba@1720: public: deba@1720: /// Map's first key type. deba@1720: typedef K1 FirstKey; deba@1720: /// Map's second key type. deba@1720: typedef K2 SecondKey; deba@1720: /// \brief Map's value type. deba@1720: /// (The type of objects associated with the pairs of keys). deba@1720: typedef V Value; deba@1720: deba@1720: /// Returns the value associated with a pair of keys. deba@1720: Value operator()(const FirstKey&, const SecondKey&) const { deba@1720: return Value(); deba@1720: } deba@1720: /// Sets the value associated with the pair of keys. deba@1720: void set(const FirstKey&, const SecondKey& ,const Value&) {} deba@1720: deba@1720: template deba@1720: struct Constraints { deba@1720: void constraints() { deba@1720: checkConcept, _ReadWriteMatrixMap >(); deba@1720: checkConcept, _ReadWriteMatrixMap >(); deba@1720: } deba@1720: }; deba@1720: }; deba@1720: deba@1720: deba@1720: ///Dereferable matrix map concept deba@1720: template deba@1720: class ReferenceMatrixMap : public ReadWriteMatrixMap deba@1720: { deba@1720: public: deba@1720: /// Tag for reference maps. deba@1720: typedef True ReferenceMapTag; deba@1720: /// Map's first key type. deba@1720: typedef K1 FirstKey; deba@1720: /// Map's second key type. deba@1720: typedef K1 SecondKey; deba@1720: /// Map's value type. (The type of objects associated with the keys). deba@1720: typedef V Value; deba@1720: /// Map's reference type. deba@1720: typedef R Reference; deba@1720: /// Map's const reference type. deba@1720: typedef CR ConstReference; deba@1720: deba@1720: protected: deba@1720: Value tmp; deba@1720: public: deba@1720: deba@1720: ///Returns a reference to the value associated to a pair of keys. deba@1720: Reference operator()(const FirstKey&, const SecondKey&) { deba@1720: return tmp; deba@1720: } deba@1720: ///Returns a const reference to the value associated to a pair of keys. deba@1720: ConstReference operator()(const FirstKey&, const SecondKey&) const { deba@1720: return tmp; deba@1720: } deba@1720: /// Sets the value associated with the pair of keys. deba@1720: void set(const FirstKey&, const SecondKey& ,const Value&) {} deba@1720: deba@1720: // \todo rethink this concept deba@1720: template deba@1720: struct ReferenceMapConcept { deba@1720: deba@1720: void constraints() { deba@1720: checkConcept(); deba@1720: m(first_key, second_key) = val; deba@1720: val = m(first_key, second_key); deba@1720: m(first_key, second_key) = ref; deba@1720: ref = m(first_key, second_key); deba@1720: m(own_first_key, own_second_key) = own_val; deba@1720: own_val = m(own_first_key, own_second_key); deba@1720: m(own_first_key, own_second_key) = own_ref; deba@1720: own_ref = m(own_first_key, own_second_key); deba@1720: } deba@1720: deba@1720: typename _ReferenceMatrixMap::Key& own_first_key; deba@1720: typename _ReferenceMatrixMap::Key& own_second_key; deba@1720: typename _ReferenceMatrixMap::Value& own_val; deba@1720: typename _ReferenceMatrixMap::Reference& own_ref; deba@1720: FirstKey& first_key; deba@1720: SecondKey& second_key; deba@1720: Value& val; deba@1720: Reference& ref; deba@1720: _ReferenceMatrixMap& m; deba@1720: }; deba@1720: }; deba@1720: deba@1720: // @} deba@1720: deba@1720: } //namespace concept deba@1720: } //namespace lemon deba@1720: #endif // LEMON_CONCEPT_MATRIX_MAPS_H