source: XMLIO_V2/dev/trunk/src/XMLIO/xmlio_group_template.hpp @ 103

Last change on this file since 103 was 98, checked in by ymipsl, 14 years ago
File size: 3.0 KB
Line 
1#ifndef __XMLIO_GROUP_TEMPLATE__
2#define __XMLIO_GROUP_TEMPLATE__
3
4namespace XMLIOSERVER
5{
6   template <class T, class U>
7      class GroupTemplate : public ObjectTemplate<GroupTemplate<T, U> >, public U
8   {
9      public:
10           
11         GroupTemplate(void) : ObjectTemplate<GroupTemplate<T, U> >(),  U(), childList(), groupList()
12         {/* Ne rien faire de plus */}               
13         GroupTemplate(const string& _id) : ObjectTemplate<GroupTemplate<T, U> >(_id), U(), 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, U>& createGroup(const string _id) throw (XMLIOUndefinedValueException) 
21         {
22            GroupTemplate<T, U> &obj = GroupTemplate<T, U>::CreateObject(_id);
23            groupList.addObject(&obj);
24             
25            return (GroupTemplate<T, U>::GetObject(_id));
26         }
27         
28         GroupTemplate<T, U>& createGroup(void)
29         {
30            GroupTemplate<T, U>& obj = GroupTemplate<T, U>::CreateObject();
31            groupList.addObject(&obj);
32                     
33            return (obj);
34         }
35         
36         GroupTemplate<T, U>& getGroup(const string _id) throw (XMLIOUndefinedValueException) { return (*groupList[_id]); }
37         bool hasGroup(const string _id) { return (groupList.hasMappedValue(_id)); }
38         
39         const StrHashMap<GroupTemplate<T, U>* >& getGroupList(void) { return (groupList); }
40         
41         size_t getNbGroup() const {return (groupList.getVectorSize()); }
42         
43         /// Pour les objets enfants ///
44         
45         T& createChild(const string _id) throw (XMLIOUndefinedValueException) 
46         {
47            T& obj = ObjectTemplate<T>::CreateObject(_id);
48            childList.addObject(&obj);
49            return (obj);
50         }
51         
52         T& createChild(void)
53         {
54            T& obj = ObjectTemplate<T>::CreateObject();
55            childList.addObject(&obj);           
56            return (obj);
57         }         
58         
59         T& getChild(const string _id) throw (XMLIOUndefinedValueException) { return (*childList[_id]); }
60         bool hasChild(const string _id) { return (childList.hasMappedValue(_id)); }
61         
62         const StrHashMap<T*>& getCurrentListChild(void) { return (childList); }
63         
64         size_t getNbChild() const {return (childList.getVectorSize()); }
65           
66       
67         virtual ~GroupTemplate()
68         {
69            for (unsigned int i = 0; i < childList.getVector().size(); i++)
70               delete childList.getVector()[i];
71            for (unsigned int i = 0; i < groupList.getVector().size(); i++)
72               delete groupList.getVector()[i];
73         }
74         
75      protected:
76     
77      private:
78         StrHashMap<T> childList;
79         StrHashMap<GroupTemplate<T, U> > groupList;
80
81   }; // class GroupTemplate
82   
83   
84   
85}// namespace XMLIOSERVER
86
87
88#endif // __XMLIO_GROUP_TEMPLATE__
Note: See TracBrowser for help on using the repository browser.