object config


Previous: Object model
Next: Object message

Objectif

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



Note:
	Using getter and setter is really better, and faster.

With a string configuration


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

whith the object name


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

Get Parameter


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

Implement configuration


#include <ewol/object/Object.h>
namespace appl {
	class MyObj : public ewol::Object {
		protected:
			//! @brief Constructor
			MyObj(void) :
			  m_value(*this, "value", false, "Value of the parameter (descrition string)") {
				// nothing to do..
			}
			void init() {
				ewol::Object::init();
			}
		public:
			//! @brief Destructor
			virtual ~MyObj(void) { }
			DECLARE_FACTORY(MyObj);
		private:
			ewol::object::Param<bool> m_value; //!< Internal Object value
		public:
			//! @brief Setter
			void setValue(bool _val) {
				m_value.set(_val);
			}
			//! @brief Getter
			bool getValue() const {
				return m_value.get();
			}
		public: // herited function:
			void onParameterChangeValue(const ewol::object::ParameterRef& _paramPointer) {
				if (_paramPointer == m_value) {
					APPL_DEBUG("The internal value has change, new value is : '" << m_value.get() << "'");
				}
			}
	}
}

In the contructor we need to add:
m_value(*this, "value", false, "Value of the parameter (descrition string)")

The function onParameterChangeValue is called only the parameter change (no historic has been registered)
The last point is that the m_value.get() is an inline fuction then it take no more CPU cycle to access the value than normal variable.
Some other parameter are availlable :