summaryrefslogtreecommitdiff
path: root/indra/test/llsdtraits.h
diff options
context:
space:
mode:
authorDon Kjer <don@lindenlab.com>2007-05-01 21:39:25 +0000
committerDon Kjer <don@lindenlab.com>2007-05-01 21:39:25 +0000
commit4ecb9cb63e4993b3b4bc65d73ed255139b5c3f75 (patch)
tree48d9bb9a1ae468ecdbd53cf21a598d66ee8eced3 /indra/test/llsdtraits.h
parentf5e9ce7e47694e349a4eb28b052016b11e1bdf81 (diff)
svn merge -r 59163:61099 svn+ssh://svn/svn/linden/branches/release-candidate into release
Diffstat (limited to 'indra/test/llsdtraits.h')
-rw-r--r--indra/test/llsdtraits.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/indra/test/llsdtraits.h b/indra/test/llsdtraits.h
new file mode 100644
index 0000000000..2e6a96a425
--- /dev/null
+++ b/indra/test/llsdtraits.h
@@ -0,0 +1,78 @@
+#ifndef LLSDTRAITS_H
+#define LLSDTRAITS_H
+
+#include "llsd.h"
+#include "llstring.h"
+
+template<class T>
+class LLSDTraits
+{
+ protected:
+ typedef T (LLSD::*Getter)() const;
+
+ LLSD::Type type;
+ Getter getter;
+
+ public:
+ LLSDTraits();
+
+ T get(const LLSD& actual)
+ {
+ return (actual.*getter)();
+ }
+
+ bool checkType(const LLSD& actual)
+ {
+ return actual.type() == type;
+ }
+};
+
+template<> inline
+LLSDTraits<LLSD::Boolean>::LLSDTraits()
+ : type(LLSD::TypeBoolean), getter(&LLSD::asBoolean)
+{ }
+
+template<> inline
+LLSDTraits<LLSD::Integer>::LLSDTraits()
+ : type(LLSD::TypeInteger), getter(&LLSD::asInteger)
+{ }
+
+template<> inline
+LLSDTraits<LLSD::Real>::LLSDTraits()
+ : type(LLSD::TypeReal), getter(&LLSD::asReal)
+{ }
+
+template<> inline
+LLSDTraits<LLSD::UUID>::LLSDTraits()
+ : type(LLSD::TypeUUID), getter(&LLSD::asUUID)
+{ }
+
+template<> inline
+LLSDTraits<LLSD::String>::LLSDTraits()
+ : type(LLSD::TypeString), getter(&LLSD::asString)
+{ }
+
+template<>
+class LLSDTraits<LLString> : public LLSDTraits<LLSD::String>
+{ };
+
+template<>
+class LLSDTraits<const char*> : public LLSDTraits<LLSD::String>
+{ };
+
+template<> inline
+LLSDTraits<LLSD::Date>::LLSDTraits()
+ : type(LLSD::TypeDate), getter(&LLSD::asDate)
+{ }
+
+template<> inline
+LLSDTraits<LLSD::URI>::LLSDTraits()
+ : type(LLSD::TypeURI), getter(&LLSD::asURI)
+{ }
+
+template<> inline
+LLSDTraits<LLSD::Binary>::LLSDTraits()
+ : type(LLSD::TypeBinary), getter(&LLSD::asBinary)
+{ }
+
+#endif // LLSDTRAITS_H