From b2afb8800bb033a04bb3ecdf0363068d56648ef1 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:44:54 -0500 Subject: Second Life viewer sources 1.15.0.2 --- linden/indra/test/llsdtraits.h | 78 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 linden/indra/test/llsdtraits.h (limited to 'linden/indra/test/llsdtraits.h') 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 @@ +#ifndef LLSDTRAITS_H +#define LLSDTRAITS_H + +#include "llsd.h" +#include "llstring.h" + +template +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::LLSDTraits() + : type(LLSD::TypeBoolean), getter(&LLSD::asBoolean) +{ } + +template<> inline +LLSDTraits::LLSDTraits() + : type(LLSD::TypeInteger), getter(&LLSD::asInteger) +{ } + +template<> inline +LLSDTraits::LLSDTraits() + : type(LLSD::TypeReal), getter(&LLSD::asReal) +{ } + +template<> inline +LLSDTraits::LLSDTraits() + : type(LLSD::TypeUUID), getter(&LLSD::asUUID) +{ } + +template<> inline +LLSDTraits::LLSDTraits() + : type(LLSD::TypeString), getter(&LLSD::asString) +{ } + +template<> +class LLSDTraits : public LLSDTraits +{ }; + +template<> +class LLSDTraits : public LLSDTraits +{ }; + +template<> inline +LLSDTraits::LLSDTraits() + : type(LLSD::TypeDate), getter(&LLSD::asDate) +{ } + +template<> inline +LLSDTraits::LLSDTraits() + : type(LLSD::TypeURI), getter(&LLSD::asURI) +{ } + +template<> inline +LLSDTraits::LLSDTraits() + : type(LLSD::TypeBinary), getter(&LLSD::asBinary) +{ } + +#endif // LLSDTRAITS_H -- cgit v1.1