1 | #ifndef __XMLIO_CGroupTemplate_impl__ |
---|
2 | #define __XMLIO_CGroupTemplate_impl__ |
---|
3 | |
---|
4 | namespace xmlioserver |
---|
5 | { |
---|
6 | using namespace tree; |
---|
7 | |
---|
8 | /// ////////////////////// Définitions ////////////////////// /// |
---|
9 | |
---|
10 | template <class U, class V, class W> |
---|
11 | CGroupTemplate<U, V, W>::CGroupTemplate(void) |
---|
12 | : CObjectTemplate<V>() //, V() |
---|
13 | , childMap(), childList() |
---|
14 | , groupMap(), groupList() |
---|
15 | { /* Ne rien faire de plus */ } |
---|
16 | |
---|
17 | template <class U, class V, class W> |
---|
18 | CGroupTemplate<U, V, W>::CGroupTemplate(const StdString & id) |
---|
19 | : CObjectTemplate<V>(id) //, V() |
---|
20 | , childMap(), childList() |
---|
21 | , groupMap(), groupList() |
---|
22 | { /* Ne rien faire de plus */ } |
---|
23 | |
---|
24 | template <class U, class V, class W> |
---|
25 | CGroupTemplate<U, V, W>::~CGroupTemplate(void) |
---|
26 | { /* Ne rien faire de plus */ } |
---|
27 | |
---|
28 | ///-------------------------------------------------------------- |
---|
29 | |
---|
30 | template <class U, class V, class W> |
---|
31 | void CGroupTemplate<U, V, W>::toBinary(StdOStream & os) const |
---|
32 | { |
---|
33 | SuperClass::toBinary(os); |
---|
34 | |
---|
35 | const StdSize grpnb = this->groupList.size(); |
---|
36 | const StdSize chdnb = this->childList.size(); |
---|
37 | tree::ENodeType cenum = U::GetType(); |
---|
38 | tree::ENodeType genum = V::GetType(); |
---|
39 | |
---|
40 | os.write (reinterpret_cast<const char*>(&grpnb) , sizeof(StdSize)); |
---|
41 | os.write (reinterpret_cast<const char*>(&chdnb) , sizeof(StdSize)); |
---|
42 | |
---|
43 | typename std::vector<boost::shared_ptr<V> >::const_iterator |
---|
44 | itg = this->groupList.begin(), endg = this->groupList.end(); |
---|
45 | typename std::vector<boost::shared_ptr<U> >::const_iterator |
---|
46 | itc = this->childList.begin(), endc = this->childList.end(); |
---|
47 | |
---|
48 | for (; itg != endg; itg++) |
---|
49 | { |
---|
50 | boost::shared_ptr<V> group = *itg; |
---|
51 | bool hid = group->hasId(); |
---|
52 | |
---|
53 | os.write (reinterpret_cast<const char*>(&genum), sizeof(tree::ENodeType)); |
---|
54 | os.write (reinterpret_cast<const char*>(&hid), sizeof(bool)); |
---|
55 | |
---|
56 | if (hid) |
---|
57 | { |
---|
58 | const StdString & id = group->getId(); |
---|
59 | const StdSize size = id.size(); |
---|
60 | |
---|
61 | os.write (reinterpret_cast<const char*>(&size), sizeof(StdSize)); |
---|
62 | os.write (id.data(), size * sizeof(char)); |
---|
63 | } |
---|
64 | group->toBinary(os); |
---|
65 | } |
---|
66 | |
---|
67 | for (; itc != endc; itc++) |
---|
68 | { |
---|
69 | boost::shared_ptr<U> child = *itc; |
---|
70 | bool hid = child->hasId(); |
---|
71 | |
---|
72 | os.write (reinterpret_cast<const char*>(&cenum), sizeof(tree::ENodeType)); |
---|
73 | os.write (reinterpret_cast<const char*>(&hid), sizeof(bool)); |
---|
74 | |
---|
75 | if (hid) |
---|
76 | { |
---|
77 | const StdString & id = child->getId(); |
---|
78 | const StdSize size = id.size(); |
---|
79 | |
---|
80 | os.write (reinterpret_cast<const char*>(&size), sizeof(StdSize)); |
---|
81 | os.write (id.data(), size * sizeof(char)); |
---|
82 | } |
---|
83 | child->toBinary(os); |
---|
84 | } |
---|
85 | |
---|
86 | } |
---|
87 | |
---|
88 | template <class U, class V, class W> |
---|
89 | void CGroupTemplate<U, V, W>::fromBinary(StdIStream & is) |
---|
90 | { |
---|
91 | SuperClass::fromBinary(is); |
---|
92 | |
---|
93 | boost::shared_ptr<V> group_ptr = (this->hasId()) |
---|
94 | ? CObjectFactory::GetObject<V>(this->getId()) |
---|
95 | : CObjectFactory::GetObject(boost::polymorphic_downcast<V*>(this)); |
---|
96 | |
---|
97 | StdSize grpnb = 0; |
---|
98 | StdSize chdnb = 0; |
---|
99 | tree::ENodeType renum = Unknown; |
---|
100 | |
---|
101 | is.read (reinterpret_cast<char*>(&grpnb), sizeof(StdSize)); |
---|
102 | is.read (reinterpret_cast<char*>(&chdnb), sizeof(StdSize)); |
---|
103 | |
---|
104 | for (StdSize i = 0; i < grpnb; i++) |
---|
105 | { |
---|
106 | bool hid = false; |
---|
107 | is.read (reinterpret_cast<char*>(&renum), sizeof(tree::ENodeType)); |
---|
108 | is.read (reinterpret_cast<char*>(&hid), sizeof(bool)); |
---|
109 | |
---|
110 | if (renum != V::GetType()) |
---|
111 | ERROR("CGroupTemplate<U, V, W>::fromBinary(StdIStream & is)", |
---|
112 | << "[ renum = " << renum << "] Bad type !"); |
---|
113 | |
---|
114 | if (hid) |
---|
115 | { |
---|
116 | StdSize size = 0; |
---|
117 | is.read (reinterpret_cast<char*>(&size), sizeof(StdSize)); |
---|
118 | StdString id(size, ' '); |
---|
119 | is.read (const_cast<char *>(id.data()), size * sizeof(char)); |
---|
120 | CGroupFactory::CreateGroup(group_ptr, id)->fromBinary(is); |
---|
121 | } |
---|
122 | else |
---|
123 | { |
---|
124 | CGroupFactory::CreateGroup(group_ptr)->fromBinary(is); |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | for (StdSize j = 0; j < chdnb; j++) |
---|
129 | { |
---|
130 | bool hid = false; |
---|
131 | is.read (reinterpret_cast<char*>(&renum), sizeof(tree::ENodeType)); |
---|
132 | is.read (reinterpret_cast<char*>(&hid), sizeof(bool)); |
---|
133 | |
---|
134 | if (renum != U::GetType()) |
---|
135 | ERROR("CGroupTemplate<U, V, W>::fromBinary(StdIStream & is)", |
---|
136 | << "[ renum = " << renum << "] Bad type !"); |
---|
137 | |
---|
138 | if (hid) |
---|
139 | { |
---|
140 | StdSize size = 0; |
---|
141 | is.read (reinterpret_cast<char*>(&size), sizeof(StdSize)); |
---|
142 | StdString id(size, ' '); |
---|
143 | is.read (const_cast<char *>(id.data()), size * sizeof(char)); |
---|
144 | CGroupFactory::CreateChild(group_ptr, id)->fromBinary(is); |
---|
145 | } |
---|
146 | else |
---|
147 | { |
---|
148 | CGroupFactory::CreateChild(group_ptr)->fromBinary(is); |
---|
149 | } |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | //-------------------------------------------------------------- |
---|
154 | |
---|
155 | template <class U, class V, class W> |
---|
156 | StdString CGroupTemplate<U, V, W>::toString(void) const |
---|
157 | { |
---|
158 | StdOStringStream oss; |
---|
159 | StdString name = (this->getId().compare(V::GetDefName()) != 0) |
---|
160 | ? V::GetName() : V::GetDefName(); |
---|
161 | |
---|
162 | oss << "<" << name << " "; |
---|
163 | if (this->hasId() && (this->getId().compare(V::GetDefName()) != 0)) |
---|
164 | oss << " id=\"" << this->getId() << "\" "; |
---|
165 | |
---|
166 | if (this->hasChild()) |
---|
167 | { |
---|
168 | oss << SuperClassAttribute::toString() << ">" << std::endl; |
---|
169 | |
---|
170 | typename std::vector<boost::shared_ptr<V> >::const_iterator |
---|
171 | itg = this->groupList.begin(), endg = this->groupList.end(); |
---|
172 | typename std::vector<boost::shared_ptr<U> >::const_iterator |
---|
173 | itc = this->childList.begin(), endc = this->childList.end(); |
---|
174 | |
---|
175 | for (; itg != endg; itg++) |
---|
176 | { |
---|
177 | boost::shared_ptr<V> group = *itg; |
---|
178 | oss << *group << std::endl; |
---|
179 | } |
---|
180 | |
---|
181 | for (; itc != endc; itc++) |
---|
182 | { |
---|
183 | boost::shared_ptr<U> child = *itc; |
---|
184 | oss << *child << std::endl; |
---|
185 | } |
---|
186 | |
---|
187 | oss << "</" << name << " >"; |
---|
188 | } |
---|
189 | else |
---|
190 | { |
---|
191 | oss << SuperClassAttribute::toString() << "/>"; |
---|
192 | } |
---|
193 | return (oss.str()); |
---|
194 | } |
---|
195 | |
---|
196 | template <class U, class V, class W> |
---|
197 | void CGroupTemplate<U, V, W>::fromString(const StdString & str) |
---|
198 | { |
---|
199 | ERROR("CGroupTemplate<U, V, W>::toString(void)", |
---|
200 | << "[ str = " << str << "] Not implemented yet !"); |
---|
201 | } |
---|
202 | |
---|
203 | //--------------------------------------------------------------- |
---|
204 | |
---|
205 | template <class U, class V, class W> |
---|
206 | StdString CGroupTemplate<U, V, W>::GetName(void) |
---|
207 | { |
---|
208 | return (U::GetName().append("_group")); |
---|
209 | } |
---|
210 | |
---|
211 | template <class U, class V, class W> |
---|
212 | StdString CGroupTemplate<U, V, W>::GetDefName(void) |
---|
213 | { |
---|
214 | return (U::GetName().append("_definition")); |
---|
215 | } |
---|
216 | |
---|
217 | //--------------------------------------------------------------- |
---|
218 | |
---|
219 | template <class U, class V, class W> |
---|
220 | const std::vector<boost::shared_ptr<U> >& |
---|
221 | CGroupTemplate<U, V, W>::getChildList(void) const |
---|
222 | { |
---|
223 | return (this->childList); |
---|
224 | } |
---|
225 | |
---|
226 | //--------------------------------------------------------------- |
---|
227 | |
---|
228 | template <class U, class V, class W> |
---|
229 | const xios_map<StdString, boost::shared_ptr<V> >& |
---|
230 | CGroupTemplate<U, V, W>::getGroupMap(void) const |
---|
231 | { |
---|
232 | return (this->groupList); |
---|
233 | } |
---|
234 | |
---|
235 | //--------------------------------------------------------------- |
---|
236 | |
---|
237 | template <class U, class V, class W> |
---|
238 | bool CGroupTemplate<U, V, W>::hasChild(void) const |
---|
239 | { |
---|
240 | return ((groupList.size() + childList.size()) > 0); |
---|
241 | } |
---|
242 | |
---|
243 | //--------------------------------------------------------------- |
---|
244 | |
---|
245 | template <class U, class V, class W> |
---|
246 | void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node) |
---|
247 | { |
---|
248 | this->parse(node, true); |
---|
249 | } |
---|
250 | |
---|
251 | //--------------------------------------------------------------- |
---|
252 | |
---|
253 | template <class U, class V, class W> |
---|
254 | void CGroupTemplate<U, V, W>::solveDescInheritance(const CAttributeMap * const parent) |
---|
255 | { |
---|
256 | if (parent != NULL) |
---|
257 | SuperClassAttribute::setAttributes(parent); |
---|
258 | |
---|
259 | typename std::vector<boost::shared_ptr<U> >::const_iterator |
---|
260 | itc = this->childList.begin(), endc = this->childList.end(); |
---|
261 | typename std::vector<boost::shared_ptr<V> >::const_iterator |
---|
262 | itg = this->groupList.begin(), endg = this->groupList.end(); |
---|
263 | |
---|
264 | for (; itc != endc; itc++) |
---|
265 | { |
---|
266 | boost::shared_ptr<U> child = *itc; |
---|
267 | child->solveDescInheritance(this); |
---|
268 | } |
---|
269 | |
---|
270 | for (; itg != endg; itg++) |
---|
271 | { |
---|
272 | boost::shared_ptr<V> group = *itg; |
---|
273 | group->solveRefInheritance(); |
---|
274 | group->solveDescInheritance(this); |
---|
275 | } |
---|
276 | } |
---|
277 | |
---|
278 | //--------------------------------------------------------------- |
---|
279 | |
---|
280 | template <class U, class V, class W> |
---|
281 | void CGroupTemplate<U, V, W>::getAllChildren(std::vector<boost::shared_ptr<U> > & allc) const |
---|
282 | { |
---|
283 | allc.insert (allc.end(), childList.begin(), childList.end()); |
---|
284 | typename std::vector<boost::shared_ptr<V> >::const_iterator |
---|
285 | itg = this->groupList.begin(), endg = this->groupList.end(); |
---|
286 | |
---|
287 | for (; itg != endg; itg++) |
---|
288 | { |
---|
289 | boost::shared_ptr<V> group = *itg; |
---|
290 | group->getAllChildren(allc); |
---|
291 | } |
---|
292 | } |
---|
293 | |
---|
294 | //--------------------------------------------------------------- |
---|
295 | |
---|
296 | template <class U, class V, class W> |
---|
297 | std::vector<boost::shared_ptr<U> > CGroupTemplate<U, V, W>::getAllChildren(void) const |
---|
298 | { |
---|
299 | std::vector<boost::shared_ptr<U> > allc; |
---|
300 | this->getAllChildren(allc); |
---|
301 | return (allc); |
---|
302 | } |
---|
303 | |
---|
304 | //--------------------------------------------------------------- |
---|
305 | |
---|
306 | template <class U, class V, class W> |
---|
307 | void CGroupTemplate<U, V, W>::solveRefInheritance(void) |
---|
308 | { /* Ne rien faire de plus */ } |
---|
309 | |
---|
310 | ///-------------------------------------------------------------- |
---|
311 | |
---|
312 | } // namespace xmlioserver |
---|
313 | |
---|
314 | |
---|
315 | #endif // __XMLIO_CGroupTemplate_impl__ |
---|