Changeset 282:7f85e99502db in lemon0.x for src/include/skeletons
 Timestamp:
 04/03/04 20:21:25 (20 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@396
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/include/skeletons/maps.h
r254 r282 7 7 8 8 namespace hugo { 9 10 /// The namespace of HUGOlib concepts and concept checking classes 11 namespace skeleton { 9 12 10 ///Readable map skeleton11 template<typename K, typename T>12 class ReadMapSkeleton13 {14 public:15 /// Map valuetype.16 typedef T ValueType;17 /// Map key type.18 typedef K KeyType;13 /// Null map concept 14 template<typename K, typename T> 15 class NullMap 16 { 17 public: 18 /// Map's key type. 19 typedef K KeyType; 20 /// Map's value type. (The type of objects associated with the keys). 21 typedef T ValueType; 19 22 20 ///Default constructor. 21 ReadMapSkeleton() {} 23 /// Facility to define a map with an other value type 24 template<typename T1> 25 struct rebind { 26 /// The type of a map with the given value type 27 typedef NullMap<K,T1> other; 28 }; 29 30 NullMap() {} 31 }; 22 32 23 ///Reads an element of the map. 24 ValueType operator[](const KeyType &i) const {return ValueType();} 25 }; 33 /// Readable map concept 34 template<typename K, typename T> 35 class ReadableMap : public NullMap<K,T> 36 { 37 public: 38 /// Map's key type. 39 typedef K KeyType; 40 /// Map's value type. (The type of objects associated with the keys). 41 typedef T ValueType; 42 43 /// Returns the value associated with a key. 44 ValueType operator[](const KeyType &k) const {return ValueType();} 45 46 /// Copy contsructor. (optional) 47 ReadableMap(const ReadableMap&) {} 48 /// Assignment operator. (optional) 49 ReadableMap& operator=(const ReadableMap&) {return *this;} 50 51 /// Facility to define a map with an other value type (optional) 52 template<typename T1> 53 struct rebind { 54 /// The type of a map with the given value type 55 typedef ReadableMap<K,T1> other; 56 }; 57 /// @brief Constructor that copies all keys from the other map and 58 /// assigns to them a default value (optional) 59 template<typename T1> 60 ReadableMap(const ReadableMap<K,T1> &map, const T1 &v) {} 61 62 ReadableMap() {} 63 }; 26 64 27 65 28 ///Writeable map skeleton29 template<typename K, typename T>30 class WriteMapSkeleton31 {32 public:33 /// Map valuetype.34 typedef T ValueType;35 /// Map key type.36 typedef K KeyType;66 /// Writable map concept 67 template<typename K, typename T> 68 class WritableMap : public NullMap<K,T> 69 { 70 public: 71 /// Map's key type. 72 typedef K KeyType; 73 /// Map's value type. (The type of objects associated with the keys). 74 typedef T ValueType; 37 75 38 ///Default constructor. 39 WriteMapSkeleton() {} 40 ///'Fill with' constructor. 41 WriteMapSkeleton(const ValueType &t) {} 42 43 ///Write an element of a map. 44 void set(const KeyType &i,const ValueType &t) {} 45 }; 76 /// Sets the value associated with a key. 77 void set(const KeyType &k,const ValueType &t) {} 46 78 47 ///Read/Write map skeleton. 48 template<typename K, typename T> 49 class ReadWriteMapSkeleton : public ReadMapSkeleton<K,T>, 50 public WriteMapSkeleton<K,T> 51 { 52 public: 53 ///Default constructor. 54 ReadWriteMapSkeleton() : ReadMapSkeleton(), WriteMapSkeleton() {} 55 ///'Fill with' constructor. 56 ReadWriteMap(const ValueType &t) :ReadMapSkeleton(), WriteMapSkeleton(t) {} 57 }; 79 /// Copy contsructor. (optional) 80 WritableMap(const WritableMap&) {} 81 /// Assignment operator. (optional) 82 WritableMap& operator=(const WritableMap&) {return *this;} 83 84 /// Facility to define a map with an other value type (optional) 85 template<typename T1> 86 struct rebind { 87 /// The type of a map with the given value type 88 typedef WritableMap<K,T1> other; 89 }; 90 /// @brief Constructor that copies all keys from the other map and 91 /// assigns to them a default value (optional) 92 template<typename T1> 93 WritableMap(const WritableMap<K,T1> &map, const T1 &v) {} 94 95 WritableMap() {} 96 }; 97 98 ///Read/Writeable map concept 99 template<typename K, typename T> 100 class ReadWritableMap : public ReadableMap<K,T>, 101 public WritableMap<K,T> 102 { 103 public: 104 /// Map's key type. 105 typedef K KeyType; 106 /// Map's value type. (The type of objects associated with the keys). 107 typedef T ValueType; 108 109 /// Returns the value associated with a key. 110 ValueType operator[](const KeyType &k) const {return ValueType();} 111 /// Sets the value associated with a key. 112 void set(const KeyType &k,const ValueType &t) {} 113 114 /// Copy contsructor. (optional) 115 ReadWritableMap(const ReadWritableMap&) {} 116 /// Assignment operator. (optional) 117 ReadWritableMap& operator=(const ReadWritableMap&) {return *this;} 118 119 /// Facility to define a map with an other value type (optional) 120 template<typename T1> 121 struct rebind { 122 /// The type of a map with the given value type 123 typedef ReadWritableMap<K,T1> other; 124 }; 125 /// @brief Constructor that copies all keys from the other map and 126 /// assigns to them a default value (optional) 127 template<typename T1> 128 ReadWritableMap(const ReadWritableMap<K,T1> &map, const T1 &v) {} 129 130 ReadWritableMap() {} 131 }; 58 132 59 133 60 ///Dereferable map skeleton 61 template<typename K, typename T> 62 class MemoryMapSkeleton : public ReadWriteMapSkeleton<K,T> 63 { 64 public: 65 /// Map value type. 66 typedef T ValueType; 67 /// Map key type. 68 typedef K KeyType; 134 ///Dereferable map concept 135 template<typename K, typename T> 136 class DereferableMap : public ReadWritableMap<K,T> 137 { 138 public: 139 /// Map's key type. 140 typedef K KeyType; 141 /// Map's value type. (The type of objects associated with the keys). 142 typedef T ValueType; 143 /// Map's reference type. (Reference to an object associated with a key) 144 typedef ValueType& ReferenceType; 145 /// Map's const reference type. 146 typedef const ValueType& ConstReferenceType; 69 147 70 ///Default constructor. 71 ReferenceMapSkeleton() : ReadWriteMapSkeleton() {} 72 ///'Fill with' constructor. 73 ReferenceMapSkeleton(const ValueType &t) : ReadWriteMapSkeleton(t) {} 148 ///Returns a reference to the value associated to a key. 149 ReferenceType operator[](const KeyType &i); 150 ///Returns a const reference to the value associated to a key. 151 ConstReferenceType operator[](const KeyType &i) const; 152 /// Sets the value associated with a key. 153 void set(const KeyType &k,const ValueType &t) { operator[](k)=t; } 74 154 75 ///Give a reference to the value belonging to a key. 76 ValueType &operator[](const KeyType &i) {return *(ValueType*)0;} 77 ///Give a const reference to the value belonging to a key. 78 const ValueType &operator[](const KeyType &i) const {return *(T*)0;} 79 }; 155 /// Copy contsructor. (optional) 156 DereferableMap(const DereferableMap&) {} 157 /// Assignment operator. (optional) 158 DereferableMap& operator=(const DereferableMap&) {return *this;} 159 160 /// Facility to define a map with an other value type (optional) 161 template<typename T1> 162 struct rebind { 163 /// The type of a map with the given value type 164 typedef DereferableMap<K,T1> other; 165 }; 166 /// @brief Constructor that copies all keys from the other map and 167 /// assigns to them a default value (optional) 168 template<typename T1> 169 DereferableMap(const DereferableMap<K,T1> &map, const T1 &v) {} 170 171 DereferableMap() {} 172 }; 80 173 81 174 82 175 } 83 176 } 84 177 #endif // HUGO_MAPSKELETON_H
Note: See TracChangeset
for help on using the changeset viewer.