diff options
Diffstat (limited to 'linden/indra/test/llsdtraits.h')
-rw-r--r-- | linden/indra/test/llsdtraits.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/linden/indra/test/llsdtraits.h b/linden/indra/test/llsdtraits.h new file mode 100644 index 0000000..2e6a96a --- /dev/null +++ b/linden/indra/test/llsdtraits.h | |||
@@ -0,0 +1,78 @@ | |||
1 | #ifndef LLSDTRAITS_H | ||
2 | #define LLSDTRAITS_H | ||
3 | |||
4 | #include "llsd.h" | ||
5 | #include "llstring.h" | ||
6 | |||
7 | template<class T> | ||
8 | class LLSDTraits | ||
9 | { | ||
10 | protected: | ||
11 | typedef T (LLSD::*Getter)() const; | ||
12 | |||
13 | LLSD::Type type; | ||
14 | Getter getter; | ||
15 | |||
16 | public: | ||
17 | LLSDTraits(); | ||
18 | |||
19 | T get(const LLSD& actual) | ||
20 | { | ||
21 | return (actual.*getter)(); | ||
22 | } | ||
23 | |||
24 | bool checkType(const LLSD& actual) | ||
25 | { | ||
26 | return actual.type() == type; | ||
27 | } | ||
28 | }; | ||
29 | |||
30 | template<> inline | ||
31 | LLSDTraits<LLSD::Boolean>::LLSDTraits() | ||
32 | : type(LLSD::TypeBoolean), getter(&LLSD::asBoolean) | ||
33 | { } | ||
34 | |||
35 | template<> inline | ||
36 | LLSDTraits<LLSD::Integer>::LLSDTraits() | ||
37 | : type(LLSD::TypeInteger), getter(&LLSD::asInteger) | ||
38 | { } | ||
39 | |||
40 | template<> inline | ||
41 | LLSDTraits<LLSD::Real>::LLSDTraits() | ||
42 | : type(LLSD::TypeReal), getter(&LLSD::asReal) | ||
43 | { } | ||
44 | |||
45 | template<> inline | ||
46 | LLSDTraits<LLSD::UUID>::LLSDTraits() | ||
47 | : type(LLSD::TypeUUID), getter(&LLSD::asUUID) | ||
48 | { } | ||
49 | |||
50 | template<> inline | ||
51 | LLSDTraits<LLSD::String>::LLSDTraits() | ||
52 | : type(LLSD::TypeString), getter(&LLSD::asString) | ||
53 | { } | ||
54 | |||
55 | template<> | ||
56 | class LLSDTraits<LLString> : public LLSDTraits<LLSD::String> | ||
57 | { }; | ||
58 | |||
59 | template<> | ||
60 | class LLSDTraits<const char*> : public LLSDTraits<LLSD::String> | ||
61 | { }; | ||
62 | |||
63 | template<> inline | ||
64 | LLSDTraits<LLSD::Date>::LLSDTraits() | ||
65 | : type(LLSD::TypeDate), getter(&LLSD::asDate) | ||
66 | { } | ||
67 | |||
68 | template<> inline | ||
69 | LLSDTraits<LLSD::URI>::LLSDTraits() | ||
70 | : type(LLSD::TypeURI), getter(&LLSD::asURI) | ||
71 | { } | ||
72 | |||
73 | template<> inline | ||
74 | LLSDTraits<LLSD::Binary>::LLSDTraits() | ||
75 | : type(LLSD::TypeBinary), getter(&LLSD::asBinary) | ||
76 | { } | ||
77 | |||
78 | #endif // LLSDTRAITS_H | ||