PageRenderTime 36ms CodeModel.GetById 20ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LLSDTRAITS_H
  27. #define LLSDTRAITS_H
  28. #include "llsd.h"
  29. #include "llstring.h"
  30. template<class T>
  31. class LLSDTraits
  32. {
  33. protected:
  34. typedef T (LLSD::*Getter)() const;
  35. LLSD::Type type;
  36. Getter getter;
  37. public:
  38. LLSDTraits();
  39. T get(const LLSD& actual)
  40. {
  41. return (actual.*getter)();
  42. }
  43. bool checkType(const LLSD& actual)
  44. {
  45. return actual.type() == type;
  46. }
  47. };
  48. template<> inline
  49. LLSDTraits<LLSD::Boolean>::LLSDTraits()
  50. : type(LLSD::TypeBoolean), getter(&LLSD::asBoolean)
  51. { }
  52. template<> inline
  53. LLSDTraits<LLSD::Integer>::LLSDTraits()
  54. : type(LLSD::TypeInteger), getter(&LLSD::asInteger)
  55. { }
  56. template<> inline
  57. LLSDTraits<LLSD::Real>::LLSDTraits()
  58. : type(LLSD::TypeReal), getter(&LLSD::asReal)
  59. { }
  60. template<> inline
  61. LLSDTraits<LLSD::UUID>::LLSDTraits()
  62. : type(LLSD::TypeUUID), getter(&LLSD::asUUID)
  63. { }
  64. template<> inline
  65. LLSDTraits<LLSD::String>::LLSDTraits()
  66. : type(LLSD::TypeString), getter(&LLSD::asString)
  67. { }
  68. template<>
  69. class LLSDTraits<const char*> : public LLSDTraits<LLSD::String>
  70. { };
  71. template<> inline
  72. LLSDTraits<LLSD::Date>::LLSDTraits()
  73. : type(LLSD::TypeDate), getter(&LLSD::asDate)
  74. { }
  75. template<> inline
  76. LLSDTraits<LLSD::URI>::LLSDTraits()
  77. : type(LLSD::TypeURI), getter(&LLSD::asURI)
  78. { }
  79. template<> inline
  80. LLSDTraits<LLSD::Binary>::LLSDTraits()
  81. : type(LLSD::TypeBinary), getter(&LLSD::asBinary)
  82. { }
  83. #endif // LLSDTRAITS_H