4 |
4 |
5 ///\file |
5 ///\file |
6 ///\brief Map concepts checking classes for testing and documenting. |
6 ///\brief Map concepts checking classes for testing and documenting. |
7 |
7 |
8 namespace hugo { |
8 namespace hugo { |
|
9 |
|
10 /// The namespace of HUGOlib concepts and concept checking classes |
|
11 namespace skeleton { |
9 |
12 |
10 ///Readable map skeleton |
13 /// Null map concept |
11 template<typename K, typename T> |
14 template<typename K, typename T> |
12 class ReadMapSkeleton |
15 class NullMap |
13 { |
16 { |
14 public: |
17 public: |
15 /// Map value type. |
18 /// Map's key type. |
16 typedef T ValueType; |
19 typedef K KeyType; |
17 /// Map key type. |
20 /// Map's value type. (The type of objects associated with the keys). |
18 typedef K KeyType; |
21 typedef T ValueType; |
19 |
22 |
20 ///Default constructor. |
23 /// Facility to define a map with an other value type |
21 ReadMapSkeleton() {} |
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. |
33 /// Readable map concept |
24 ValueType operator[](const KeyType &i) const {return ValueType();} |
34 template<typename K, typename T> |
25 }; |
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 skeleton |
66 /// Writable map concept |
29 template<typename K, typename T> |
67 template<typename K, typename T> |
30 class WriteMapSkeleton |
68 class WritableMap : public NullMap<K,T> |
31 { |
69 { |
32 public: |
70 public: |
33 /// Map value type. |
71 /// Map's key type. |
34 typedef T ValueType; |
72 typedef K KeyType; |
35 /// Map key type. |
73 /// Map's value type. (The type of objects associated with the keys). |
36 typedef K KeyType; |
74 typedef T ValueType; |
37 |
75 |
38 ///Default constructor. |
76 /// Sets the value associated with a key. |
39 WriteMapSkeleton() {} |
77 void set(const KeyType &k,const ValueType &t) {} |
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 }; |
|
46 |
78 |
47 ///Read/Write map skeleton. |
79 /// Copy contsructor. (optional) |
48 template<typename K, typename T> |
80 WritableMap(const WritableMap&) {} |
49 class ReadWriteMapSkeleton : public ReadMapSkeleton<K,T>, |
81 /// Assignment operator. (optional) |
50 public WriteMapSkeleton<K,T> |
82 WritableMap& operator=(const WritableMap&) {return *this;} |
51 { |
83 |
52 public: |
84 /// Facility to define a map with an other value type (optional) |
53 ///Default constructor. |
85 template<typename T1> |
54 ReadWriteMapSkeleton() : ReadMapSkeleton(), WriteMapSkeleton() {} |
86 struct rebind { |
55 ///'Fill with' constructor. |
87 /// The type of a map with the given value type |
56 ReadWriteMap(const ValueType &t) :ReadMapSkeleton(), WriteMapSkeleton(t) {} |
88 typedef WritableMap<K,T1> other; |
57 }; |
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 |
134 ///Dereferable map concept |
61 template<typename K, typename T> |
135 template<typename K, typename T> |
62 class MemoryMapSkeleton : public ReadWriteMapSkeleton<K,T> |
136 class DereferableMap : public ReadWritableMap<K,T> |
63 { |
137 { |
64 public: |
138 public: |
65 /// Map value type. |
139 /// Map's key type. |
66 typedef T ValueType; |
140 typedef K KeyType; |
67 /// Map key type. |
141 /// Map's value type. (The type of objects associated with the keys). |
68 typedef K KeyType; |
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. |
148 ///Returns a reference to the value associated to a key. |
71 ReferenceMapSkeleton() : ReadWriteMapSkeleton() {} |
149 ReferenceType operator[](const KeyType &i); |
72 ///'Fill with' constructor. |
150 ///Returns a const reference to the value associated to a key. |
73 ReferenceMapSkeleton(const ValueType &t) : ReadWriteMapSkeleton(t) {} |
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. |
155 /// Copy contsructor. (optional) |
76 ValueType &operator[](const KeyType &i) {return *(ValueType*)0;} |
156 DereferableMap(const DereferableMap&) {} |
77 ///Give a const reference to the value belonging to a key. |
157 /// Assignment operator. (optional) |
78 const ValueType &operator[](const KeyType &i) const {return *(T*)0;} |
158 DereferableMap& operator=(const DereferableMap&) {return *this;} |
79 }; |
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 #endif // HUGO_MAPSKELETON_H |
177 #endif // HUGO_MAPSKELETON_H |