1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/hugo/skeletons/maps.h Thu May 06 13:21:24 2004 +0000
1.3 @@ -0,0 +1,130 @@
1.4 +// -*- c++ -*-
1.5 +#ifndef HUGO_MAPSKELETON_H
1.6 +#define HUGO_MAPSKELETON_H
1.7 +
1.8 +///\file
1.9 +///\brief Map concepts checking classes for testing and documenting.
1.10 +
1.11 +namespace hugo {
1.12 +
1.13 + /// The namespace of HUGOlib concepts and concept checking classes
1.14 + namespace skeleton {
1.15 +
1.16 + /// Readable map concept
1.17 + template<typename K, typename T>
1.18 + class ReadableMap
1.19 + {
1.20 + public:
1.21 + /// Map's key type.
1.22 + typedef K KeyType;
1.23 + /// Map's value type. (The type of objects associated with the keys).
1.24 + typedef T ValueType;
1.25 +
1.26 + /// Returns the value associated with a key.
1.27 + ValueType operator[](const KeyType &k) const {return ValueType();}
1.28 +
1.29 + /// Copy contsructor. (optional)
1.30 + ReadableMap(const ReadableMap&) {}
1.31 + /// Assignment operator. (optional)
1.32 + ReadableMap& operator=(const ReadableMap&) {return *this;}
1.33 +
1.34 + ReadableMap() {}
1.35 + };
1.36 +
1.37 +
1.38 + /// Writable map concept
1.39 + template<typename K, typename T>
1.40 + class WritableMap
1.41 + {
1.42 + public:
1.43 + /// Map's key type.
1.44 + typedef K KeyType;
1.45 + /// Map's value type. (The type of objects associated with the keys).
1.46 + typedef T ValueType;
1.47 +
1.48 + /// Sets the value associated with a key.
1.49 + void set(const KeyType &k,const ValueType &t) {}
1.50 +
1.51 + WritableMap() {}
1.52 + };
1.53 +
1.54 + ///Read/Writeable map concept
1.55 + template<typename K, typename T>
1.56 + class ReadWritableMap : public ReadableMap<K,T>,
1.57 + public WritableMap<K,T>
1.58 + {
1.59 + public:
1.60 + /// Map's key type.
1.61 + typedef K KeyType;
1.62 + /// Map's value type. (The type of objects associated with the keys).
1.63 + typedef T ValueType;
1.64 +
1.65 + /// Returns the value associated with a key.
1.66 + ValueType operator[](const KeyType &k) const {return ValueType();}
1.67 + /// Sets the value associated with a key.
1.68 + void set(const KeyType &k,const ValueType &t) {}
1.69 +
1.70 + /// Copy contsructor. (optional)
1.71 + ReadWritableMap(const ReadWritableMap&) {}
1.72 + /// Assignment operator. (optional)
1.73 + ReadWritableMap& operator=(const ReadWritableMap&) {return *this;}
1.74 +
1.75 + /// Facility to define a map with an other value type (optional)
1.76 + template<typename T1>
1.77 + struct rebind {
1.78 + /// The type of a map with the given value type
1.79 + typedef ReadWritableMap<K,T1> other;
1.80 + };
1.81 + /// @brief Constructor that copies all keys from the other map and
1.82 + /// assigns to them a default value (optional)
1.83 + template<typename T1>
1.84 + ReadWritableMap(const ReadWritableMap<K,T1> &map, const ValueType &v) {}
1.85 +
1.86 + ReadWritableMap() {}
1.87 + };
1.88 +
1.89 +
1.90 + ///Dereferable map concept
1.91 + template<typename K, typename T>
1.92 + class DereferableMap : public ReadWritableMap<K,T>
1.93 + {
1.94 + public:
1.95 + /// Map's key type.
1.96 + typedef K KeyType;
1.97 + /// Map's value type. (The type of objects associated with the keys).
1.98 + typedef T ValueType;
1.99 + /// Map's reference type. (Reference to an object associated with a key)
1.100 + typedef ValueType& ReferenceType;
1.101 + /// Map's const reference type.
1.102 + typedef const ValueType& ConstReferenceType;
1.103 +
1.104 + ///Returns a reference to the value associated to a key.
1.105 + ReferenceType operator[](const KeyType &i);
1.106 + ///Returns a const reference to the value associated to a key.
1.107 + ConstReferenceType operator[](const KeyType &i) const;
1.108 + /// Sets the value associated with a key.
1.109 + void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
1.110 +
1.111 + /// Copy contsructor. (optional)
1.112 + DereferableMap(const DereferableMap&) {}
1.113 + /// Assignment operator. (optional)
1.114 + DereferableMap& operator=(const DereferableMap&) {return *this;}
1.115 +
1.116 + /// Facility to define a map with an other value type (optional)
1.117 + template<typename T1>
1.118 + struct rebind {
1.119 + /// The type of a map with the given value type
1.120 + typedef DereferableMap<K,T1> other;
1.121 + };
1.122 + /// @brief Constructor that copies all keys from the other map and
1.123 + /// assigns to them a default value (optional)
1.124 + template<typename T1>
1.125 + DereferableMap(const DereferableMap<K,T1> &map, const ValueType &v) {}
1.126 +
1.127 + DereferableMap() {}
1.128 + };
1.129 +
1.130 +
1.131 + }
1.132 +}
1.133 +#endif // HUGO_MAPSKELETON_H