1.1 --- a/src/include/skeletons/maps.h Sat Apr 03 17:26:46 2004 +0000
1.2 +++ b/src/include/skeletons/maps.h Sat Apr 03 18:21:25 2004 +0000
1.3 @@ -6,79 +6,172 @@
1.4 ///\brief Map concepts checking classes for testing and documenting.
1.5
1.6 namespace hugo {
1.7 +
1.8 + /// The namespace of HUGOlib concepts and concept checking classes
1.9 + namespace skeleton {
1.10
1.11 - ///Readable map skeleton
1.12 - template<typename K, typename T>
1.13 - class ReadMapSkeleton
1.14 - {
1.15 - public:
1.16 - /// Map value type.
1.17 - typedef T ValueType;
1.18 - /// Map key type.
1.19 - typedef K KeyType;
1.20 + /// Null map concept
1.21 + template<typename K, typename T>
1.22 + class NullMap
1.23 + {
1.24 + public:
1.25 + /// Map's key type.
1.26 + typedef K KeyType;
1.27 + /// Map's value type. (The type of objects associated with the keys).
1.28 + typedef T ValueType;
1.29
1.30 - ///Default constructor.
1.31 - ReadMapSkeleton() {}
1.32 + /// Facility to define a map with an other value type
1.33 + template<typename T1>
1.34 + struct rebind {
1.35 + /// The type of a map with the given value type
1.36 + typedef NullMap<K,T1> other;
1.37 + };
1.38 +
1.39 + NullMap() {}
1.40 + };
1.41
1.42 - ///Reads an element of the map.
1.43 - ValueType operator[](const KeyType &i) const {return ValueType();}
1.44 - };
1.45 + /// Readable map concept
1.46 + template<typename K, typename T>
1.47 + class ReadableMap : public NullMap<K,T>
1.48 + {
1.49 + public:
1.50 + /// Map's key type.
1.51 + typedef K KeyType;
1.52 + /// Map's value type. (The type of objects associated with the keys).
1.53 + typedef T ValueType;
1.54
1.55 + /// Returns the value associated with a key.
1.56 + ValueType operator[](const KeyType &k) const {return ValueType();}
1.57
1.58 - ///Writeable map skeleton
1.59 - template<typename K, typename T>
1.60 - class WriteMapSkeleton
1.61 - {
1.62 - public:
1.63 - /// Map value type.
1.64 - typedef T ValueType;
1.65 - /// Map key type.
1.66 - typedef K KeyType;
1.67 + /// Copy contsructor. (optional)
1.68 + ReadableMap(const ReadableMap&) {}
1.69 + /// Assignment operator. (optional)
1.70 + ReadableMap& operator=(const ReadableMap&) {return *this;}
1.71
1.72 - ///Default constructor.
1.73 - WriteMapSkeleton() {}
1.74 - ///'Fill with' constructor.
1.75 - WriteMapSkeleton(const ValueType &t) {}
1.76 -
1.77 - ///Write an element of a map.
1.78 - void set(const KeyType &i,const ValueType &t) {}
1.79 - };
1.80 + /// Facility to define a map with an other value type (optional)
1.81 + template<typename T1>
1.82 + struct rebind {
1.83 + /// The type of a map with the given value type
1.84 + typedef ReadableMap<K,T1> other;
1.85 + };
1.86 + /// @brief Constructor that copies all keys from the other map and
1.87 + /// assigns to them a default value (optional)
1.88 + template<typename T1>
1.89 + ReadableMap(const ReadableMap<K,T1> &map, const T1 &v) {}
1.90
1.91 - ///Read/Write map skeleton.
1.92 - template<typename K, typename T>
1.93 - class ReadWriteMapSkeleton : public ReadMapSkeleton<K,T>,
1.94 - public WriteMapSkeleton<K,T>
1.95 - {
1.96 - public:
1.97 - ///Default constructor.
1.98 - ReadWriteMapSkeleton() : ReadMapSkeleton(), WriteMapSkeleton() {}
1.99 - ///'Fill with' constructor.
1.100 - ReadWriteMap(const ValueType &t) :ReadMapSkeleton(), WriteMapSkeleton(t) {}
1.101 - };
1.102 + ReadableMap() {}
1.103 + };
1.104 +
1.105 +
1.106 + /// Writable map concept
1.107 + template<typename K, typename T>
1.108 + class WritableMap : public NullMap<K,T>
1.109 + {
1.110 + public:
1.111 + /// Map's key type.
1.112 + typedef K KeyType;
1.113 + /// Map's value type. (The type of objects associated with the keys).
1.114 + typedef T ValueType;
1.115 +
1.116 + /// Sets the value associated with a key.
1.117 + void set(const KeyType &k,const ValueType &t) {}
1.118 +
1.119 + /// Copy contsructor. (optional)
1.120 + WritableMap(const WritableMap&) {}
1.121 + /// Assignment operator. (optional)
1.122 + WritableMap& operator=(const WritableMap&) {return *this;}
1.123 +
1.124 + /// Facility to define a map with an other value type (optional)
1.125 + template<typename T1>
1.126 + struct rebind {
1.127 + /// The type of a map with the given value type
1.128 + typedef WritableMap<K,T1> other;
1.129 + };
1.130 + /// @brief Constructor that copies all keys from the other map and
1.131 + /// assigns to them a default value (optional)
1.132 + template<typename T1>
1.133 + WritableMap(const WritableMap<K,T1> &map, const T1 &v) {}
1.134 +
1.135 + WritableMap() {}
1.136 + };
1.137 +
1.138 + ///Read/Writeable map concept
1.139 + template<typename K, typename T>
1.140 + class ReadWritableMap : public ReadableMap<K,T>,
1.141 + public WritableMap<K,T>
1.142 + {
1.143 + public:
1.144 + /// Map's key type.
1.145 + typedef K KeyType;
1.146 + /// Map's value type. (The type of objects associated with the keys).
1.147 + typedef T ValueType;
1.148 +
1.149 + /// Returns the value associated with a key.
1.150 + ValueType operator[](const KeyType &k) const {return ValueType();}
1.151 + /// Sets the value associated with a key.
1.152 + void set(const KeyType &k,const ValueType &t) {}
1.153 +
1.154 + /// Copy contsructor. (optional)
1.155 + ReadWritableMap(const ReadWritableMap&) {}
1.156 + /// Assignment operator. (optional)
1.157 + ReadWritableMap& operator=(const ReadWritableMap&) {return *this;}
1.158 +
1.159 + /// Facility to define a map with an other value type (optional)
1.160 + template<typename T1>
1.161 + struct rebind {
1.162 + /// The type of a map with the given value type
1.163 + typedef ReadWritableMap<K,T1> other;
1.164 + };
1.165 + /// @brief Constructor that copies all keys from the other map and
1.166 + /// assigns to them a default value (optional)
1.167 + template<typename T1>
1.168 + ReadWritableMap(const ReadWritableMap<K,T1> &map, const T1 &v) {}
1.169 +
1.170 + ReadWritableMap() {}
1.171 + };
1.172
1.173
1.174 - ///Dereferable map skeleton
1.175 - template<typename K, typename T>
1.176 - class MemoryMapSkeleton : public ReadWriteMapSkeleton<K,T>
1.177 - {
1.178 - public:
1.179 - /// Map value type.
1.180 - typedef T ValueType;
1.181 - /// Map key type.
1.182 - typedef K KeyType;
1.183 + ///Dereferable map concept
1.184 + template<typename K, typename T>
1.185 + class DereferableMap : public ReadWritableMap<K,T>
1.186 + {
1.187 + public:
1.188 + /// Map's key type.
1.189 + typedef K KeyType;
1.190 + /// Map's value type. (The type of objects associated with the keys).
1.191 + typedef T ValueType;
1.192 + /// Map's reference type. (Reference to an object associated with a key)
1.193 + typedef ValueType& ReferenceType;
1.194 + /// Map's const reference type.
1.195 + typedef const ValueType& ConstReferenceType;
1.196
1.197 - ///Default constructor.
1.198 - ReferenceMapSkeleton() : ReadWriteMapSkeleton() {}
1.199 - ///'Fill with' constructor.
1.200 - ReferenceMapSkeleton(const ValueType &t) : ReadWriteMapSkeleton(t) {}
1.201 + ///Returns a reference to the value associated to a key.
1.202 + ReferenceType operator[](const KeyType &i);
1.203 + ///Returns a const reference to the value associated to a key.
1.204 + ConstReferenceType operator[](const KeyType &i) const;
1.205 + /// Sets the value associated with a key.
1.206 + void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
1.207
1.208 - ///Give a reference to the value belonging to a key.
1.209 - ValueType &operator[](const KeyType &i) {return *(ValueType*)0;}
1.210 - ///Give a const reference to the value belonging to a key.
1.211 - const ValueType &operator[](const KeyType &i) const {return *(T*)0;}
1.212 - };
1.213 + /// Copy contsructor. (optional)
1.214 + DereferableMap(const DereferableMap&) {}
1.215 + /// Assignment operator. (optional)
1.216 + DereferableMap& operator=(const DereferableMap&) {return *this;}
1.217
1.218 + /// Facility to define a map with an other value type (optional)
1.219 + template<typename T1>
1.220 + struct rebind {
1.221 + /// The type of a map with the given value type
1.222 + typedef DereferableMap<K,T1> other;
1.223 + };
1.224 + /// @brief Constructor that copies all keys from the other map and
1.225 + /// assigns to them a default value (optional)
1.226 + template<typename T1>
1.227 + DereferableMap(const DereferableMap<K,T1> &map, const T1 &v) {}
1.228
1.229 + DereferableMap() {}
1.230 + };
1.231
1.232 +
1.233 + }
1.234 }
1.235 #endif // HUGO_MAPSKELETON_H