OgreProperty.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __OGRE_PROPERTY_H__
#define __OGRE_PROPERTY_H__
#include "OgrePropertyPrerequisites.h"
#include "OgreAny.h"
#include "OgreIteratorWrappers.h"
#include "OgreString.h"
#include "OgreException.h"
#include "OgreVector2.h"
#include "OgreVector3.h"
#include "OgreVector4.h"
#include "OgreColourValue.h"
#include "OgreQuaternion.h"
#include "OgreMatrix3.h"
#include "OgreMatrix4.h"
#include <boost/bind.hpp>
#include <boost/function.hpp>
namespace Ogre
{
enum PropertyType
{
PROP_SHORT = 0,
PROP_UNSIGNED_SHORT = 1,
PROP_INT = 2,
PROP_UNSIGNED_INT = 3,
PROP_LONG = 4,
PROP_UNSIGNED_LONG = 5,
PROP_REAL = 6,
PROP_STRING = 7,
PROP_VECTOR2 = 8,
PROP_VECTOR3 = 9,
PROP_VECTOR4 = 10,
PROP_COLOUR = 11,
PROP_BOOL = 12,
PROP_QUATERNION = 13,
PROP_MATRIX3 = 14,
PROP_MATRIX4 = 15,
PROP_UNKNOWN = 999
};
class _OgrePropertyExport PropertyDef : public PropertyAlloc
{
public:
PropertyDef(const String& name, const String& desc, PropertyType pType)
: mName(name), mDesc(desc), mType(pType) {}
const String& getName() const { return mName; }
const String& getDescription() const { return mDesc; }
PropertyType getType() const { return mType; }
static const String& getTypeName(PropertyType theType);
static PropertyType getTypeForValue(const short& val) { return PROP_SHORT; }
static PropertyType getTypeForValue(const unsigned short& val) { return PROP_UNSIGNED_SHORT; }
static PropertyType getTypeForValue(const int& val) { return PROP_INT; }
static PropertyType getTypeForValue(const unsigned int& val) { return PROP_UNSIGNED_INT; }
static PropertyType getTypeForValue(const long& val) { return PROP_LONG; }
static PropertyType getTypeForValue(const unsigned long& val) { return PROP_UNSIGNED_LONG; }
static PropertyType getTypeForValue(const Real& val) { return PROP_REAL; }
static PropertyType getTypeForValue(const String& val) { return PROP_STRING; }
static PropertyType getTypeForValue(const Vector2& val) { return PROP_VECTOR2; }
static PropertyType getTypeForValue(const Vector3& val) { return PROP_VECTOR3; }
static PropertyType getTypeForValue(const Vector4& val) { return PROP_VECTOR4; }
static PropertyType getTypeForValue(const ColourValue& val) { return PROP_COLOUR; }
static PropertyType getTypeForValue(const bool& val) { return PROP_BOOL; }
static PropertyType getTypeForValue(const Quaternion& val) { return PROP_QUATERNION; }
static PropertyType getTypeForValue(const Matrix3& val) { return PROP_MATRIX3; }
static PropertyType getTypeForValue(const Matrix4& val) { return PROP_MATRIX4; }
protected:
// no default construction
PropertyDef() {}
String mName;
String mDesc;
PropertyType mType;
};
typedef map<String, PropertyDef>::type PropertyDefMap;
class _OgrePropertyExport PropertyBase : public PropertyAlloc
{
public:
PropertyBase(PropertyDef* def) : mDef(def) {}
virtual ~PropertyBase() {}
const String& getName() const { return mDef->getName(); }
const String& getDescription() const { return mDef->getDescription(); }
PropertyType getType() const { return mDef->getType(); }
virtual Ogre::Any getValue() const = 0;
protected:
// disallow default construction
PropertyBase() {}
PropertyDef* mDef;
};
template <typename T>
class Property : public PropertyBase
{
public:
typedef T value_type;
typedef boost::function< T (void) > getter_func;
typedef boost::function< void (T) > setter_func;
Property(PropertyDef* def, getter_func getter, setter_func setter)
: PropertyBase(def)
, mGetter(getter)
, mSetter(setter)
{
}
virtual void set(T val)
{
mSetter(val);
}
virtual T get() const
{
return mGetter();
}
Ogre::Any getValue() const
{
return Ogre::Any(get());
}
protected:
// disallow default construction
Property() {}
~Property() {}
getter_func mGetter;
setter_func mSetter;
};
struct PropertyValue
{
PropertyType propType;
Ogre::Any val;
};
typedef map<String, PropertyValue>::type PropertyValueMap;
class _OgrePropertyExport PropertySet : public PropertyAlloc
{
public:
PropertySet();
~PropertySet();
void addProperty(PropertyBase* prop);
PropertyBase* getProperty(const String& name) const;
bool hasProperty(const String& name) const;
void removeProperty(const String& name);
typedef map<String, PropertyBase*>::type PropertyMap;
typedef Ogre::MapIterator<PropertyMap> PropertyIterator;
PropertyIterator getPropertyIterator();
PropertyValueMap getValueMap() const;
void setValueMap(const PropertyValueMap& values);
template<typename T>
void getValue(const String& name, T& value) const
{
getPropertyImpl(name, value, PropertyDef::getTypeForValue(value));
}
template<typename T>
void setValue(const String& name, const T* value)
{
setPropertyImpl(name, *value, PropertyDef::getTypeForValue(*value));
}
template<typename T>
void setValue(const String& name, T value)
{
setPropertyImpl(name, value, PropertyDef::getTypeForValue(value));
}
void setValue(const String& name, const char* pChar)
{
String v(pChar);
setPropertyImpl(name, v, PROP_STRING);
}
protected:
PropertyMap mPropertyMap;
template <typename T>
void setPropertyImpl(const String& name, const T& val, PropertyType typeCheck)
{
PropertyBase* baseProp = getProperty(name);
if (baseProp->getType() != typeCheck)
{
StringUtil::StrStreamType msg;
msg << "Property error: type passed in: '" << PropertyDef::getTypeName(typeCheck)
<< "', type of property: '" << PropertyDef::getTypeName(baseProp->getType()) << "'";
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, msg.str(), "PropertySet::setPropertyImpl");
}
static_cast<Property<T>*>(baseProp)->set(val);
}
template <typename T>
void getPropertyImpl(const String& name, T& refVal, PropertyType typeCheck) const
{
PropertyBase* baseProp = getProperty(name);
if (baseProp->getType() != typeCheck)
{
StringUtil::StrStreamType msg;
msg << "Property error: type requested: '" << PropertyDef::getTypeName(typeCheck)
<< "', type of property: '" << PropertyDef::getTypeName(baseProp->getType()) << "'";
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, msg.str(), "PropertySet::getPropertyImpl");
}
refVal = static_cast<Property<T>*>(baseProp)->get();
}
};
}
#endif
OgreVector4.h
Ogre::PROP_STRING
Definition: OgreProperty.h:119
Ogre::PropertyValue::val
Ogre::Any val
Definition: OgreProperty.h:271
Ogre::PropertyDef::getTypeForValue
static PropertyType getTypeForValue(const Vector4 &val)
Definition: OgreProperty.h:171
Ogre::PROP_SHORT
Definition: OgreProperty.h:112
Ogre::PropertyDef::getTypeForValue
static PropertyType getTypeForValue(const int &val)
Definition: OgreProperty.h:163
OgreQuaternion.h
Ogre::PROP_MATRIX4
Definition: OgreProperty.h:127
OgreVector3.h
Ogre::PropertyBase::PropertyBase
PropertyBase(PropertyDef *def)
Constructor.
Definition: OgreProperty.h:197
Ogre::PropertyValue
A simple structure designed just as a holder of property values between the instances of objects they...
Definition: OgreProperty.h:268
Ogre::PropertyDef::getTypeForValue
static PropertyType getTypeForValue(const String &val)
Definition: OgreProperty.h:168
Ogre::PropertyDef::getTypeForValue
static PropertyType getTypeForValue(const unsigned int &val)
Definition: OgreProperty.h:164
Ogre::PropertyDef::PropertyDef
PropertyDef(const String &name, const String &desc, PropertyType pType)
Construct a property.
Definition: OgreProperty.h:146
Ogre::PropertySet::getPropertyImpl
void getPropertyImpl(const String &name, T &refVal, PropertyType typeCheck) const
Get a named property value, internal implementation (type match required)
Definition: OgreProperty.h:371
Ogre::Property::setter_func
boost::function< void(T) > setter_func
Definition: OgreProperty.h:226
Ogre::PropertyDef::getTypeForValue
static PropertyType getTypeForValue(const Quaternion &val)
Definition: OgreProperty.h:174
Ogre::Quaternion
Implementation of a Quaternion, i.e.
Definition: OgreQuaternion.h:57
Ogre::MapIterator
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
Definition: OgreIteratorWrapper.h:319
Ogre::PropertyDefMap
map< String, PropertyDef >::type PropertyDefMap
Map from property name to shared definition.
Definition: OgreProperty.h:189
Ogre::PropertyValueMap
map< String, PropertyValue >::type PropertyValueMap
Defines a transferable map of properties using wrapped value types (Ogre::Any)
Definition: OgreProperty.h:274
Ogre::Matrix3
A 3x3 matrix which can represent rotations around axes.
Definition: OgreMatrix3.h:68
Ogre::Vector4
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
_OgrePropertyExport
#define _OgrePropertyExport
Definition: OgrePropertyPrerequisites.h:51
Ogre::Vector2
Standard 2-dimensional vector.
Definition: OgreVector2.h:51
Ogre::ColourValue
Class representing colour.
Definition: OgreColourValue.h:57
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::PROP_UNKNOWN
Definition: OgreProperty.h:129
Ogre::PropertyValue::propType
PropertyType propType
Definition: OgreProperty.h:270
OgreString.h
Ogre::PROP_LONG
Definition: OgreProperty.h:116
Ogre::StringUtil::StrStreamType
StringStream StrStreamType
Definition: OgreString.h:78
Ogre::Property::~Property
~Property()
Definition: OgreProperty.h:258
Ogre::PropertySet
Defines a complete set of properties for a single object instance.
Definition: OgreProperty.h:279
Ogre::PropertyDef
Definition of a property of an object.
Definition: OgreProperty.h:137
Ogre::PropertyDef::getDescription
const String & getDescription() const
Get the description of the property.
Definition: OgreProperty.h:153
Ogre::PropertyDef::getTypeForValue
static PropertyType getTypeForValue(const ColourValue &val)
Definition: OgreProperty.h:172
Ogre::Any
Variant type that can hold Any other type.
Definition: OgreAny.h:56
Ogre::Property::value_type
T value_type
Definition: OgreProperty.h:224
Ogre::PropertyDef::mDesc
String mDesc
Definition: OgreProperty.h:183
Ogre::PROP_REAL
Definition: OgreProperty.h:118
Ogre::PropertySet::getValue
void getValue(const String &name, T &value) const
Get a named property value.
Definition: OgreProperty.h:323
Ogre::Property
Property instance with passthrough calls to a given object.
Definition: OgreProperty.h:221
Ogre::Matrix4
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Ogre::Property::mSetter
setter_func mSetter
Definition: OgreProperty.h:261
Ogre::map::type
std::map< K, V, P, A > type
Definition: OgrePrerequisites.h:536
Ogre::PropertyDef::getTypeForValue
static PropertyType getTypeForValue(const bool &val)
Definition: OgreProperty.h:173
Ogre::PropertySet::setValue
void setValue(const String &name, const char *pChar)
Special-case char*, convert to String automatically.
Definition: OgreProperty.h:344
Ogre::PropertyDef::getTypeForValue
static PropertyType getTypeForValue(const short &val)
Definition: OgreProperty.h:161
Ogre::PropertyDef::getTypeForValue
static PropertyType getTypeForValue(const Matrix3 &val)
Definition: OgreProperty.h:175
Ogre::PropertyBase
Base interface for an instance of a property.
Definition: OgreProperty.h:193
Ogre::PROP_VECTOR2
Definition: OgreProperty.h:120
Ogre::Property::getValue
Ogre::Any getValue() const
Return the current value as an Any.
Definition: OgreProperty.h:250
Ogre::PropertyDef::getTypeForValue
static PropertyType getTypeForValue(const unsigned long &val)
Definition: OgreProperty.h:166
OgrePropertyPrerequisites.h
Ogre::PropertyBase::getDescription
const String & getDescription() const
Get the description of the property.
Definition: OgreProperty.h:204
Ogre::PropertyDef::getTypeForValue
static PropertyType getTypeForValue(const Real &val)
Definition: OgreProperty.h:167
Ogre::Property::mGetter
getter_func mGetter
Definition: OgreProperty.h:260
Ogre::PropertyBase::PropertyBase
PropertyBase()
Definition: OgreProperty.h:214
Ogre::PropertySet::PropertyIterator
Ogre::MapIterator< PropertyMap > PropertyIterator
Definition: OgreProperty.h:307
Ogre::Property::getter_func
boost::function< T(void) > getter_func
Definition: OgreProperty.h:225
OgreMatrix4.h
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::PropertyDef::getType
PropertyType getType() const
Get the type of the property.
Definition: OgreProperty.h:156
Ogre::PropertyDef::mType
PropertyType mType
Definition: OgreProperty.h:184
Ogre::PropertyDef::PropertyDef
PropertyDef()
Definition: OgreProperty.h:180
Ogre::PROP_QUATERNION
Definition: OgreProperty.h:125
Ogre::PROP_VECTOR4
Definition: OgreProperty.h:122
Ogre::PROP_UNSIGNED_INT
Definition: OgreProperty.h:115
Ogre::Property::Property
Property()
Definition: OgreProperty.h:257
Ogre::PropertyDef::getTypeForValue
static PropertyType getTypeForValue(const Matrix4 &val)
Definition: OgreProperty.h:176
Ogre::PropertyBase::~PropertyBase
virtual ~PropertyBase()
Definition: OgreProperty.h:198
OgreAny.h
Ogre::PropertySet::mPropertyMap
PropertyMap mPropertyMap
Definition: OgreProperty.h:352
OgreMatrix3.h
OgreIteratorWrappers.h
Ogre::PROP_COLOUR
Definition: OgreProperty.h:123
Ogre::PropertyDef::getTypeForValue
static PropertyType getTypeForValue(const Vector2 &val)
Definition: OgreProperty.h:169
OGRE_EXCEPT
#define OGRE_EXCEPT(num, desc, src)
Definition: OgreException.h:334
Ogre::Exception::ERR_INVALIDPARAMS
Definition: OgreException.h:103
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::PropertyBase::getType
PropertyType getType() const
Get the type of the property.
Definition: OgreProperty.h:207
OgreException.h
Ogre::PROP_INT
Definition: OgreProperty.h:114
Ogre::Property::Property
Property(PropertyDef *def, getter_func getter, setter_func setter)
Construct a property which is able to directly call a given getter and setter on a specific object in...
Definition: OgreProperty.h:231
OgreColourValue.h
Ogre::PropertySet::setPropertyImpl
void setPropertyImpl(const String &name, const T &val, PropertyType typeCheck)
Set a named property value, internal implementation (type match required)
Definition: OgreProperty.h:356
Ogre::PropertyDef::getName
const String & getName() const
Get the name of the property.
Definition: OgreProperty.h:150
OgreVector2.h
Ogre::map
Definition: OgrePrerequisites.h:533
Ogre::PropertySet::setValue
void setValue(const String &name, const T *value)
Set a named property value (via pointer to avoid copy).
Definition: OgreProperty.h:331
Ogre::PropertyDef::mName
String mName
Definition: OgreProperty.h:182
Ogre::PropertyDef::getTypeName
static const String & getTypeName(PropertyType theType)
Get a string name of a property type.
Ogre::PropertyDef::getTypeForValue
static PropertyType getTypeForValue(const long &val)
Definition: OgreProperty.h:165
Ogre::PropertySet::PropertyMap
map< String, PropertyBase * >::type PropertyMap
Definition: OgreProperty.h:306
Ogre::PropertySet::setValue
void setValue(const String &name, T value)
Set a named property value.
Definition: OgreProperty.h:338
Ogre::PROP_UNSIGNED_SHORT
Definition: OgreProperty.h:113
Ogre::PropertyDef::getTypeForValue
static PropertyType getTypeForValue(const Vector3 &val)
Definition: OgreProperty.h:170
Ogre::PROP_UNSIGNED_LONG
Definition: OgreProperty.h:117
Ogre::PropertyType
PropertyType
The type of a property.
Definition: OgreProperty.h:110
Ogre::PropertyBase::getName
const String & getName() const
Get the name of the property.
Definition: OgreProperty.h:201
Ogre::PropertyDef::getTypeForValue
static PropertyType getTypeForValue(const unsigned short &val)
Definition: OgreProperty.h:162
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::PropertyBase::mDef
PropertyDef * mDef
Definition: OgreProperty.h:215
Ogre::PROP_MATRIX3
Definition: OgreProperty.h:126
Ogre::PROP_VECTOR3
Definition: OgreProperty.h:121
Ogre::PROP_BOOL
Definition: OgreProperty.h:124

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.