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