Mixin class for enabling a property system on OSS classes, the instance still needs to initialize properties in the constructor by using either addSetter, addGetter, addAccessors or the macro for each member variable that should be made accessible.
More...
#include <SurgSim/Framework/Accessible.h>
|
typedef std::function< boost::any(void)> | GetterType |
|
typedef std::function< void(boost::any)> | SetterType |
|
typedef std::function< YAML::Node(void)> | EncoderType |
|
typedef std::function< void(const YAML::Node *)> | DecoderType |
|
|
| Accessible () |
| Default Constructor. More...
|
|
| ~Accessible () |
| Destructor. More...
|
|
template<class T > |
T | getValue (const std::string &name) const |
| Retrieves the value with the name by executing the getter if it is found and tries to convert it to the given type. More...
|
|
boost::any | getValue (const std::string &name) const |
| Retrieves the value with the name by executing the getter if it is found. More...
|
|
template<class T > |
bool | getValue (const std::string &name, T *value) const |
| Retrieves the value with the name by executing the getter if it is found, and converts it to the type of the output parameter. More...
|
|
void | setValue (const std::string &name, const boost::any &value) |
| Sets a value of a property that has setter. More...
|
|
bool | isReadable (const std::string &name) const |
| Check whether a property is readable. More...
|
|
bool | isWriteable (const std::string &name) const |
| Check whether a property is writable. More...
|
|
void | setGetter (const std::string &name, GetterType func) |
| Sets a getter for a given property. More...
|
|
void | setSetter (const std::string &name, SetterType func) |
| Sets a setter for a given property. More...
|
|
void | setAccessors (const std::string &name, GetterType getter, SetterType setter) |
| Sets the accessors getter and setter in one function. More...
|
|
void | removeAccessors (const std::string &name) |
| Removes all the accessors (getter and setter) for a given property. More...
|
|
void | forwardProperty (const std::string &name, const Accessible &target, const std::string &targetProperty) |
| Adds a property with the given name that uses the targets accessors, in effect forwarding the value to the target. More...
|
|
void | setSerializable (const std::string &name, EncoderType encoder, DecoderType decoder) |
| Sets the functions used to convert data from and to a YAML::Node. More...
|
|
YAML::Node | encode () const |
| Encode this Accessible to a YAML::Node. More...
|
|
void | decode (const YAML::Node &node, const std::vector< std::string > &ignoredProperties=std::vector< std::string >()) |
| Decode this Accessible from a YAML::Node, will throw an exception if the data type cannot be converted. More...
|
|
template<> |
boost::any | getValue (const std::string &name) const |
|
Mixin class for enabling a property system on OSS classes, the instance still needs to initialize properties in the constructor by using either addSetter, addGetter, addAccessors or the macro for each member variable that should be made accessible.
SurgSim::Framework::Accessible::Accessible |
( |
| ) |
|
SurgSim::Framework::Accessible::~Accessible |
( |
| ) |
|
SurgSim::Framework::Accessible::Accessible |
( |
const Accessible & |
other | ) |
|
|
private |
Prevent default copy construction and default assignment
void SurgSim::Framework::Accessible::decode |
( |
const YAML::Node & |
node, |
|
|
const std::vector< std::string > & |
ignoredProperties = std::vector<std::string>() |
|
) |
| |
Decode this Accessible from a YAML::Node, will throw an exception if the data type cannot be converted.
- Exceptions
-
- Parameters
-
node | The node that carries the data to be decoded, properties with names that don't match up with properties in the Accessible will be reported. |
ignoredProperties | Properties that will be ignored. |
YAML::Node SurgSim::Framework::Accessible::encode |
( |
| ) |
const |
Encode this Accessible to a YAML::Node.
- Returns
- The encoded version of this instance.
void SurgSim::Framework::Accessible::forwardProperty |
( |
const std::string & |
name, |
|
|
const Accessible & |
target, |
|
|
const std::string & |
targetProperty |
|
) |
| |
Adds a property with the given name that uses the targets accessors, in effect forwarding the value to the target.
- Note
- This will copy the appropriate calls into the local function table of this accessible, in effect exposing a pointer to the target, if the target goes out of scope, the behavior is undefined
- Exceptions
-
- Parameters
-
name | The name of the new property |
target | The instance that provides the actual property |
targetProperty | The name of the property that should be used. |
boost::any SurgSim::Framework::Accessible::getValue |
( |
const std::string & |
name | ) |
const |
template<class T >
T SurgSim::Framework::Accessible::getValue |
( |
const std::string & |
name | ) |
const |
Retrieves the value with the name by executing the getter if it is found and tries to convert it to the given type.
- Exceptions
-
- Template Parameters
-
T | The requested type for the property. |
- Parameters
-
name | The name of the property. |
- Returns
- The value of the property if the getter was found
boost::any SurgSim::Framework::Accessible::getValue |
( |
const std::string & |
name | ) |
const |
Retrieves the value with the name by executing the getter if it is found.
- Exceptions
-
- Parameters
-
name | The name of the property. |
- Returns
- The value of the property if the getter was found
template<class T >
bool SurgSim::Framework::Accessible::getValue |
( |
const std::string & |
name, |
|
|
T * |
value |
|
) |
| const |
Retrieves the value with the name by executing the getter if it is found, and converts it to the type of the output parameter.
This does not throw.
- Template Parameters
-
T | the type of the property, usually can be deduced automatically |
- Parameters
-
| name | The name of the property. |
[out] | value | If non-null, will receive the value of the given property. |
- Returns
- true if value != nullptr and the getter can be found.
bool SurgSim::Framework::Accessible::isReadable |
( |
const std::string & |
name | ) |
const |
Check whether a property is readable.
- Parameters
-
name | Name of the property to be checked. |
- Returns
- true if the property exists and has a getter
bool SurgSim::Framework::Accessible::isWriteable |
( |
const std::string & |
name | ) |
const |
Check whether a property is writable.
- Parameters
-
name | Name of the property to be checked. |
- Returns
- true if the property exists and has a setter
Prevent default copy construction and default assignment
void SurgSim::Framework::Accessible::removeAccessors |
( |
const std::string & |
name | ) |
|
Removes all the accessors (getter and setter) for a given property.
- Parameters
-
name | The name of the property |
void SurgSim::Framework::Accessible::setAccessors |
( |
const std::string & |
name, |
|
|
GetterType |
getter, |
|
|
SetterType |
setter |
|
) |
| |
Sets the accessors getter and setter in one function.
- Exceptions
-
- Parameters
-
name | The name of the property. |
getter | The getter. |
setter | The setter. |
void SurgSim::Framework::Accessible::setGetter |
( |
const std::string & |
name, |
|
|
GetterType |
func |
|
) |
| |
Sets a getter for a given property.
- Exceptions
-
- Parameters
-
name | The name of the property. |
func | The getter function. |
void SurgSim::Framework::Accessible::setSerializable |
( |
const std::string & |
name, |
|
|
EncoderType |
encoder, |
|
|
DecoderType |
decoder |
|
) |
| |
Sets the functions used to convert data from and to a YAML::Node.
Will throw and exception if the data type that is passed to YAML cannot be converted into a YAML::Node
- Parameters
-
name | The name of the property. |
encoder | The function to be used to put the property into the node. |
decoder | The function to be used to read the property from the node and set it in the instance. |
void SurgSim::Framework::Accessible::setSetter |
( |
const std::string & |
name, |
|
|
SetterType |
func |
|
) |
| |
Sets a setter for a given property.
- Exceptions
-
- Parameters
-
name | The name of the property. |
func | The setter function. |
void SurgSim::Framework::Accessible::setValue |
( |
const std::string & |
name, |
|
|
const boost::any & |
value |
|
) |
| |
Sets a value of a property that has setter.
- Exceptions
-
- Parameters
-
name | The name of the property. |
value | The value that it should be set to. |
std::unordered_map<std::string, Functors> SurgSim::Framework::Accessible::m_functors |
|
private |
The documentation for this class was generated from the following files: