00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef CAELUM__TYPE_DESCRIPTOR_H
00022 #define CAELUM__TYPE_DESCRIPTOR_H
00023
00024 #include "CaelumPrerequisites.h"
00025
00026 #if CAELUM_TYPE_DESCRIPTORS
00027
00028 #include <typeinfo>
00029
00030 namespace Caelum
00031 {
00032 class ValuePropertyDescriptor;
00033
00048 class CAELUM_EXPORT TypeDescriptor
00049 {
00050 public:
00051 typedef std::map<String, const ValuePropertyDescriptor*> PropertyMap;
00052
00057 virtual const ValuePropertyDescriptor* getPropertyDescriptor (const Ogre::String& name) const = 0;
00058
00062 virtual const std::vector<String> getPropertyNames () const = 0;
00063
00067 virtual const PropertyMap getFullPropertyMap () const = 0;
00068 };
00069
00081 class CAELUM_EXPORT ValuePropertyDescriptor
00082 {
00083 public:
00090 virtual bool canGetValue () const = 0;
00091
00093 virtual bool canSetValue () const = 0;
00094
00100 virtual const Ogre::Any getValue (const void* target) const = 0;
00101
00107 virtual void setValue (void* target, const Ogre::Any& value) const = 0;
00108
00110 virtual const std::type_info& getValueTypeId () const = 0;
00111
00118 virtual bool implementsTypedValuePropertyDescriptor () const {
00119 return false;
00120 }
00121 };
00122
00125 template<typename ValueT>
00126 class CAELUM_EXPORT TypedValuePropertyDescriptor: public ValuePropertyDescriptor
00127 {
00128 public:
00130 virtual const ValueT getValueTyped (const void* target) const = 0;
00132 virtual void setValueTyped (void* target, const ValueT& value) const = 0;
00133
00134 private:
00135 virtual const Ogre::Any getValue (const void* target) const {
00136 return Ogre::Any(this->getValueTyped (target));
00137 }
00138
00139 virtual void setValue (void* target, const Ogre::Any& value) const {
00140 this->setValueTyped (target, Ogre::any_cast<ValueT>(value));
00141 }
00142
00143 virtual const std::type_info& getValueTypeId () const {
00144 return typeid(ValueT);
00145 }
00146
00147 virtual bool implementsTypedValuePropertyDescriptor () const {
00148 return true;
00149 }
00150 };
00151
00154 template <class TargetT, typename ParamT, typename InParamT = const ParamT&, typename OutParamT = const ParamT>
00155 class AccesorPropertyDescriptor: public TypedValuePropertyDescriptor<ParamT>
00156 {
00157 public:
00158 typedef void(TargetT::*SetFunc)(InParamT);
00159 typedef OutParamT(TargetT::*GetFunc)(void) const;
00160
00161 private:
00162 GetFunc mGetFunc;
00163 SetFunc mSetFunc;
00164
00165 public:
00166 AccesorPropertyDescriptor (GetFunc getFunc, SetFunc setFunc)
00167 {
00168 mGetFunc = getFunc;
00169 mSetFunc = setFunc;
00170 }
00171
00172 virtual bool canGetValue () const {
00173 return mGetFunc != 0;
00174 }
00175
00176 virtual bool canSetValue () const {
00177 return mSetFunc != 0;
00178 }
00179
00180 virtual const ParamT getValueTyped(const void* target) const
00181 {
00182 const TargetT* typedTarget = reinterpret_cast<const TargetT*>(target);
00183 return (typedTarget->*mGetFunc)();
00184 }
00185
00186 virtual void setValueTyped(void* target, const ParamT& value) const
00187 {
00188 TargetT* typedTarget = reinterpret_cast<TargetT*>(target);
00189 (typedTarget->*mSetFunc)(value);
00190 }
00191 };
00192
00200 class DefaultTypeDescriptor: public TypeDescriptor
00201 {
00202 public:
00203 DefaultTypeDescriptor ();
00204
00210 inline PropertyMap& getPropertyMap () { return mPropertyMap; }
00211
00212 void add (const Ogre::String& name, const ValuePropertyDescriptor* descriptor);
00213
00215 virtual const ValuePropertyDescriptor* getPropertyDescriptor (const Ogre::String& name) const;
00216
00218 virtual const std::vector<String> getPropertyNames () const;
00219
00221 virtual const PropertyMap getFullPropertyMap () const;
00222
00223 private:
00224 PropertyMap mPropertyMap;
00225 };
00226
00237 class CAELUM_EXPORT CaelumDefaultTypeDescriptorData
00238 {
00239 private:
00240 void load();
00241 void unload();
00242
00243 public:
00244 CaelumDefaultTypeDescriptorData();
00245 ~CaelumDefaultTypeDescriptorData();
00246
00247 DefaultTypeDescriptor* CaelumSystemTypeDescriptor;
00248 DefaultTypeDescriptor* PointStarfieldTypeDescriptor;
00249 DefaultTypeDescriptor* BaseSkyLightTypeDescriptor;
00250 DefaultTypeDescriptor* GroundFogTypeDescriptor;
00251 DefaultTypeDescriptor* PrecipitationTypeDescriptor;
00252 DefaultTypeDescriptor* DepthComposerTypeDescriptor;
00253 DefaultTypeDescriptor* FlatCloudLayerTypeDescriptor;
00254 DefaultTypeDescriptor* SkyDomeTypeDescriptor;
00255 };
00256 }
00257
00258 #endif // CAELUM_TYPE_DESCRIPTORS
00259
00260 #endif // CAELUM__TYPE_DESCRIPTOR_H