alpar@186: // -*- c++ -*- alpar@186: #ifndef HUGO_MAPSKELETON_H alpar@186: #define HUGO_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@186: namespace hugo { klao@282: klao@282: /// The namespace of HUGOlib concepts and concept checking classes 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@732: } //namespace hugo alpar@186: #endif // HUGO_MAPSKELETON_H