PageRenderTime 21ms CodeModel.GetById 11ms app.highlight 7ms RepoModel.GetById 1ms 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
  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
 26#ifndef LL_METAPROPERTYT_H
 27#define LL_METAPROPERTYT_H
 28
 29#include "llsd.h"
 30#include "llstring.h"
 31#include "metaclasst.h"
 32#include "metaproperty.h"
 33#include "reflectivet.h"
 34
 35template<class TProperty>
 36class LLMetaPropertyT : public LLMetaProperty
 37{
 38public:
 39	
 40	virtual ~LLMetaPropertyT() {;}
 41	
 42	// Get value of this property. Gives ownership of returned value.
 43	virtual const LLReflective* get(const LLReflective* object) const
 44	{
 45		checkObjectClass(object);
 46		return getProperty(object);
 47	}
 48  
 49	// Set value of this property.
 50	/*virtual void set(LLReflective* object, const LLReflective* value)
 51	{
 52		// TODO: Babbage: Check types.
 53		ref(object) = static_cast<const LLReflectiveT<TProperty>* >(value)->getValue();
 54	}*/
 55	
 56	// Get value of this property as LLSD.
 57	virtual LLSD getLLSD(const LLReflective* object) const
 58	{
 59		return LLSD();
 60	}
 61
 62protected:
 63
 64	LLMetaPropertyT(const std::string& name, const LLMetaClass& object_class) : LLMetaProperty(name, object_class) {;}
 65
 66	virtual const TProperty* getProperty(const LLReflective* object) const = 0;
 67};
 68
 69template <>
 70inline const LLReflective* LLMetaPropertyT<S32>::get(const LLReflective* object) const
 71{
 72	checkObjectClass(object);
 73	return NULL;
 74}
 75
 76template <>
 77inline const LLReflective* LLMetaPropertyT<std::string>::get(const LLReflective* object) const
 78{
 79	checkObjectClass(object);
 80	return NULL;
 81}
 82
 83template <>
 84inline const LLReflective* LLMetaPropertyT<LLUUID>::get(const LLReflective* object) const
 85{
 86	checkObjectClass(object);
 87	return NULL;
 88}
 89
 90template <>
 91inline const LLReflective* LLMetaPropertyT<bool>::get(const LLReflective* object) const
 92{
 93	checkObjectClass(object);
 94	return NULL;
 95}
 96
 97template <>
 98inline LLSD LLMetaPropertyT<S32>::getLLSD(const LLReflective* object) const
 99{
100	return *(getProperty(object));
101}
102
103template <>
104inline LLSD LLMetaPropertyT<std::string>::getLLSD(const LLReflective* object) const
105{
106	return *(getProperty(object));
107}
108
109template <>
110inline LLSD LLMetaPropertyT<LLUUID>::getLLSD(const LLReflective* object) const
111{
112	return *(getProperty(object));
113}
114
115template <>
116inline LLSD LLMetaPropertyT<bool>::getLLSD(const LLReflective* object) const
117{
118	return *(getProperty(object));
119}
120
121template<class TObject, class TProperty>
122class LLMetaPropertyTT : public LLMetaPropertyT<TProperty>
123{
124public:
125
126	LLMetaPropertyTT(const std::string& name, const LLMetaClass& object_class, TProperty (TObject::*property)) : 
127	  LLMetaPropertyT<TProperty>(name, object_class), mProperty(property) {;}
128
129protected:
130
131	// Get void* to property.
132	virtual const TProperty* getProperty(const LLReflective* object) const
133	{
134		const TObject* typed_object = static_cast<const TObject*>(object);
135		return &(typed_object->*mProperty);
136	};
137
138private:
139
140	TProperty (TObject::*mProperty);
141};
142
143template<class TObject, class TProperty>
144class LLMetaPropertyPtrTT : public LLMetaPropertyT<TProperty>
145{
146public:
147
148	LLMetaPropertyPtrTT(const std::string& name, const LLMetaClass& object_class, TProperty* (TObject::*property)) : 
149	  LLMetaPropertyT<TProperty>(name, object_class), mProperty(property) {;}
150
151protected:
152
153	// Get void* to property.
154	virtual const TProperty* getProperty(const LLReflective* object) const
155	{
156		const TObject* typed_object = static_cast<const TObject*>(object);
157		return typed_object->*mProperty;
158	};
159
160private:
161
162	TProperty* (TObject::*mProperty);
163};
164
165// Utility function to simplify the registration of members.
166template<class TObject, class TProperty>
167void reflectProperty(LLMetaClass& meta_class, const std::string& name, TProperty (TObject::*property))
168{
169	typedef LLMetaPropertyTT<TObject, TProperty> PropertyType;
170	const LLMetaProperty* meta_property = new PropertyType(name, meta_class, property);
171	meta_class.addProperty(meta_property);
172}
173
174// Utility function to simplify the registration of ptr properties.
175template<class TObject, class TProperty>
176void reflectPtrProperty(LLMetaClass& meta_class, const std::string& name, TProperty* (TObject::*property))
177{
178	typedef LLMetaPropertyPtrTT<TObject, TProperty> PropertyType;
179	const LLMetaProperty* meta_property = new PropertyType(name, meta_class, property);
180	meta_class.addProperty(meta_property);
181}
182
183#endif // LL_METAPROPERTYT_H