cppexpose
1.0.0.b785e04f23b8
C++ library for type introspection, reflection, and scripting interface
|
Base class for reflection-enabled objects. More...
#include <cppexpose/include/cppexpose/reflection/Object.h>
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... | |
Object & | operator= (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... | |
AbstractProperty * | property (size_t index) |
Get property by index. More... | |
const AbstractProperty * | property (size_t index) const |
AbstractProperty * | property (const std::string &path) |
Get property by name. More... | |
const AbstractProperty * | property (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... | |
Object * | parent () 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 AbstractProperty * | findProperty (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< Method > | m_functions |
List of exported functions. More... | |
Protected Attributes inherited from cppexpose::AbstractProperty | |
std::string | m_name |
Name of the property. More... | |
Object * | m_parent |
Parent object. More... | |
VariantMap | m_options |
Additional options for the property (e.g., minimum or maximum values) More... | |
Friends | |
class | AbstractProperty |
Base class for reflection-enabled objects.
cppexpose::Object::Object | ( | ) |
Constructor.
cppexpose::Object::Object | ( | const std::string & | name | ) |
Constructor.
[in] | name | Name |
|
delete |
Copy constructor (deleted)
[in] | Object | to copy from |
|
virtual |
Destructor.
Copy assignment operator (deleted)
[in] | Object | to 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.
[in] | className | Class 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.
bool cppexpose::Object::propertyExists | ( | const std::string & | name | ) | const |
Check if property exists.
[in] | name | Name of property |
Referenced by createDynamicProperty().
AbstractProperty* cppexpose::Object::property | ( | size_t | index | ) |
Get property by index.
[in] | index | Index of the property |
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.
[in] | path | Path of property relative to the object, e.g. "Prop1", or "Sub1.Sub2.Property" |
const AbstractProperty* cppexpose::Object::property | ( | const std::string & | path | ) | const |
bool cppexpose::Object::addProperty | ( | AbstractProperty * | property | ) |
Add property to object.
[in] | property | Property (must NOT be null!) |
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.
[in] | property | Property (must NOT be null!) |
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.
bool cppexpose::Object::addProperty | ( | const std::string & | name, |
Arguments &&... | arguments | ||
) |
Create and add property to object.
[in] | name | Name of the new property |
[in] | arguments | Property constructor arguments |
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.
[in] | property | Property (must NOT be null!) |
If the object has ownership of the property, it will be deleted.
DynamicProperty< T > * cppexpose::Object::createDynamicProperty | ( | const std::string & | name, |
const T & | value = T() |
||
) |
Create dynamic property.
[in] | name | Property name |
[in] | value | Default value |
References addProperty(), cppexpose::AbstractProperty::name(), property(), and propertyExists().
const std::vector<Method>& cppexpose::Object::functions | ( | ) | const |
Get list of functions exported by this object.
void cppexpose::Object::addFunction | ( | const std::string & | name, |
RET(*)(Arguments...) | fn | ||
) |
void cppexpose::Object::addFunction | ( | const std::string & | name, |
T * | obj, | ||
RET(T::*)(Arguments...) | fn | ||
) |
Add (export) method on object.
References addFunction(), and m_functions.
void cppexpose::Object::addFunction | ( | const std::string & | name, |
T * | obj, | ||
RET(T::*)(Arguments...) const | fn | ||
) |
|
overridevirtual |
Check if property is an object.
Implements cppexpose::AbstractProperty.
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
std::string cppexpose::Object::relativePathTo | ( | const Object *const | other | ) | const |
Get the relative path to another object.
[in] | other | The other object |
|
protected |
|
friend |
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.
|
protected |
Class name for this object (default: "Object")
|
protected |
List of properties in the object.
|
protected |
Map of names and properties.
|
protected |
Property that are owned by the object.
|
protected |
List of exported functions.
Referenced by addFunction().