PageRenderTime 57ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcommon/metapropertyt.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 183 lines | 114 code | 33 blank | 36 comment | 0 complexity | 121102866d1082744594659b451ccf67 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file metapropertyt.h
  3. *
  4. * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2010, Linden Research, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation;
  11. * version 2.1 of the License only.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  23. * $/LicenseInfo$
  24. */
  25. #ifndef LL_METAPROPERTYT_H
  26. #define LL_METAPROPERTYT_H
  27. #include "llsd.h"
  28. #include "llstring.h"
  29. #include "metaclasst.h"
  30. #include "metaproperty.h"
  31. #include "reflectivet.h"
  32. template<class TProperty>
  33. class LLMetaPropertyT : public LLMetaProperty
  34. {
  35. public:
  36. virtual ~LLMetaPropertyT() {;}
  37. // Get value of this property. Gives ownership of returned value.
  38. virtual const LLReflective* get(const LLReflective* object) const
  39. {
  40. checkObjectClass(object);
  41. return getProperty(object);
  42. }
  43. // Set value of this property.
  44. /*virtual void set(LLReflective* object, const LLReflective* value)
  45. {
  46. // TODO: Babbage: Check types.
  47. ref(object) = static_cast<const LLReflectiveT<TProperty>* >(value)->getValue();
  48. }*/
  49. // Get value of this property as LLSD.
  50. virtual LLSD getLLSD(const LLReflective* object) const
  51. {
  52. return LLSD();
  53. }
  54. protected:
  55. LLMetaPropertyT(const std::string& name, const LLMetaClass& object_class) : LLMetaProperty(name, object_class) {;}
  56. virtual const TProperty* getProperty(const LLReflective* object) const = 0;
  57. };
  58. template <>
  59. inline const LLReflective* LLMetaPropertyT<S32>::get(const LLReflective* object) const
  60. {
  61. checkObjectClass(object);
  62. return NULL;
  63. }
  64. template <>
  65. inline const LLReflective* LLMetaPropertyT<std::string>::get(const LLReflective* object) const
  66. {
  67. checkObjectClass(object);
  68. return NULL;
  69. }
  70. template <>
  71. inline const LLReflective* LLMetaPropertyT<LLUUID>::get(const LLReflective* object) const
  72. {
  73. checkObjectClass(object);
  74. return NULL;
  75. }
  76. template <>
  77. inline const LLReflective* LLMetaPropertyT<bool>::get(const LLReflective* object) const
  78. {
  79. checkObjectClass(object);
  80. return NULL;
  81. }
  82. template <>
  83. inline LLSD LLMetaPropertyT<S32>::getLLSD(const LLReflective* object) const
  84. {
  85. return *(getProperty(object));
  86. }
  87. template <>
  88. inline LLSD LLMetaPropertyT<std::string>::getLLSD(const LLReflective* object) const
  89. {
  90. return *(getProperty(object));
  91. }
  92. template <>
  93. inline LLSD LLMetaPropertyT<LLUUID>::getLLSD(const LLReflective* object) const
  94. {
  95. return *(getProperty(object));
  96. }
  97. template <>
  98. inline LLSD LLMetaPropertyT<bool>::getLLSD(const LLReflective* object) const
  99. {
  100. return *(getProperty(object));
  101. }
  102. template<class TObject, class TProperty>
  103. class LLMetaPropertyTT : public LLMetaPropertyT<TProperty>
  104. {
  105. public:
  106. LLMetaPropertyTT(const std::string& name, const LLMetaClass& object_class, TProperty (TObject::*property)) :
  107. LLMetaPropertyT<TProperty>(name, object_class), mProperty(property) {;}
  108. protected:
  109. // Get void* to property.
  110. virtual const TProperty* getProperty(const LLReflective* object) const
  111. {
  112. const TObject* typed_object = static_cast<const TObject*>(object);
  113. return &(typed_object->*mProperty);
  114. };
  115. private:
  116. TProperty (TObject::*mProperty);
  117. };
  118. template<class TObject, class TProperty>
  119. class LLMetaPropertyPtrTT : public LLMetaPropertyT<TProperty>
  120. {
  121. public:
  122. LLMetaPropertyPtrTT(const std::string& name, const LLMetaClass& object_class, TProperty* (TObject::*property)) :
  123. LLMetaPropertyT<TProperty>(name, object_class), mProperty(property) {;}
  124. protected:
  125. // Get void* to property.
  126. virtual const TProperty* getProperty(const LLReflective* object) const
  127. {
  128. const TObject* typed_object = static_cast<const TObject*>(object);
  129. return typed_object->*mProperty;
  130. };
  131. private:
  132. TProperty* (TObject::*mProperty);
  133. };
  134. // Utility function to simplify the registration of members.
  135. template<class TObject, class TProperty>
  136. void reflectProperty(LLMetaClass& meta_class, const std::string& name, TProperty (TObject::*property))
  137. {
  138. typedef LLMetaPropertyTT<TObject, TProperty> PropertyType;
  139. const LLMetaProperty* meta_property = new PropertyType(name, meta_class, property);
  140. meta_class.addProperty(meta_property);
  141. }
  142. // Utility function to simplify the registration of ptr properties.
  143. template<class TObject, class TProperty>
  144. void reflectPtrProperty(LLMetaClass& meta_class, const std::string& name, TProperty* (TObject::*property))
  145. {
  146. typedef LLMetaPropertyPtrTT<TObject, TProperty> PropertyType;
  147. const LLMetaProperty* meta_property = new PropertyType(name, meta_class, property);
  148. meta_class.addProperty(meta_property);
  149. }
  150. #endif // LL_METAPROPERTYT_H