EWOL: Object config

Constructor MyObj(void) : propertyValue(this, "value", false, "Value of the parameter (descrition string)", &appl::MyObj::onChangeParameterValue) { // nothing to do.. } void init() { ewol::Object::init(); // do some stuff with the init value } public: //!

Objectifs:

  • Understand base of e-property configuration parameter
  • Create an configurable object

Configuration using

All ewol::Object have a configuration of parameters (the object name is a parameter), then we need to set get and use xml to update parameters.

Set a Parameter/Property

Note:

Parameter is managed by the [e-property](http://atria-soft.github.io/eproperty)

With a string configuration


if (tmpObject->properties.set("name", "new name of object") == false) {
APPL_ERROR("Can not set object parameter");
}

whith the object name


if (ewol::propertySetOnObjectNamed("objectName", "value", "16.2") == false) {
APPL_ERROR("Can not set object parameter");
}

Get Parameter

std::string val = tmpObject->properties.get("name");
APPL_INFO("Get Object property: name='" << val << "'");

Implement configuration

namespace appl {
class MyObj : public ewol::Object {
public:
eproperty::Value<bool> propertyValue;
protected:
virtual ~MyObj(void) { }
DECLARE_FACTORY(MyObj);
public:
void onChangeParameterValue() {
APPL_DEBUG("The internal value has change, new value is : '" << *m_value << "'");
}
}
}

In the contructor we need to add:

propertyValue(this,
"value",
false,
"Value of the parameter (descrition string)",
&appl::MyObj::onChangeParameterValue)
  • **'this':** Pointer the main class to call it chen value change.
  • **"value":** Is the name of the parameter.
  • false: The default value.
  • **"....."** Description of the parameter (optionnal).
  • **&appl::MyObj::onChangeParameterValue** The callback when the value change (optionnal).

The last point is that the *propertyValue same as propertyValue.get() are inline fuction then it take no more CPU cycle to access the value than normal variable.

Some other parameter are availlable :

  • eproperty::Value<T> Basic parameter.
  • eproperty::Range<T> For numeric parameter that range value are check befor setting new value.
  • eproperty::List<T> For List of parameter values.

For more information see e-property