opensurgsim
|
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 <Accessible.h>
Public Member Functions | |
Accessible () | |
Default Constructor. | |
~Accessible () | |
Destructor. | |
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... | |
void | setDecoder (const std::string &name, DecoderType decoder) |
Sets the functions used to convert data from 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... | |
std::vector< std::string > | getProperties () |
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.
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.
SurgSim::Framework::AssertionFailure | if node is not of YAML::NodeType::Map. |
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.
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.
SurgSim::Framework::AssertionFailure | if the target does not contain the property named in this call. |
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. |
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.
SurgSim::Framework::AssertionFailure | If the conversion fails or the property cannot be found. |
T | The requested type for the property. |
name | The name of the property. |
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.
SurgSim::Framework::AssertionFailure | if the property cannot be found |
name | The name of the property. |
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.
T | the type of the property, usually can be deduced automatically |
name | The name of the property. | |
[out] | value | If non-null, will receive the value of the given property. |
bool SurgSim::Framework::Accessible::isReadable | ( | const std::string & | name | ) | const |
Check whether a property is readable.
name | Name of the property to be checked. |
bool SurgSim::Framework::Accessible::isWriteable | ( | const std::string & | name | ) | const |
Check whether a property is writable.
name | Name of the property to be checked. |
void SurgSim::Framework::Accessible::removeAccessors | ( | const std::string & | name | ) |
Removes all the accessors (getter and setter) for a given property.
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.
SurgSim::Framework::AssertionFailure | if either getter or setter is a nullptr. |
name | The name of the property. |
getter | The getter. |
setter | The setter. |
void SurgSim::Framework::Accessible::setDecoder | ( | const std::string & | name, |
DecoderType | decoder | ||
) |
Sets the functions used to convert data from a YAML::Node.
This leaves the encoder (class -> YAML) conversion empty, this can be used to let the user decide how to model the data in the data file, inside the class this should all result in one member to be created/changed.
name | The name of the property. |
decoder | The function to be used to read the property from the node and set it in the instance. |
void SurgSim::Framework::Accessible::setGetter | ( | const std::string & | name, |
GetterType | func | ||
) |
Sets a getter for a given property.
SurgSim::Framework::AssertionFailure | if func is a nullptr. |
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 an exception if the data type that is passed to YAML cannot be converted into a YAML::Node
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.
SurgSim::Framework::AssertionFailure | if func is a nullptr. |
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.
SurgSim::Framework::AssertionFailure | If the property cannot be found. |
name | The name of the property. |
value | The value that it should be set to. |