source: XMLIO_V2/dev/dev_rv/old/group_template.hpp @ 90

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

Ancienne Version de parsing.

File size: 4.3 KB
Line 
1#ifndef GROUP_TEMPLATE_HPP
2#define GROUP_TEMPLATE_HPP
3
4
5#include "object_template.hpp"
6#include "xmlio_std.hpp"
7
8template<typename CObject>
9class group  : public CObjectTemplate<group<CObject> >
10{
11  public :
12
13  CObject * defaultAttribut ;
14 
15  unordered_map<string,CObject *>* childListId ;
16  vector<CObject *>* childList ;
17 
18  unordered_map<string,group<CObject> *>* groupListId ;
19  vector<group<CObject> *>* groupList ;
20 
21  group(void) : CObjectTemplate< group<CObject> >() 
22  {
23    defaultAttribut=new CObject ;
24    childListId=new unordered_map<string,CObject *> ;
25    childList=new vector<CObject *> ;
26    groupListId=new unordered_map<string,group<CObject> *> ;
27    groupList=new vector<group<CObject> *> ;
28  }
29
30  group(const string Id) : CObjectTemplate< group<CObject> >(Id) 
31  {
32    defaultAttribut=new CObject ;
33    childListId=new unordered_map<string,CObject *> ;
34    childList=new vector<CObject *> ;
35    groupListId=new unordered_map<string,group<CObject> *> ;
36    groupList=new vector<group<CObject>*> ;
37  }
38 
39  CObject * getDefaultAttribut(void) {return defaultAttribut ;}
40 
41  bool foundChild(const string & Id) const 
42  {
43    if (childListId->find(Id)==childListId->end()) return false ;
44    else return true ;
45  }
46
47  CObject * getChild(const string & Id)
48  {
49    typename unordered_map<string,CObject*>::iterator It ;
50
51    It=childListId->find(Id) ;
52    if (It==childListId->end())
53    {
54      error("group<object>::getChild(const string & Id)")<<"Child <<"<<Id<<">> does not exist"<<endl ;
55      return 0 ;
56    }
57    else return It->second ;
58  }
59
60  CObject * getNewChild(void)
61  {
62    CObject * newChild=new CObject ;
63    childList->push_back(newChild) ;
64    return newChild ;
65  }
66
67
68  CObject* getNewChild(const string & Id)
69  {
70    CObject* newChild=new CObject(Id) ;
71   
72    pair<string,CObject *> value(Id,newChild) ;
73    if (childListId->insert(value).second) 
74    {
75      childList->push_back(newChild) ;
76      return newChild ;
77    }
78    else
79    {
80      error("group<object>::getNewChild(const string & Id)")<<"Child <<"<<Id<<">> is already present"<<endl ;
81      return 0 ;
82    }
83  }
84
85
86  CObject * getOrAppendChild(const string & Id)
87  {
88    if (foundChild(Id)) return getChild(Id) ;
89    else return getNewChild(Id) ;
90  }
91
92 
93  bool foundGroup(const string & Id) const
94  {
95    if (groupListId->find(Id)==groupListId->end()) return false ;
96    else return true ;
97  }
98 
99  group<CObject> * getGroup(const string & Id)
100  {
101    typename unordered_map<string,group<CObject>*>::iterator It ;
102
103    It=groupListId->find(Id) ;
104    if (It==groupListId->end())
105    {
106      error("group<object>::getGroup(const string & Id)")<<"Group <<"<<Id<<">> does not exist"<<endl ;
107      return 0 ;
108    }
109    else return It->second ;
110  }
111
112  group<CObject>* getNewGroup(void)
113  {
114    group<CObject> * newGroup=new group<CObject> ;
115    groupList->push_back(newGroup) ;
116    return newGroup ;
117  }
118
119
120  group<CObject>* getNewGroup(const string & Id)
121  {
122    group<CObject>* newGroup=new group<CObject>(Id) ;
123   
124    pair<string,group<CObject>*> value(Id,newGroup) ;
125    if (groupListId->insert(value).second)
126    {
127      groupList->push_back(newGroup) ;
128      return newGroup ;
129    }
130    else
131    {
132      error("group<object>::getNewGroup(const string & Id)")<<"Group <<"<<Id<<">> is already present"<<endl ;
133      return 0 ;
134    }
135  }
136
137
138  group<CObject> * getOrAppendGroup(const string & Id)
139  {
140    if (foundGroup(Id)) return getGroup(Id) ;
141    else return getNewGroup(Id) ;
142  }
143
144  static const char* getName(void) 
145  {
146    return (string("group_")+string(CObject::getName())).c_str() ;
147  }
148
149
150  ostream& Print(ostream& o)
151  {
152    typename vector<CObject *>::iterator it1 ;
153    typename vector<group<CObject> *>::iterator it2 ;
154   
155    o<<"Object :"<<getName()<<" : " ;
156    this->PrintId(o)<<inc_endl ;
157    this->PrintAttribut(o)<<iendl ;
158    o<<"Default Attribut"<<inc_endl ;
159    defaultAttribut->Print(o)<<dec_endl ;
160    o<<"Group "<<getName()<<IncIndent ;
161    for(it2=groupList->begin();it2!=groupList->end();it2++) 
162    {
163      o<<iendl ;
164      (*it2)->Print(o) ;
165    }
166    o<<DecIndent<<iendl ;
167    o<<"Child "<<CObject::getName()<<IncIndent ;
168    for(it1=childList->begin();it1!=childList->end();it1++) 
169    {
170      o<<iendl;
171      (*it1)->Print(o) ;
172    }
173    o<<DecIndent<<DecIndent ;
174    return o ;
175  }
176 
177  void Print(void)
178  {
179    Print(StdOut) ;
180  }
181 
182};
183
184
185
186#endif
Note: See TracBrowser for help on using the repository browser.