source: XMLIO_V2/dev/dev_rv/xmlio_object_template.hpp @ 94

Last change on this file since 94 was 94, checked in by hozdoba, 13 years ago
File size: 2.6 KB
Line 
1#ifndef __XMLIO_OBJECT_TEMPLATE__
2#define __XMLIO_OBJECT_TEMPLATE__
3
4// Classes utilisées issues de la STL
5using std::pair;
6using std::string;
7using std::ostream;
8
9using XMLIOSERVER::StrHashMap;
10   
11namespace XMLIOSERVER
12{
13   template <class T>
14      class ObjectTemplate : public AbstractObject
15   {
16      public :
17         
18         static T& CreateObject(const string _id) throw (XMLIOUndefinedValueException) 
19         {
20            // Si l'identifiant est répertorié, on retourne l'élément existant.
21            if(ObjectTemplate<T>::HasObject(_id))
22               return (ObjectTemplate<T>::GetObject(_id));
23                             
24            // Ajout d'un nouvel objet si l'identifiant n'est pas répertorié.
25            T identified_object(_id);
26           
27            ObjectTemplate<T>::AllListObj[CurrContext].addObject(identified_object);
28            ObjectTemplate<T>::GetObject(_id).registerAllAttributes();
29           
30            return (ObjectTemplate<T>::GetObject(_id));
31         }
32         
33         static T& CreateObject(void)
34         {
35            ObjectTemplate<T>::AllListObj[CurrContext].addObject(*(new T)); //<< Perte mémoire ici
36            return (*(ObjectTemplate<T>::AllListObj[CurrContext].getVector()[ObjectTemplate<T>::AllListObj[CurrContext].getVectorSize()-1]));
37         }
38         
39         static T& GetObject(const string _id) throw (XMLIOUndefinedValueException)
40         { return (ObjectTemplate<T>::AllListObj[CurrContext][_id]); }
41         
42         static bool HasObject(const string _id)
43         { return (ObjectTemplate<T>::AllListObj[CurrContext].hasMappedValue(_id)); }
44         
45         static const StrHashMap<T> GetCurrentListObject(void) { return (AllListObj[CurrContext]); }
46               
47         static void SetContext(const string& id)
48         { ObjectTemplate<T>::CurrContext = id; } 
49         
50         virtual const char* getName(void) const {return ("ObjectTemplate"); }
51         
52         virtual ~ObjectTemplate(void)
53         {/* Ne rien faire de plus */}
54         
55      protected :
56     
57         ObjectTemplate(void) : AbstractObject()
58         {/* Ne rien faire de plus */}         
59         ObjectTemplate(const string& _id) : AbstractObject(_id) 
60         {/* Ne rien faire de plus */}
61         
62      private :
63         
64         static string CurrContext;
65         static HashMap<string, StrHashMap<T> > AllListObj;
66     
67   };// class ObjectTemplate
68   
69   template <class T> string ObjectTemplate<T>::CurrContext ;
70   template <class T> HashMap<string, StrHashMap<T> > ObjectTemplate<T>::AllListObj;
71   
72}// namespace XMLIOSERVER
73   
74#endif // __XMLIO_OBJECT_TEMPLATE__
Note: See TracBrowser for help on using the repository browser.