cppexpose  1.0.0.b785e04f23b8
C++ library for type introspection, reflection, and scripting interface
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
cppexpose::Object Class Reference

Base class for reflection-enabled objects. More...

#include <cppexpose/include/cppexpose/reflection/Object.h>

Inheritance diagram for cppexpose::Object:
Inheritance graph
[legend]
Collaboration diagram for cppexpose::Object:
Collaboration graph
[legend]

Public Member Functions

const std::vector< Method > & functions () const
 Get list of functions exported by this object. More...
 
template<typename RET , typename... Arguments>
void addFunction (const std::string &name, RET(*fn)(Arguments...))
 Add (export) static function. More...
 
template<class T , typename RET , typename... Arguments>
void addFunction (const std::string &name, T *obj, RET(T::*fn)(Arguments...))
 Add (export) method on object. More...
 
template<class T , typename RET , typename... Arguments>
void addFunction (const std::string &name, T *obj, RET(T::*fn)(Arguments...) const)
 Add (export) const method on object. More...
 
virtual bool isObject () const override
 Check if property is an object. More...
 
virtual std::unique_ptr< AbstractTyped > clone () const override
 
virtual const std::type_info & type () const override
 
virtual std::string typeName () const override
 
virtual bool isReadOnly () const override
 
virtual bool isComposite () const override
 
virtual size_t numSubValues () const override
 
virtual AbstractTyped * subValue (size_t i) override
 
virtual bool isEnum () const override
 
virtual bool isArray () const override
 
virtual bool isVariant () const override
 
virtual bool isString () const override
 
virtual bool isBool () const override
 
virtual bool isNumber () const override
 
virtual bool isIntegral () const override
 
virtual bool isSignedIntegral () const override
 
virtual bool isUnsignedIntegral () const override
 
virtual bool isFloatingPoint () const override
 
virtual Variant toVariant () const override
 
virtual bool fromVariant (const Variant &value) override
 
virtual std::string toString () const override
 
virtual bool fromString (const std::string &value) override
 
virtual bool toBool () const override
 
virtual bool fromBool (bool value) override
 
virtual long long toLongLong () const override
 
virtual bool fromLongLong (long long value) override
 
virtual unsigned long long toULongLong () const override
 
virtual bool fromULongLong (unsigned long long value) override
 
virtual double toDouble () const override
 
virtual bool fromDouble (double value) override
 
std::string relativePathTo (const Object *const other) const
 Get the relative path to another object. More...
 
 Object ()
 Constructor. More...
 
 Object (const std::string &name)
 Constructor. More...
 
 Object (const Object &)=delete
 Copy constructor (deleted) More...
 
virtual ~Object ()
 Destructor. More...
 
Objectoperator= (const Object &)=delete
 Copy assignment operator (deleted) More...
 
const std::string & className () const
 Get class name. More...
 
void setClassName (const std::string &className)
 Set class name. More...
 
void clear ()
 Clear properties. More...
 
const std::unordered_map< std::string, AbstractProperty * > & properties () const
 Get properties. More...
 
bool propertyExists (const std::string &name) const
 Check if property exists. More...
 
AbstractPropertyproperty (size_t index)
 Get property by index. More...
 
const AbstractPropertyproperty (size_t index) const
 
AbstractPropertyproperty (const std::string &path)
 Get property by name. More...
 
const AbstractPropertyproperty (const std::string &path) const
 
bool addProperty (AbstractProperty *property)
 Add property to object. More...
 
bool addProperty (std::unique_ptr< AbstractProperty > &&property)
 Add property to object. More...
 
template<typename Type , typename... Arguments>
bool addProperty (const std::string &name, Arguments &&...arguments)
 Create and add property to object. More...
 
bool removeProperty (AbstractProperty *property)
 Remove property from object. More...
 
template<typename T >
DynamicProperty< T > * createDynamicProperty (const std::string &name, const T &value=T())
 Create dynamic property. More...
 
- Public Member Functions inherited from cppexpose::AbstractProperty
 AbstractProperty ()
 Constructor. More...
 
 AbstractProperty (const Variant &options)
 Constructor. More...
 
virtual ~AbstractProperty ()
 Destructor. More...
 
const std::string & name () const
 Get name. More...
 
void setName (const std::string &name)
 Set name. More...
 
std::string qualifiedName (const Object *relativeRoot=nullptr) const
 Get qualified name. More...
 
Objectparent () const
 Get parent object. More...
 
bool hasParent () const
 Finds out whether the Object has a parent. More...
 
const VariantMap & options () const
 Get options of property. More...
 
void setOptions (const VariantMap &map)
 Set options of property. More...
 
bool hasOption (const std::string &key) const
 Check if option is set. More...
 
const Variant & option (const std::string &key) const
 Get option of property. More...
 
template<typename Type >
Type option (const std::string &key, const Type &defaultValue=Type()) const
 Get option of property convert to a specific type. More...
 
void setOption (const std::string &key, const Variant &value)
 Set option of property. More...
 
bool removeOption (const std::string &key)
 Remove option of property. More...
 

Public Attributes

Signal< size_t, AbstractProperty * > beforeAdd
 Called before a property is added to the object. More...
 
Signal< size_t, AbstractProperty * > afterAdd
 Called after a property is added to the object. More...
 
Signal< size_t, AbstractProperty * > beforeRemove
 Called before a property is removed from the object. More...
 
Signal< size_t, AbstractProperty * > afterRemove
 Called after a property is removed from the object. More...
 
- Public Attributes inherited from cppexpose::AbstractProperty
Signal< AbstractProperty * > beforeDestroy
 Called before a property is destroyed. More...
 
Signal< const std::string & > optionChanged
 Called when an option of the property has been changed. More...
 

Protected Member Functions

const AbstractPropertyfindProperty (const std::vector< std::string > &path) const
 
- Protected Member Functions inherited from cppexpose::AbstractProperty
void initProperty (const std::string &name, Object *parent)
 Initialize property. More...
 
void setParent (Object *parent)
 Set parent object. More...
 
virtual void onOptionChanged (const std::string &option)
 Called when an option of the property has changed. More...
 

Protected Attributes

std::string m_className
 Class name for this object (default: "Object") More...
 
std::vector< AbstractProperty * > m_properties
 List of properties in the object. More...
 
std::unordered_map< std::string, AbstractProperty * > m_propertiesMap
 Map of names and properties. More...
 
std::vector< std::unique_ptr< AbstractProperty > > m_managedProperties
 Property that are owned by the object. More...
 
std::vector< Methodm_functions
 List of exported functions. More...
 
- Protected Attributes inherited from cppexpose::AbstractProperty
std::string m_name
 Name of the property. More...
 
Objectm_parent
 Parent object. More...
 
VariantMap m_options
 Additional options for the property (e.g., minimum or maximum values) More...
 

Friends

class AbstractProperty
 

Detailed Description

Base class for reflection-enabled objects.

Constructor & Destructor Documentation

cppexpose::Object::Object ( )

Constructor.

cppexpose::Object::Object ( const std::string &  name)

Constructor.

Parameters
[in]nameName
cppexpose::Object::Object ( const Object )
delete

Copy constructor (deleted)

Parameters
[in]Objectto copy from
virtual cppexpose::Object::~Object ( )
virtual

Destructor.

Member Function Documentation

Object& cppexpose::Object::operator= ( const Object )
delete

Copy assignment operator (deleted)

Parameters
[in]Objectto copy from
const std::string& cppexpose::Object::className ( ) const

Get class name.

return Class name for this object (default: "Object")

void cppexpose::Object::setClassName ( const std::string &  className)

Set class name.

Parameters
[in]classNameClass name for this object (default: "Object")
void cppexpose::Object::clear ( )

Clear properties.

Removes all properties from the object. Properties which have been added with PropertyOwnership::Parent are deleted.

const std::unordered_map<std::string, AbstractProperty *>& cppexpose::Object::properties ( ) const

Get properties.

Returns
Map of names and properties
bool cppexpose::Object::propertyExists ( const std::string &  name) const

Check if property exists.

Parameters
[in]nameName of property
Returns
'true' if property exists, else 'false'

Referenced by createDynamicProperty().

AbstractProperty* cppexpose::Object::property ( size_t  index)

Get property by index.

Parameters
[in]indexIndex of the property
Returns
Pointer to the property, or nullptr on error

Referenced by addProperty(), and createDynamicProperty().

const AbstractProperty* cppexpose::Object::property ( size_t  index) const
AbstractProperty* cppexpose::Object::property ( const std::string &  path)

Get property by name.

Parameters
[in]pathPath of property relative to the object, e.g. "Prop1", or "Sub1.Sub2.Property"
Returns
Pointer to the property, or nullptr on error
const AbstractProperty* cppexpose::Object::property ( const std::string &  path) const
bool cppexpose::Object::addProperty ( AbstractProperty property)

Add property to object.

Parameters
[in]propertyProperty (must NOT be null!)
Returns
'true' if the property has been added to the object, else 'false'
Remarks
Adds the given property to the object.

The name of the property must be valid and unique to the object, also the property must not belong to any other object already. Otherwise, the property will not be added to the object.

Referenced by addProperty(), and createDynamicProperty().

bool cppexpose::Object::addProperty ( std::unique_ptr< AbstractProperty > &&  property)

Add property to object.

Parameters
[in]propertyProperty (must NOT be null!)
Returns
'true' if the property has been added to the object, else 'false'
Remarks
Adds the given property to the object.

The name of the property must be valid and unique to the object, also the property must not belong to any other object already. Otherwise, the property will not be added to the object.

template<typename Type , typename... Arguments>
bool cppexpose::Object::addProperty ( const std::string &  name,
Arguments &&...  arguments 
)

Create and add property to object.

Parameters
[in]nameName of the new property
[in]argumentsProperty constructor arguments
Returns
'true' if the property has been added to the object, else 'false'
Remarks
Creates a property of the given type with the given arguments and adds it to the object.

The name of the property must be valid and unique to the object, also the property must not belong to any other object already. Otherwise, the property will not be added to the object.

References addProperty(), cppexpose::AbstractProperty::name(), and property().

bool cppexpose::Object::removeProperty ( AbstractProperty property)

Remove property from object.

Parameters
[in]propertyProperty (must NOT be null!)
Returns
'true' if the property has been removed from the object, else 'false'
Remarks
If the specified property does not belong to the object, this function will do nothing and return 'false'.

If the object has ownership of the property, it will be deleted.

template<typename T >
DynamicProperty< T > * cppexpose::Object::createDynamicProperty ( const std::string &  name,
const T &  value = T() 
)

Create dynamic property.

Parameters
[in]nameProperty name
[in]valueDefault value
Returns
Pointer to the new property, or nullptr on error
Remarks
This function creates a new dynamic property of the specified typed and adds it to the object. It also takes ownership over the property.

References addProperty(), cppexpose::AbstractProperty::name(), property(), and propertyExists().

const std::vector<Method>& cppexpose::Object::functions ( ) const

Get list of functions exported by this object.

Returns
List of methods
template<typename RET , typename... Arguments>
void cppexpose::Object::addFunction ( const std::string &  name,
RET(*)(Arguments...)  fn 
)

Add (export) static function.

Parameters
[in]nameFunction name
[in]fnFunction pointer

References m_functions.

Referenced by addFunction().

template<class T , typename RET, typename... Arguments>
void cppexpose::Object::addFunction ( const std::string &  name,
T *  obj,
RET(T::*)(Arguments...)  fn 
)

Add (export) method on object.

Parameters
[in]nameFunction name
[in]objPointer to object instance
[in]memberMethod pointer

References addFunction(), and m_functions.

template<class T , typename RET , typename... Arguments>
void cppexpose::Object::addFunction ( const std::string &  name,
T *  obj,
RET(T::*)(Arguments...) const  fn 
)

Add (export) const method on object.

Parameters
[in]nameFunction name
[in]objPointer to object instance
[in]memberMethod pointer
virtual bool cppexpose::Object::isObject ( ) const
overridevirtual

Check if property is an object.

Returns
'true' if property is an object, else 'false'

Implements cppexpose::AbstractProperty.

virtual std::unique_ptr<AbstractTyped> cppexpose::Object::clone ( ) const
overridevirtual
virtual const std::type_info& cppexpose::Object::type ( ) const
overridevirtual
virtual std::string cppexpose::Object::typeName ( ) const
overridevirtual
virtual bool cppexpose::Object::isReadOnly ( ) const
overridevirtual
virtual bool cppexpose::Object::isComposite ( ) const
overridevirtual
virtual size_t cppexpose::Object::numSubValues ( ) const
overridevirtual
virtual AbstractTyped* cppexpose::Object::subValue ( size_t  i)
overridevirtual
virtual bool cppexpose::Object::isEnum ( ) const
overridevirtual
virtual bool cppexpose::Object::isArray ( ) const
overridevirtual
virtual bool cppexpose::Object::isVariant ( ) const
overridevirtual
virtual bool cppexpose::Object::isString ( ) const
overridevirtual
virtual bool cppexpose::Object::isBool ( ) const
overridevirtual
virtual bool cppexpose::Object::isNumber ( ) const
overridevirtual
virtual bool cppexpose::Object::isIntegral ( ) const
overridevirtual
virtual bool cppexpose::Object::isSignedIntegral ( ) const
overridevirtual
virtual bool cppexpose::Object::isUnsignedIntegral ( ) const
overridevirtual
virtual bool cppexpose::Object::isFloatingPoint ( ) const
overridevirtual
virtual Variant cppexpose::Object::toVariant ( ) const
overridevirtual
virtual bool cppexpose::Object::fromVariant ( const Variant &  value)
overridevirtual
virtual std::string cppexpose::Object::toString ( ) const
overridevirtual
virtual bool cppexpose::Object::fromString ( const std::string &  value)
overridevirtual
virtual bool cppexpose::Object::toBool ( ) const
overridevirtual
virtual bool cppexpose::Object::fromBool ( bool  value)
overridevirtual
virtual long long cppexpose::Object::toLongLong ( ) const
overridevirtual
virtual bool cppexpose::Object::fromLongLong ( long long  value)
overridevirtual
virtual unsigned long long cppexpose::Object::toULongLong ( ) const
overridevirtual
virtual bool cppexpose::Object::fromULongLong ( unsigned long long  value)
overridevirtual
virtual double cppexpose::Object::toDouble ( ) const
overridevirtual
virtual bool cppexpose::Object::fromDouble ( double  value)
overridevirtual
std::string cppexpose::Object::relativePathTo ( const Object *const  other) const

Get the relative path to another object.

Parameters
[in]otherThe other object
Returns
The relative path to the other object
Remarks
Parent-relationships are indicated using "parent" If no path could be found, the returned string is empty If this == other, the returned string is "."
const AbstractProperty* cppexpose::Object::findProperty ( const std::vector< std::string > &  path) const
protected

Friends And Related Function Documentation

friend class AbstractProperty
friend

Member Data Documentation

Signal<size_t, AbstractProperty *> cppexpose::Object::beforeAdd

Called before a property is added to the object.

Signal<size_t, AbstractProperty *> cppexpose::Object::afterAdd

Called after a property is added to the object.

Signal<size_t, AbstractProperty *> cppexpose::Object::beforeRemove

Called before a property is removed from the object.

Signal<size_t, AbstractProperty *> cppexpose::Object::afterRemove

Called after a property is removed from the object.

std::string cppexpose::Object::m_className
protected

Class name for this object (default: "Object")

std::vector<AbstractProperty *> cppexpose::Object::m_properties
protected

List of properties in the object.

std::unordered_map<std::string, AbstractProperty *> cppexpose::Object::m_propertiesMap
protected

Map of names and properties.

std::vector<std::unique_ptr<AbstractProperty> > cppexpose::Object::m_managedProperties
protected

Property that are owned by the object.

std::vector<Method> cppexpose::Object::m_functions
protected

List of exported functions.

Referenced by addFunction().


The documentation for this class was generated from the following files: