aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/test/llsdtraits.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/test/llsdtraits.h')
-rw-r--r--linden/indra/test/llsdtraits.h78
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
7template<class T>
8class 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
30template<> inline
31LLSDTraits<LLSD::Boolean>::LLSDTraits()
32 : type(LLSD::TypeBoolean), getter(&LLSD::asBoolean)
33{ }
34
35template<> inline
36LLSDTraits<LLSD::Integer>::LLSDTraits()
37 : type(LLSD::TypeInteger), getter(&LLSD::asInteger)
38{ }
39
40template<> inline
41LLSDTraits<LLSD::Real>::LLSDTraits()
42 : type(LLSD::TypeReal), getter(&LLSD::asReal)
43{ }
44
45template<> inline
46LLSDTraits<LLSD::UUID>::LLSDTraits()
47 : type(LLSD::TypeUUID), getter(&LLSD::asUUID)
48{ }
49
50template<> inline
51LLSDTraits<LLSD::String>::LLSDTraits()
52 : type(LLSD::TypeString), getter(&LLSD::asString)
53{ }
54
55template<>
56class LLSDTraits<LLString> : public LLSDTraits<LLSD::String>
57{ };
58
59template<>
60class LLSDTraits<const char*> : public LLSDTraits<LLSD::String>
61{ };
62
63template<> inline
64LLSDTraits<LLSD::Date>::LLSDTraits()
65 : type(LLSD::TypeDate), getter(&LLSD::asDate)
66{ }
67
68template<> inline
69LLSDTraits<LLSD::URI>::LLSDTraits()
70 : type(LLSD::TypeURI), getter(&LLSD::asURI)
71{ }
72
73template<> inline
74LLSDTraits<LLSD::Binary>::LLSDTraits()
75 : type(LLSD::TypeBinary), getter(&LLSD::asBinary)
76{ }
77
78#endif // LLSDTRAITS_H