1 | #ifndef __XMLIO_OBJECT_TEMPLATE__ |
---|
2 | #define __XMLIO_OBJECT_TEMPLATE__ |
---|
3 | |
---|
4 | // Classes utilisées issues de la STL |
---|
5 | using std::pair; |
---|
6 | using std::string; |
---|
7 | using std::ostream; |
---|
8 | |
---|
9 | using XMLIOSERVER::StrHashMap; |
---|
10 | |
---|
11 | namespace 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)// << Bug |
---|
41 | { return (ObjectTemplate<T>::AllListObj[CurrContext].hasMappedValue(_id)); } |
---|
42 | |
---|
43 | static const StrHashMap<T>& GetCurrentListObject(void) { return (AllListObj[CurrContext]); } |
---|
44 | static HashMap<string, StrHashMap<T> >& GetAllListObject(void) { return (AllListObj); } |
---|
45 | |
---|
46 | static void SetContext(const string& id){ ObjectTemplate<T>::CurrContext = id; } |
---|
47 | |
---|
48 | static string& GetCurrentContextId(void) { return (CurrContext); } |
---|
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__ |
---|