resources


Previous: File access
Next: Conplexe xml gui

Objectifs

What is a resource:


A resource is an usique element that can be used by manny element like: A resource have an other objective, form some platform, the graphic interface can be stopped, then we need to reload texture in the graphic inteface... Then the texture is an other graphic interface.

Get a resource:


For this example we will load a configuration file:
#include <ewol/object/Object.h>
#include <ewol/resource/ConfigFile.h>
namespace appl {
	class MyObj : public ewol::Object {
		private:
			std::shared_ptr<ewol::resource::ConfigFile> m_config;
			int32_t m_configValId;
		protected:
			//! @brief Constructor
			MyObj(void) :
			  m_configValId(-1) {
				// nothing to do..
			}
			void init() {
				ewol::Object::init();
				m_config = ewol::resource::ConfigFile::create("DATA:ExapleConfig.json");
				m_configValId = m_config->request("exampleConfigName");
			}
		public:
			//! @brief Destructor
			virtual ~MyObj(void) { }
			DECLARE_FACTORY(MyObj);
		public:
			void process() {
				double value = m_config->getNumber(m_configValId);
				APPL_DEBUG("example value : " << value);
			}
	}
}

Create a new resource:


A resource is a generic ewol::Resource that hrited form a generic ewol::Object, simply change the FACTORY macro in : we have now some specific interface to compleate (if needed):

The Resource Level


The resources can be reloaded, then we need to reaload in the good order (level [0 .. 5])
The resources are loaded fron 0 to 5.
Then for basic resource :
#include <ewol/object/Resource.h>
namespace appl {
	class MyResource : public ewol::Resource {
		protected:
			//! @brief Constructor
			MyResource() :
			  m_configValId(-1) {
				m_resourceLevel = 4;
				addObjectType("ewol::MyResource");
			}
			void init(const std::& _name) {
				ewol::Resource::init(_name);
			}
		public:
			//! @brief Destructor
			virtual ~MyResource(void) { }
			DECLARE_RESOURCE_NAMED_FACTORY(MyResource);
	}
}

Now we need to implement somme functions:
To send data on the hardware (openGL):
	void updateContext();

To remove data from the the hardware (openGL):
	void removeContext();

When loose hardware (juste update internal state):
	void removeContextToLate();

When user request to reload all resources (can be usefull when using file type : THEME:GUI:xxx)
	void reload();