metapropertyt.h

Go to the documentation of this file.
00001 
00031 #ifndef LL_METAPROPERTYT_H
00032 #define LL_METAPROPERTYT_H
00033 
00034 #include "llsd.h"
00035 #include "llstring.h"
00036 #include "metaclasst.h"
00037 #include "metaproperty.h"
00038 #include "reflectivet.h"
00039 
00040 template<class TProperty>
00041 class LLMetaPropertyT : public LLMetaProperty
00042 {
00043 public:
00044         
00045         virtual ~LLMetaPropertyT() {;}
00046         
00047         // Get value of this property. Gives ownership of returned value.
00048         virtual const LLReflective* get(const LLReflective* object) const
00049         {
00050                 checkObjectClass(object);
00051                 return getProperty(object);
00052         }
00053   
00054         // Set value of this property.
00055         /*virtual void set(LLReflective* object, const LLReflective* value)
00056         {
00057                 // TODO: Babbage: Check types.
00058                 ref(object) = static_cast<const LLReflectiveT<TProperty>* >(value)->getValue();
00059         }*/
00060         
00061         // Get value of this property as LLSD.
00062         virtual LLSD getLLSD(const LLReflective* object) const
00063         {
00064                 return LLSD();
00065         }
00066 
00067 protected:
00068 
00069         LLMetaPropertyT(const std::string& name, const LLMetaClass& object_class) : LLMetaProperty(name, object_class) {;}
00070 
00071         virtual const TProperty* getProperty(const LLReflective* object) const = 0;
00072 };
00073 
00074 template <>
00075 inline const LLReflective* LLMetaPropertyT<S32>::get(const LLReflective* object) const
00076 {
00077         checkObjectClass(object);
00078         return NULL;
00079 }
00080 
00081 template <>
00082 inline const LLReflective* LLMetaPropertyT<std::string>::get(const LLReflective* object) const
00083 {
00084         checkObjectClass(object);
00085         return NULL;
00086 }
00087 
00088 template <>
00089 inline const LLReflective* LLMetaPropertyT<LLString>::get(const LLReflective* object) const
00090 {
00091         checkObjectClass(object);
00092         return NULL;
00093 }
00094 
00095 template <>
00096 inline const LLReflective* LLMetaPropertyT<LLUUID>::get(const LLReflective* object) const
00097 {
00098         checkObjectClass(object);
00099         return NULL;
00100 }
00101 
00102 template <>
00103 inline LLSD LLMetaPropertyT<S32>::getLLSD(const LLReflective* object) const
00104 {
00105         return *(getProperty(object));
00106 }
00107 
00108 template <>
00109 inline LLSD LLMetaPropertyT<std::string>::getLLSD(const LLReflective* object) const
00110 {
00111         return *(getProperty(object));
00112 }
00113 
00114 template <>
00115 inline LLSD LLMetaPropertyT<LLString>::getLLSD(const LLReflective* object) const
00116 {
00117         return *(getProperty(object));
00118 }
00119 
00120 template <>
00121 inline LLSD LLMetaPropertyT<LLUUID>::getLLSD(const LLReflective* object) const
00122 {
00123         return *(getProperty(object));
00124 }
00125 
00126 template<class TObject, class TProperty>
00127 class LLMetaPropertyTT : public LLMetaPropertyT<TProperty>
00128 {
00129 public:
00130 
00131         LLMetaPropertyTT(const std::string& name, const LLMetaClass& object_class, TProperty (TObject::*property)) : 
00132           LLMetaPropertyT<TProperty>(name, object_class), mProperty(property) {;}
00133 
00134 protected:
00135 
00136         // Get void* to property.
00137         virtual const TProperty* getProperty(const LLReflective* object) const
00138         {
00139                 const TObject* typed_object = static_cast<const TObject*>(object);
00140                 return &(typed_object->*mProperty);
00141         };
00142 
00143 private:
00144 
00145         TProperty (TObject::*mProperty);
00146 };
00147 
00148 template<class TObject, class TProperty>
00149 class LLMetaPropertyPtrTT : public LLMetaPropertyT<TProperty>
00150 {
00151 public:
00152 
00153         LLMetaPropertyPtrTT(const std::string& name, const LLMetaClass& object_class, TProperty* (TObject::*property)) : 
00154           LLMetaPropertyT<TProperty>(name, object_class), mProperty(property) {;}
00155 
00156 protected:
00157 
00158         // Get void* to property.
00159         virtual const TProperty* getProperty(const LLReflective* object) const
00160         {
00161                 const TObject* typed_object = static_cast<const TObject*>(object);
00162                 return typed_object->*mProperty;
00163         };
00164 
00165 private:
00166 
00167         TProperty* (TObject::*mProperty);
00168 };
00169 
00170 // Utility function to simplify the registration of members.
00171 template<class TObject, class TProperty>
00172 void reflectProperty(LLMetaClass& meta_class, const std::string& name, TProperty (TObject::*property))
00173 {
00174         typedef LLMetaPropertyTT<TObject, TProperty> PropertyType;
00175         const LLMetaProperty* meta_property = new PropertyType(name, meta_class, property);
00176         meta_class.addProperty(meta_property);
00177 }
00178 
00179 // Utility function to simplify the registration of ptr properties.
00180 template<class TObject, class TProperty>
00181 void reflectPtrProperty(LLMetaClass& meta_class, const std::string& name, TProperty* (TObject::*property))
00182 {
00183         typedef LLMetaPropertyPtrTT<TObject, TProperty> PropertyType;
00184         const LLMetaProperty* meta_property = new PropertyType(name, meta_class, property);
00185         meta_class.addProperty(meta_property);
00186 }
00187 
00188 #endif // LL_METAPROPERTYT_H

Generated on Thu Jul 1 06:09:56 2010 for Second Life Viewer by  doxygen 1.4.7