HowTo use CL_TEMPLATE_MNGR?

In this section we will describe why and how to use the SGE::CL_TEMPLATE_OBJECT_MANAGER class.

How to create a manager?

Before creating you manager, there is a few important questions to answer:
Here is a small exemple on how to create a simple manager of SGE::CL_BASE_OBJ<std::string> :
 ...
 #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
                    ...
 }


How to add objects to your manager?

There is two way to add an object to your manager:

How to retrieve objects from your manager?

To retrieve an object from the manager, just ask for it :
          SGE::CL_BASE_OBJ<std::string> * Obj = TestManager->Get("Existing Obj");
          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.

Why and How to use the remote manager facilities?

You can affect a remote CL_TEMPLATE_OBJECT_MANAGER<> manager to your local CL_TEMPLATE_OBJECT_MANAGER<> when you create it. When you do so, your managers will have the following behaviors when you access le local one:

This means :
=> The local manager acts as a cache for the remote one, so you can access quickly some of your shared data.

How to create your own manager?

SGE::CL_TEMPLATE_OBJECT_MANAGER is a generic manager, so you will sometime need to create your own manager to deal with your own XML objects. Here is the few steps you need to follow.

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.


Generated on Mon Mar 19 23:15:11 2007 for SugoiTools by  doxygen 1.4.6-NO