|
1 // -*- c++ -*- |
|
2 #ifndef HUGO_MAPSKELETON_H |
|
3 #define HUGO_MAPSKELETON_H |
|
4 |
|
5 namespace hugo { |
|
6 |
|
7 ///Readable map skeleton |
|
8 template<typename K, typename T> |
|
9 class ReadMapSkeleton |
|
10 { |
|
11 public: |
|
12 /// Map value type. |
|
13 typedef T ValueType; |
|
14 /// Map key type. |
|
15 typedef K KeyType; |
|
16 |
|
17 ///Default constructor. |
|
18 ReadMapSkeleton() {} |
|
19 |
|
20 ///Reads an element of the map. |
|
21 ValueType get(const KeyType &i) const {return ValueType();} |
|
22 }; |
|
23 |
|
24 |
|
25 ///Writeable map skeleton |
|
26 template<typename K, typename T> |
|
27 class WriteMapSkeleton |
|
28 { |
|
29 public: |
|
30 /// Map value type. |
|
31 typedef T ValueType; |
|
32 /// Map key type. |
|
33 typedef K KeyType; |
|
34 |
|
35 ///Default constructor. |
|
36 WriteMapSkeleton() {} |
|
37 ///'Fill with' constructor. |
|
38 WriteMapSkeleton(const ValueType &t) {} |
|
39 |
|
40 ///Write an element of a map. |
|
41 void set(const KeyType &i,const ValueType &t) {} |
|
42 }; |
|
43 |
|
44 ///Read/Write map skeleton. |
|
45 template<typename K, typename T> |
|
46 class ReadWriteMapSkeleton : public ReadMapSkeleton<K,T>, |
|
47 public WriteMapSkeleton<K,T> |
|
48 { |
|
49 public: |
|
50 ///Default constructor. |
|
51 ReadWriteMapSkeleton() : ReadMapSkeleton(), WriteMapSkeleton() {} |
|
52 ///'Fill with' constructor. |
|
53 ReadWriteMap(const ValueType &t) :ReadMapSkeleton(), WriteMapSkeleton(t) {} |
|
54 }; |
|
55 |
|
56 |
|
57 ///Dereferable map skeleton |
|
58 template<typename K, typename T> |
|
59 class MemoryMapSkeleton : public ReadWriteMapSkeleton<K,T> |
|
60 { |
|
61 public: |
|
62 /// Map value type. |
|
63 typedef T ValueType; |
|
64 /// Map key type. |
|
65 typedef K KeyType; |
|
66 |
|
67 ///Default constructor. |
|
68 ReferenceMapSkeleton() : ReadWriteMapSkeleton() {} |
|
69 ///'Fill with' constructor. |
|
70 ReferenceMapSkeleton(const ValueType &t) : ReadWriteMapSkeleton(t) {} |
|
71 |
|
72 ///Give a reference to the value belonging to a key. |
|
73 ValueType &operator[](const KeyType &i) {return *(ValueType*)0;} |
|
74 // const ValueType &operator[](const KeyType &i) const {return *(T*)0;} |
|
75 }; |
|
76 |
|
77 |
|
78 |
|
79 } |
|
80 #endif // HUGO_MAPSKELETON_H |