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