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