object model


Previous: Hello word
Next: Object config

Objectif

Basis of the ewol::Object


An object in Ewol is a simple class : ewol::Object This object is the basis of all element in the ewol system. This is designed to manage many common things:

Note:
Please do not compare with the gObject basic class...

Create an Object:


Creating an object is really simple:
	std::shared_ptr<ewol::Button> tmpButon = ewol::Button::create();
	APPL_INFO("We just create a button widget with unique ID=" << tmpButon->getId() << " name='" << tmpButon->getName() << "'");

Note that all object created are std::shared_ptr.
Set the name of the object:
	tmpButon->setName("my widget name");
	APPL_INFO("We just create an Object with ID=" << tmpButon->getId() << " name='" << tmpButon->getName() << "'");

Remove an Object:


Simply use the function:
	tmpButon->destroy();

This function request his parrent to remove the std::shared_ptr it keep on it. And when all std::shared_ptr is removed the object will be really removed.
At his point we can think an object is allive all the time someone keep a reference on it, then when you are not a parrent of the object, do not keep a std::shared_ptr but a std::weak_ptr.

Note:
If some Object is not removed when you close the application, the system inform you with displaying all object already alive.

Retrieve an Object:


In Ewol this is possible to get a object with his name.

Find a global Object (ouside an Object)


	#include <ewol/context/Context.h>
	
	std::shared_ptr<ewol::Object> tmpObject = ewol::getContext().getEObjectManager().getObjectNamed("obj Name");
	if (tmpObject == NULL) {
		APPL_ERROR("The Object does not exist");
	}

Find a global Object (inside an Object)


	std::shared_ptr<ewol::Object> tmpObject = getObjectNamed("obj Name");
	if (tmpObject == NULL) {
		APPL_ERROR("The Object does not exist");
	}

Find a sub-object


	std::shared_ptr<ewol::Object> tmpObject = getSubObjectNamed("obj Name");
	if (tmpObject == NULL) {
		APPL_ERROR("The Object does not exist");
	}

retriving your object type


It could be really interesting to retrive your own instance:
	std::shared_ptr<ewol::Object> tmpObject ...;
	
	std::shared_ptr<appl::MyOwnObject> myObject = std::dynamic_pointer_cast<appl::MyOwnObject>(tmpObject);

conclusion


TODO ...