2016-09-16 22:35:06 +02:00
EWOL: Object config {#ewol_tutorial_object_config }
===================
@tableofcontents
2014-09-09 21:15:50 +02:00
2016-09-16 22:35:06 +02:00
Objectifs: {#ewol_tutorial_object_config_objectives }
2016-09-15 22:43:04 +02:00
==========
2016-09-16 22:35:06 +02:00
- Understand base of [e-property ](http://atria-soft.github.io/eproperty ) configuration parameter
- Create an configurable object
2014-03-04 21:18:41 +01:00
2016-09-16 22:35:06 +02:00
Configuration using {#ewol_tutorial_object_configusing }
2016-09-15 22:43:04 +02:00
===================
2014-03-04 21:18:41 +01:00
2016-09-16 22:35:06 +02:00
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.
2014-03-04 21:18:41 +01:00
2016-09-16 22:35:06 +02:00
Set a Parameter/Property {#ewol_tutorial_object_config_prop }
2016-09-15 22:43:04 +02:00
------------------------
2014-03-04 21:18:41 +01:00
2016-09-16 22:35:06 +02:00
**Note:**
```
Parameter is managed by the [e-property ](http://atria-soft.github.io/eproperty )
```
2014-03-04 21:18:41 +01:00
2016-09-15 22:43:04 +02:00
With a string configuration
***************************
2014-03-04 21:18:41 +01:00
2016-09-16 22:35:06 +02:00
```{.cpp}
if (tmpObject->properties.set("name", "new name of object") == false) {
2014-09-02 21:26:15 +02:00
APPL_ERROR("Can not set object parameter");
2014-03-04 21:18:41 +01:00
}
2016-09-16 22:35:06 +02:00
```
2014-03-04 21:18:41 +01:00
2016-09-15 22:43:04 +02:00
whith the object name
*********************
2014-03-04 21:18:41 +01:00
2016-09-16 22:35:06 +02:00
```{.cpp}
if (ewol::propertySetOnObjectNamed("objectName", "value", "16.2") == false) {
2014-09-02 21:26:15 +02:00
APPL_ERROR("Can not set object parameter");
2014-03-04 21:18:41 +01:00
}
2016-09-16 22:35:06 +02:00
```
2014-03-04 21:18:41 +01:00
2016-09-16 22:35:06 +02:00
Get Parameter {#ewol_tutorial_object_config_param }
2016-09-15 22:43:04 +02:00
-------------
2014-03-04 21:18:41 +01:00
2016-09-16 22:35:06 +02:00
```{.cpp}
2017-09-14 00:59:21 +02:00
etk::String val = tmpObject->properties.get("name");
2016-09-16 22:35:06 +02:00
APPL_INFO("Get Object property: name='" < < val < < " ' " ) ;
```
2014-03-04 21:18:41 +01:00
2016-09-16 22:35:06 +02:00
Implement configuration {#ewol_tutorial_object_config_impl }
2016-09-15 22:43:04 +02:00
=======================
2014-03-04 21:18:41 +01:00
2016-09-16 22:35:06 +02:00
```{.cpp}
2016-10-02 23:49:03 +02:00
#include <ewol/object/Object.hpp>
2014-03-04 21:18:41 +01:00
namespace appl {
class MyObj : public ewol::Object {
2016-03-23 21:44:32 +01:00
public:
eproperty::Value< bool > propertyValue; //!< Property interface ( all time start with " property " )
2014-09-02 21:26:15 +02:00
protected:
2014-03-04 21:18:41 +01:00
//! @brief Constructor
2014-09-02 21:26:15 +02:00
MyObj(void) :
2016-03-23 21:44:32 +01:00
propertyValue(this, "value",
false,
"Value of the parameter (descrition string)",
& appl::MyObj::onChangeParameterValue) {
2014-09-02 21:26:15 +02:00
// nothing to do..
}
void init() {
ewol::Object::init();
2016-03-23 21:44:32 +01:00
// do some stuff with the init value
2014-09-02 21:26:15 +02:00
}
public:
2014-03-04 21:18:41 +01:00
//! @brief Destructor
2014-09-02 21:26:15 +02:00
virtual ~MyObj(void) { }
DECLARE_FACTORY(MyObj);
2014-03-04 21:18:41 +01:00
public:
2016-03-23 21:44:32 +01:00
void onChangeParameterValue() {
APPL_DEBUG("The internal value has change, new value is : '" < < *m_value < < "'");
2014-09-02 21:26:15 +02:00
}
2014-03-04 21:18:41 +01:00
}
}
2016-09-16 22:35:06 +02:00
```
2014-03-04 21:18:41 +01:00
2014-09-02 21:26:15 +02:00
In the contructor we need to add:
2016-09-16 22:35:06 +02:00
```{.cpp}
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.
2014-03-04 21:18:41 +01:00
2014-09-02 21:26:15 +02:00
Some other parameter are availlable :
2016-09-16 22:35:06 +02:00
- 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.
2014-03-04 21:18:41 +01:00
2016-09-16 22:35:06 +02:00
For more information see [e-property ](http://atria-soft.github.io/eproperty )
2014-03-04 21:18:41 +01:00