source: XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_object_template.hpp @ 104

Last change on this file since 104 was 104, checked in by hozdoba, 14 years ago

Prise en charge de l'héritage descendant.
Travail sur les flux de sortie.
Correction de divers problÚmes.
Ajout d'une macro à BaseAttribut?.

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            ObjectTemplate<T>::AllListObj[CurrContext].addObject(new T(_id));
26           
27            return (ObjectTemplate<T>::GetObject(_id));
28         }
29         
30         static T& CreateObject(void)
31         {
32            T* value = new T;
33            ObjectTemplate<T>::AllListObj[CurrContext].addObject(value);
34            return (*value);
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         {
42            if(ObjectTemplate<T>::AllListObj.find(CurrContext) == ObjectTemplate<T>::AllListObj.end()) return false;
43            return (ObjectTemplate<T>::AllListObj[CurrContext].hasMappedValue(_id));
44         }
45         
46         static const StrHashMap<T>& GetCurrentListObject(void) { return (AllListObj[CurrContext]); }
47         static HashMap<string, StrHashMap<T> >& GetAllListObject(void) { return (AllListObj); }
48               
49         static void SetContext(const string& id){ ObjectTemplate<T>::CurrContext = id; } 
50         
51         static string& GetCurrentContextId(void) { return (CurrContext); } 
52         
53         virtual ~ObjectTemplate(void)
54         {/* Ne rien faire de plus */}
55         
56      protected :
57     
58         ObjectTemplate(void) : AbstractObject()
59         {/* Ne rien faire de plus */}         
60         ObjectTemplate(const string& _id) : AbstractObject(_id) 
61         {/* Ne rien faire de plus */}
62         
63      private :
64         
65         static string CurrContext;
66         static HashMap<string, StrHashMap<T> > AllListObj;
67     
68   };// class ObjectTemplate
69   
70   template <class T> string ObjectTemplate<T>::CurrContext ;
71   template <class T> HashMap<string, StrHashMap<T> > ObjectTemplate<T>::AllListObj;
72   
73}// namespace XMLIOSERVER
74   
75#endif // __XMLIO_OBJECT_TEMPLATE__
Note: See TracBrowser for help on using the repository browser.