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

Last change on this file since 91 was 91, checked in by hozdoba, 13 years ago

Corrections de plusieurs problÚmes.

File size: 2.5 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            ObjectTemplate<T>::AllListObj[CurrContext].addObject(identified_object);
27            ObjectTemplate<T>::GetObject(_id).registerAllAttributes();
28            return (ObjectTemplate<T>::GetObject(_id));
29         }
30         
31         static T& CreateObject(void)
32         {
33            ObjectTemplate<T>::CurrListObj.addObject(*(new T)); //<< Perte mémoire ici
34            return (*(ObjectTemplate<T>::CurrListObj.getVector()[ObjectTemplate<T>::CurrListObj.getVectorSize()-1]));
35         }
36         
37         static T& GetObject(const string _id) throw (XMLIOUndefinedValueException)
38         { return (ObjectTemplate<T>::AllListObj[CurrContext][_id]); }
39         
40         static bool HasObject(const string _id)
41         { return (ObjectTemplate<T>::AllListObj[CurrContext].hasMappedValue(_id)); }
42         
43         static const StrHashMap<T> GetCurrentListObject(void) { return (AllListObj[CurrContext]); }
44               
45         static void SetContext(const string& id)
46         { ObjectTemplate<T>::CurrContext = id; } 
47         
48         virtual const char* getName(void) const {return ("ObjectTemplate"); }
49         
50         virtual ~ObjectTemplate(void)
51         {/* Ne rien faire de plus */}
52         
53      protected :
54     
55         ObjectTemplate(void) : AbstractObject()
56         {/* Ne rien faire de plus */}         
57         ObjectTemplate(const string& _id) : AbstractObject(_id) 
58         {/* Ne rien faire de plus */}
59         
60      private :
61         
62         static string CurrContext;
63         static HashMap<string, StrHashMap<T> > AllListObj;
64     
65   };// class ObjectTemplate
66   
67   template <class T> string ObjectTemplate<T>::CurrContext ;
68   template <class T> HashMap<string, StrHashMap<T> > ObjectTemplate<T>::AllListObj;
69   
70}// namespace XMLIOSERVER
71   
72#endif // __XMLIO_OBJECT_TEMPLATE__
Note: See TracBrowser for help on using the repository browser.