1 | #ifndef __XMLIO_GROUP_TEMPLATE__ |
---|
2 | #define __XMLIO_GROUP_TEMPLATE__ |
---|
3 | |
---|
4 | namespace XMLIOSERVER |
---|
5 | { |
---|
6 | template <class T> |
---|
7 | class GroupTemplate : public ObjectTemplate<GroupTemplate<T> > |
---|
8 | { |
---|
9 | public: |
---|
10 | |
---|
11 | GroupTemplate(void) : ObjectTemplate<GroupTemplate<T> >(), childList(), groupList() |
---|
12 | {/* Ne rien faire de plus */} |
---|
13 | GroupTemplate(const string& _id) : ObjectTemplate<GroupTemplate<T> >(_id), childList(), groupList() |
---|
14 | {/* Ne rien faire de plus */} |
---|
15 | |
---|
16 | virtual const char* getName(void) const {return ("GroupTemplate"); } |
---|
17 | |
---|
18 | /// Pour les groupes d'objets enfants /// |
---|
19 | |
---|
20 | GroupTemplate<T>& createGroup(const string _id) throw (XMLIOUndefinedValueException) |
---|
21 | { |
---|
22 | GroupTemplate<T>& obj = GroupTemplate<T>::CreateObject(_id); |
---|
23 | groupList.addPtrObject(&obj); |
---|
24 | return (obj); |
---|
25 | } |
---|
26 | |
---|
27 | GroupTemplate<T>& createGroup(void) |
---|
28 | { |
---|
29 | GroupTemplate<T>& obj = GroupTemplate<T>::CreateObject(); |
---|
30 | groupList.addPtrObject(&obj); |
---|
31 | return (obj); |
---|
32 | } |
---|
33 | |
---|
34 | GroupTemplate<T>& getGroup(const string _id) throw (XMLIOUndefinedValueException) { return (*groupList[_id]); } |
---|
35 | bool hasGroup(const string _id) { return (groupList.hasMappedValue(_id)); } |
---|
36 | |
---|
37 | const StrHashMap<GroupTemplate<T>* >& getGroupList(void) { return (groupList); } |
---|
38 | |
---|
39 | size_t getNbGroup() const {return (groupList.getVectorSize()); } |
---|
40 | |
---|
41 | /// Pour les objets enfants /// |
---|
42 | |
---|
43 | T& createChild(const string _id) throw (XMLIOUndefinedValueException) |
---|
44 | { |
---|
45 | T& obj = ObjectTemplate<T>::CreateObject(_id); |
---|
46 | childList.addPtrObject(&obj); |
---|
47 | return (obj); |
---|
48 | } |
---|
49 | |
---|
50 | T& createChild(void) |
---|
51 | { |
---|
52 | T& obj = ObjectTemplate<T>::CreateObject(); |
---|
53 | childList.addPtrObject(&obj); |
---|
54 | return (obj); |
---|
55 | } |
---|
56 | |
---|
57 | T& getChild(const string _id) throw (XMLIOUndefinedValueException) { return (*childList[_id]); } |
---|
58 | bool hasChild(const string _id) { return (childList.hasMappedValue(_id)); } |
---|
59 | |
---|
60 | const StrHashMap<T*>& getCurrentListChild(void) { return (childList); } |
---|
61 | |
---|
62 | size_t getNbChild() const {return (childList.getVectorSize()); } |
---|
63 | |
---|
64 | static bool CLASS_TEST(ostream& log = std::clog) |
---|
65 | { |
---|
66 | GroupTemplate<T> group; |
---|
67 | ///////////////////////////////////////// |
---|
68 | GroupTemplate<T>& group0 = group.createGroup("toto"); |
---|
69 | GroupTemplate<T>& group1 = group.createGroup(); |
---|
70 | T& child0 = group.createChild("toto"); |
---|
71 | T& child1 = group.createChild(); |
---|
72 | log << "Nombre de (groupes) enfants : " << group.getNbChild() << "/" << group.getNbGroup() << " (2/2 attendu)" << std::endl; |
---|
73 | ///////////////////////////////////////// |
---|
74 | log << "Test GroupTemplate ... ok !" << std::endl; |
---|
75 | return (true); |
---|
76 | }; |
---|
77 | |
---|
78 | |
---|
79 | ~GroupTemplate() |
---|
80 | {/* Ne rien faire de plus pour le moment */ } |
---|
81 | |
---|
82 | protected: |
---|
83 | |
---|
84 | private: |
---|
85 | StrHashMap<T*> childList; |
---|
86 | StrHashMap<GroupTemplate<T>* > groupList; |
---|
87 | |
---|
88 | }; // class GroupTemplate |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | }// namespace XMLIOSERVER |
---|
93 | |
---|
94 | |
---|
95 | #endif // __XMLIO_GROUP_TEMPLATE__ |
---|