diff -r 3fefabfd00b7 -r 7f85e99502db src/include/skeletons/maps.h --- a/src/include/skeletons/maps.h Sat Apr 03 17:26:46 2004 +0000 +++ b/src/include/skeletons/maps.h Sat Apr 03 18:21:25 2004 +0000 @@ -6,79 +6,172 @@ ///\brief Map concepts checking classes for testing and documenting. namespace hugo { + + /// The namespace of HUGOlib concepts and concept checking classes + namespace skeleton { - ///Readable map skeleton - template - class ReadMapSkeleton - { - public: - /// Map value type. - typedef T ValueType; - /// Map key type. - typedef K KeyType; + /// Null map concept + template + class NullMap + { + public: + /// Map's key type. + typedef K KeyType; + /// Map's value type. (The type of objects associated with the keys). + typedef T ValueType; - ///Default constructor. - ReadMapSkeleton() {} + /// Facility to define a map with an other value type + template + struct rebind { + /// The type of a map with the given value type + typedef NullMap other; + }; + + NullMap() {} + }; - ///Reads an element of the map. - ValueType operator[](const KeyType &i) const {return ValueType();} - }; + /// Readable map concept + template + class ReadableMap : public NullMap + { + 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();} - ///Writeable map skeleton - template - class WriteMapSkeleton - { - public: - /// Map value type. - typedef T ValueType; - /// Map key type. - typedef K KeyType; + /// Copy contsructor. (optional) + ReadableMap(const ReadableMap&) {} + /// Assignment operator. (optional) + ReadableMap& operator=(const ReadableMap&) {return *this;} - ///Default constructor. - WriteMapSkeleton() {} - ///'Fill with' constructor. - WriteMapSkeleton(const ValueType &t) {} - - ///Write an element of a map. - void set(const KeyType &i,const ValueType &t) {} - }; + /// Facility to define a map with an other value type (optional) + template + struct rebind { + /// The type of a map with the given value type + typedef ReadableMap other; + }; + /// @brief Constructor that copies all keys from the other map and + /// assigns to them a default value (optional) + template + ReadableMap(const ReadableMap &map, const T1 &v) {} - ///Read/Write map skeleton. - template - class ReadWriteMapSkeleton : public ReadMapSkeleton, - public WriteMapSkeleton - { - public: - ///Default constructor. - ReadWriteMapSkeleton() : ReadMapSkeleton(), WriteMapSkeleton() {} - ///'Fill with' constructor. - ReadWriteMap(const ValueType &t) :ReadMapSkeleton(), WriteMapSkeleton(t) {} - }; + ReadableMap() {} + }; + + + /// Writable map concept + template + class WritableMap : public NullMap + { + 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) {} + + /// Copy contsructor. (optional) + WritableMap(const WritableMap&) {} + /// Assignment operator. (optional) + WritableMap& operator=(const WritableMap&) {return *this;} + + /// Facility to define a map with an other value type (optional) + template + struct rebind { + /// The type of a map with the given value type + typedef WritableMap other; + }; + /// @brief Constructor that copies all keys from the other map and + /// assigns to them a default value (optional) + template + WritableMap(const WritableMap &map, const T1 &v) {} + + WritableMap() {} + }; + + ///Read/Writeable map concept + template + class ReadWritableMap : public ReadableMap, + public WritableMap + { + 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) {} + + /// Copy contsructor. (optional) + ReadWritableMap(const ReadWritableMap&) {} + /// Assignment operator. (optional) + ReadWritableMap& operator=(const ReadWritableMap&) {return *this;} + + /// Facility to define a map with an other value type (optional) + template + struct rebind { + /// The type of a map with the given value type + typedef ReadWritableMap other; + }; + /// @brief Constructor that copies all keys from the other map and + /// assigns to them a default value (optional) + template + ReadWritableMap(const ReadWritableMap &map, const T1 &v) {} + + ReadWritableMap() {} + }; - ///Dereferable map skeleton - template - class MemoryMapSkeleton : public ReadWriteMapSkeleton - { - public: - /// Map value type. - typedef T ValueType; - /// Map key type. - typedef K KeyType; + ///Dereferable map concept + template + class DereferableMap : public ReadWritableMap + { + public: + /// Map's key type. + typedef K KeyType; + /// Map's value type. (The type of objects associated with the keys). + typedef T ValueType; + /// Map's reference type. (Reference to an object associated with a key) + typedef ValueType& ReferenceType; + /// Map's const reference type. + typedef const ValueType& ConstReferenceType; - ///Default constructor. - ReferenceMapSkeleton() : ReadWriteMapSkeleton() {} - ///'Fill with' constructor. - ReferenceMapSkeleton(const ValueType &t) : ReadWriteMapSkeleton(t) {} + ///Returns a reference to the value associated to a key. + ReferenceType operator[](const KeyType &i); + ///Returns a const reference to the value associated to a key. + ConstReferenceType operator[](const KeyType &i) const; + /// Sets the value associated with a key. + void set(const KeyType &k,const ValueType &t) { operator[](k)=t; } - ///Give a reference to the value belonging to a key. - ValueType &operator[](const KeyType &i) {return *(ValueType*)0;} - ///Give a const reference to the value belonging to a key. - const ValueType &operator[](const KeyType &i) const {return *(T*)0;} - }; + /// Copy contsructor. (optional) + DereferableMap(const DereferableMap&) {} + /// Assignment operator. (optional) + DereferableMap& operator=(const DereferableMap&) {return *this;} + /// Facility to define a map with an other value type (optional) + template + struct rebind { + /// The type of a map with the given value type + typedef DereferableMap other; + }; + /// @brief Constructor that copies all keys from the other map and + /// assigns to them a default value (optional) + template + DereferableMap(const DereferableMap &map, const T1 &v) {} + DereferableMap() {} + }; + + } } #endif // HUGO_MAPSKELETON_H