... #include <SugoiTools\cl_template_manager.h> //include the manager header file. ... int main() { ... //Create a manager //first template obj is the type of object we want to manage //second template obj is the type of value used to give unique ID to all managed objects //we have NULL argument, cause we are using a single manager without remote manager. SGE::CL_TEMPLATE_OBJECT_MANAGER<SGE::CL_BASE_OBJ<std::string>, std::string> * TestManager = new SGE::CL_TEMPLATE_OBJECT_MANAGER <SGE::CL_BASE_OBJ<std::string> >(NULL); //set a default obj?? //CL_BASE_OBJ<std::string> DftObj = TestManager->SetDefaultObj("default"); //Init default obj...?? //now our manager is ready to work ... }
SGE::CL_BASE_OBJ<std::string> * Obj = TestManager->AddObj("Existing Obj");
//equivalent to the first method, but with existing object. SGE::CL_BASE_OBJ<std::string> * Obj = new SGE::CL_BASE_OBJ<std::string> ("Existing Obj"); TestManager->AddObj(Obj);
SGE::CL_BASE_OBJ<std::string> * Obj = TestManager->Get("Existing Obj"); if (Obj) cout << "Object found" << endl; else cout << "Object not found" << endl;
Step One : Create the object you want to use with the manager.
You object class must herit from one of the following class CL_BASE_OBJ/CL_XML_BASE_OBJ/CL_XML_BASE_OBJ_file base class.
//Here is the definition of your object that use a string as main ID. //Using the CL_BASE_OBJ class. class CL_MyObjBase :pulic CL_BASE_OBJ<std::string> { protected: ...members... public: CL_MyObjBase(std::string _ID) //Default constructor with only one parameters, to be sure the object sis fully compatible with the generic manager :CL_BASE_OBJ<std::string>(_ID); { }; CL_MyObjBase(std::string _ID,...) //Other constructors :CL_BASE_OBJ<std::string>(_ID); { }; ~CL_MyObjBase(){}; }; //Using the CL_BASE_OBJ class. class CL_MyObjXML :pulic CL_XML_BASE_OBJ<std::string> { protected: ...members... public: CL_MyObjXML(std::string _ID) //Default constructor with only one parameters, to be sure the object it is fully compatible with the generic manager :CL_XML_BASE_OBJ<std::string>(_ID, "MyObjXMLTag") // "MyObjXMLTag" is the name of the XML tag corresponding to this object. { }; CL_MyObjXML(std::string _ID,...) //Other constructors :CL_XML_BASE_OBJ<std::string>(_ID, "MyObjXMLTag") { }; ~CL_MyObjXML(){}; //then you need to overload the 2 following XML functions: TiXmlElement* XMLSave (TiXmlElement* _XML_Root); TiXmlElement* XMLLoad (TiXmlElement* _XML_Root); //See the XML How to for more information on creating XML objects. };
Step Two : Create your manager.
Now you have to create a manager that herits from CL_TEMPLATE_OBJECT_MANAGER or CL_XML_MNGR.
//Here is the definition of your Manager. //Using the CL_BASE_OBJ class. class CL_MyObjBase_Mngr :pulic CL_TEMPLATE_OBJECT_MANAGER<CL_MyObjBase_Mngr, std::string> { public: CL_MyObjBase_Mngr(TplManager *_RemoteManager) //Default constructor. :CL_TEMPLATE_OBJECT_MANAGER<CL_MyObjBase_Mngr, std::string>(_RemoteManager); { }; ~CL_MyObjBase(){}; };
Here you have a manager that can manage...CL_MyObjBase_Mngr if (Obj) cout << "Object found" << endl; else cout << "Object not found" << endl;
If the object you are looking for is not found and you previously defined a default object, then the Get() function will return the default object.