alpar@906: /* -*- C++ -*- alpar@921: * src/lemon/skeletons/maps.h - Part of LEMON, a generic C++ optimization library alpar@906: * alpar@906: * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@906: * (Egervary Combinatorial Optimization Research Group, EGRES). alpar@906: * alpar@906: * Permission to use, modify and distribute this software is granted alpar@906: * provided that this copyright notice appears in all copies. For alpar@906: * precise terms see the accompanying LICENSE file. alpar@906: * alpar@906: * This software is provided "AS IS" with no warranty of any kind, alpar@906: * express or implied, and with no claim as to its suitability for any alpar@906: * purpose. alpar@906: * alpar@906: */ alpar@906: alpar@921: #ifndef LEMON_MAPSKELETON_H alpar@921: #define LEMON_MAPSKELETON_H alpar@186: alpar@794: ///\ingroup skeletons alpar@242: ///\file alpar@242: ///\brief Map concepts checking classes for testing and documenting. alpar@242: alpar@921: namespace lemon { klao@282: klao@282: namespace skeleton { alpar@186: alpar@794: /// \addtogroup skeletons alpar@794: /// @{ alpar@794: klao@282: /// Readable map concept klao@282: template alpar@732: class ReadMap klao@282: { klao@282: public: klao@282: /// Map's key type. klao@282: typedef K KeyType; klao@282: /// Map's value type. (The type of objects associated with the keys). klao@282: typedef T ValueType; alpar@186: klao@282: /// Returns the value associated with a key. klao@282: ValueType operator[](const KeyType &k) const {return ValueType();} alpar@186: alpar@732: ///Default constructor alpar@732: ReadMap() {} klao@282: }; klao@282: klao@282: klao@282: /// Writable map concept klao@282: template alpar@732: class WriteMap klao@282: { klao@282: public: klao@282: /// Map's key type. klao@282: typedef K KeyType; klao@282: /// Map's value type. (The type of objects associated with the keys). klao@282: typedef T ValueType; klao@282: klao@282: /// Sets the value associated with a key. klao@282: void set(const KeyType &k,const ValueType &t) {} klao@282: alpar@732: ///Default constructor alpar@732: WriteMap() {} klao@282: }; klao@282: alpar@809: ///Read/Writable map concept klao@282: template alpar@732: class ReadWriteMap : public ReadMap, alpar@732: public WriteMap klao@282: { klao@282: public: klao@282: /// Map's key type. klao@282: typedef K KeyType; klao@282: /// Map's value type. (The type of objects associated with the keys). klao@282: typedef T ValueType; klao@282: klao@282: /// Returns the value associated with a key. klao@282: ValueType operator[](const KeyType &k) const {return ValueType();} klao@282: /// Sets the value associated with a key. klao@282: void set(const KeyType &k,const ValueType &t) {} klao@282: alpar@732: ///Default constructor alpar@732: ReadWriteMap() {} klao@282: }; alpar@186: alpar@186: klao@282: ///Dereferable map concept klao@282: template alpar@732: class ReferenceMap : public ReadWriteMap klao@282: { klao@282: public: klao@282: /// Map's key type. klao@282: typedef K KeyType; klao@282: /// Map's value type. (The type of objects associated with the keys). klao@282: typedef T ValueType; alpar@732: alpar@732: protected: alpar@732: ValueType tmp; alpar@732: public: klao@282: typedef ValueType& ReferenceType; klao@282: /// Map's const reference type. klao@282: typedef const ValueType& ConstReferenceType; alpar@186: klao@282: ///Returns a reference to the value associated to a key. alpar@732: ReferenceType operator[](const KeyType &i) { return tmp; } klao@282: ///Returns a const reference to the value associated to a key. alpar@732: ConstReferenceType operator[](const KeyType &i) const alpar@732: { return tmp; } klao@282: /// Sets the value associated with a key. klao@282: void set(const KeyType &k,const ValueType &t) { operator[](k)=t; } alpar@186: alpar@732: ///Default constructor alpar@732: ReferenceMap() {} klao@282: }; alpar@794: alpar@794: // @} alpar@794: alpar@732: } //namespace skeleton alpar@921: } //namespace lemon alpar@921: #endif // LEMON_MAPSKELETON_H