PageRenderTime 17ms CodeModel.GetById 1ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/test/llsdtraits.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 100 lines | 58 code | 17 blank | 25 comment | 1 complexity | 0ed1e034ca9b26e3afc89c8724653d95 MD5 | raw file
  1/**
  2 * @file llsdtraits.h
  3 * @brief Unit test helpers
  4 *
  5 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LLSDTRAITS_H
 28#define LLSDTRAITS_H
 29
 30#include "llsd.h"
 31#include "llstring.h"
 32
 33template<class T>
 34class LLSDTraits
 35{
 36 protected:
 37	typedef T (LLSD::*Getter)() const;
 38	
 39	LLSD::Type type;
 40	Getter getter;
 41	
 42 public:
 43	LLSDTraits();
 44	
 45	T get(const LLSD& actual)
 46		{
 47			return (actual.*getter)();
 48		}
 49	
 50	bool checkType(const LLSD& actual)
 51		{
 52			return actual.type() == type;
 53		}
 54};
 55
 56template<> inline
 57LLSDTraits<LLSD::Boolean>::LLSDTraits()
 58	: type(LLSD::TypeBoolean), getter(&LLSD::asBoolean)
 59{ }
 60
 61template<> inline
 62LLSDTraits<LLSD::Integer>::LLSDTraits()
 63	: type(LLSD::TypeInteger), getter(&LLSD::asInteger)
 64{ }
 65
 66template<> inline
 67LLSDTraits<LLSD::Real>::LLSDTraits()
 68	: type(LLSD::TypeReal), getter(&LLSD::asReal)
 69{ }
 70
 71template<> inline
 72LLSDTraits<LLSD::UUID>::LLSDTraits()
 73	: type(LLSD::TypeUUID), getter(&LLSD::asUUID)
 74{ }
 75
 76template<> inline
 77LLSDTraits<LLSD::String>::LLSDTraits()
 78	: type(LLSD::TypeString), getter(&LLSD::asString)
 79{ }
 80
 81template<>
 82class LLSDTraits<const char*> : public LLSDTraits<LLSD::String>
 83{ };
 84
 85template<> inline
 86LLSDTraits<LLSD::Date>::LLSDTraits()
 87	: type(LLSD::TypeDate), getter(&LLSD::asDate)
 88{ }
 89
 90template<> inline
 91LLSDTraits<LLSD::URI>::LLSDTraits()
 92	: type(LLSD::TypeURI), getter(&LLSD::asURI)
 93{ }
 94
 95template<> inline
 96LLSDTraits<LLSD::Binary>::LLSDTraits()
 97	: type(LLSD::TypeBinary), getter(&LLSD::asBinary)
 98{ }
 99
100#endif // LLSDTRAITS_H