1 | /* ************************************************************************** * |
---|
2 | * Copyright © IPSL/LSCE, xios, Avril 2010 - Octobre 2011 * |
---|
3 | * ************************************************************************** */ |
---|
4 | |
---|
5 | #include <boost/multi_array.hpp> |
---|
6 | #include <boost/shared_ptr.hpp> |
---|
7 | |
---|
8 | #include "xmlioserver.hpp" |
---|
9 | |
---|
10 | #include "attribute_template.hpp" |
---|
11 | #include "object_template.hpp" |
---|
12 | #include "group_template.hpp" |
---|
13 | |
---|
14 | #include "icutil.hpp" |
---|
15 | #include "timer.hpp" |
---|
16 | #include "context.hpp" |
---|
17 | #include "grid.hpp" |
---|
18 | #include "file.hpp" |
---|
19 | #include "field.hpp" |
---|
20 | #include "axis.hpp" |
---|
21 | #include "domain.hpp" |
---|
22 | #include "variable.hpp" |
---|
23 | |
---|
24 | extern "C" |
---|
25 | { |
---|
26 | // /////////////////////////////// Définitions ////////////////////////////// // |
---|
27 | |
---|
28 | // ----------------------- Redéfinition de types ---------------------------- |
---|
29 | |
---|
30 | typedef xios::CContext * XContextPtr; |
---|
31 | |
---|
32 | typedef xios::CGrid * XGridPtr; |
---|
33 | typedef xios::CGridGroup * XGridGroupPtr; |
---|
34 | |
---|
35 | typedef xios::CFile * XFilePtr; |
---|
36 | typedef xios::CFileGroup * XFileGroupPtr; |
---|
37 | |
---|
38 | typedef xios::CField * XFieldPtr; |
---|
39 | typedef xios::CFieldGroup * XFieldGroupPtr; |
---|
40 | |
---|
41 | typedef xios::CDomain * XDomainPtr; |
---|
42 | typedef xios::CDomainGroup * XDomainGroupPtr; |
---|
43 | |
---|
44 | typedef xios::CAxis * XAxisPtr; |
---|
45 | typedef xios::CAxisGroup * XAxisGroupPtr; |
---|
46 | |
---|
47 | typedef xios::CVariable * XVariablePtr; |
---|
48 | typedef xios::CVariableGroup * XVariableGroupPtr; |
---|
49 | |
---|
50 | // ----------------------- Ajout d'enfant à un parent ----------------------- |
---|
51 | |
---|
52 | void cxios_xml_tree_add_field |
---|
53 | (XFieldGroupPtr parent_, XFieldPtr * child_, const char * child_id, int child_id_size) |
---|
54 | { |
---|
55 | std::string child_id_str; |
---|
56 | CTimer::get("XIOS").resume() ; |
---|
57 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
58 | { |
---|
59 | *child_ = parent_->createChild(child_id_str) ; |
---|
60 | parent_->sendCreateChild(child_id_str) ; |
---|
61 | } |
---|
62 | else |
---|
63 | { |
---|
64 | *child_ = parent_->createChild() ; |
---|
65 | parent_->sendCreateChild() ; |
---|
66 | } |
---|
67 | CTimer::get("XIOS").suspend() ; |
---|
68 | } |
---|
69 | |
---|
70 | void cxios_xml_tree_add_grid |
---|
71 | (XGridGroupPtr parent_, XGridPtr * child_, const char * child_id, int child_id_size) |
---|
72 | { |
---|
73 | std::string child_id_str; |
---|
74 | CTimer::get("XIOS").resume() ; |
---|
75 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
76 | { |
---|
77 | *child_ = parent_->createChild(child_id_str) ; |
---|
78 | parent_->sendCreateChild(child_id_str) ; |
---|
79 | } |
---|
80 | else |
---|
81 | { |
---|
82 | *child_ = parent_->createChild() ; |
---|
83 | parent_->sendCreateChild() ; |
---|
84 | } |
---|
85 | CTimer::get("XIOS").suspend() ; |
---|
86 | } |
---|
87 | |
---|
88 | void cxios_xml_tree_add_file |
---|
89 | (XFileGroupPtr parent_, XFilePtr * child_, const char * child_id, int child_id_size) |
---|
90 | { |
---|
91 | std::string child_id_str; |
---|
92 | CTimer::get("XIOS").resume() ; |
---|
93 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
94 | { |
---|
95 | *child_ = parent_->createChild(child_id_str) ; |
---|
96 | parent_->sendCreateChild(child_id_str) ; |
---|
97 | } |
---|
98 | else |
---|
99 | { |
---|
100 | *child_ = parent_->createChild() ; |
---|
101 | parent_->sendCreateChild() ; |
---|
102 | } |
---|
103 | CTimer::get("XIOS").suspend() ; |
---|
104 | } |
---|
105 | |
---|
106 | void cxios_xml_tree_add_axis |
---|
107 | (XAxisGroupPtr parent_, XAxisPtr * child_, const char * child_id, int child_id_size) |
---|
108 | { |
---|
109 | std::string child_id_str; |
---|
110 | CTimer::get("XIOS").resume() ; |
---|
111 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
112 | { |
---|
113 | *child_ = parent_->createChild(child_id_str) ; |
---|
114 | parent_->sendCreateChild(child_id_str) ; |
---|
115 | } |
---|
116 | else |
---|
117 | { |
---|
118 | *child_ = parent_->createChild() ; |
---|
119 | parent_->sendCreateChild() ; |
---|
120 | } |
---|
121 | CTimer::get("XIOS").suspend() ; |
---|
122 | } |
---|
123 | |
---|
124 | void cxios_xml_tree_add_domain |
---|
125 | (XDomainGroupPtr parent_, XDomainPtr * child_, const char * child_id, int child_id_size) |
---|
126 | { |
---|
127 | std::string child_id_str; |
---|
128 | CTimer::get("XIOS").resume() ; |
---|
129 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
130 | { |
---|
131 | *child_ = parent_->createChild(child_id_str) ; |
---|
132 | parent_->sendCreateChild(child_id_str) ; |
---|
133 | } |
---|
134 | else |
---|
135 | { |
---|
136 | *child_ = parent_->createChild() ; |
---|
137 | parent_->sendCreateChild() ; |
---|
138 | } |
---|
139 | CTimer::get("XIOS").suspend() ; |
---|
140 | } |
---|
141 | |
---|
142 | void cxios_xml_tree_add_fieldtofile |
---|
143 | (XFilePtr parent_, XFieldPtr * child_, const char * child_id, int child_id_size) |
---|
144 | { |
---|
145 | std::string child_id_str; |
---|
146 | CTimer::get("XIOS").resume() ; |
---|
147 | |
---|
148 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
149 | { |
---|
150 | *child_ = parent_->addField(child_id_str); |
---|
151 | parent_->sendAddField(child_id_str) ; |
---|
152 | } |
---|
153 | else |
---|
154 | { |
---|
155 | *child_ = parent_->addField(); |
---|
156 | parent_->sendAddField() ; |
---|
157 | } |
---|
158 | CTimer::get("XIOS").suspend() ; |
---|
159 | } |
---|
160 | |
---|
161 | void cxios_xml_tree_add_variabletofile |
---|
162 | (XFilePtr parent_, XVariablePtr * child_, const char * child_id, int child_id_size) |
---|
163 | { |
---|
164 | std::string child_id_str; |
---|
165 | CTimer::get("XIOS").resume() ; |
---|
166 | |
---|
167 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
168 | { |
---|
169 | *child_ = parent_->addVariable(child_id_str); |
---|
170 | parent_->sendAddVariable(child_id_str) ; |
---|
171 | } |
---|
172 | else |
---|
173 | { |
---|
174 | *child_ = parent_->addVariable(); |
---|
175 | parent_->sendAddVariable() ; |
---|
176 | } |
---|
177 | CTimer::get("XIOS").suspend() ; |
---|
178 | } |
---|
179 | |
---|
180 | void cxios_xml_tree_add_variabletofield |
---|
181 | (XFieldPtr parent_, XVariablePtr * child_, const char * child_id, int child_id_size) |
---|
182 | { |
---|
183 | std::string child_id_str; |
---|
184 | CTimer::get("XIOS").resume() ; |
---|
185 | |
---|
186 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
187 | { |
---|
188 | *child_ = parent_->addVariable(child_id_str); |
---|
189 | parent_->sendAddVariable(child_id_str) ; |
---|
190 | } |
---|
191 | else |
---|
192 | { |
---|
193 | *child_ = parent_->addVariable(); |
---|
194 | parent_->sendAddVariable() ; |
---|
195 | } |
---|
196 | CTimer::get("XIOS").suspend() ; |
---|
197 | } |
---|
198 | // ----------------------- Ajout de groupe à un parent ---------------------- |
---|
199 | |
---|
200 | void cxios_xml_tree_add_fieldgroup |
---|
201 | (XFieldGroupPtr parent_, XFieldGroupPtr * child_, const char * child_id, int child_id_size) |
---|
202 | { |
---|
203 | std::string child_id_str; |
---|
204 | CTimer::get("XIOS").resume() ; |
---|
205 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
206 | { |
---|
207 | *child_ = parent_->createChildGroup(child_id_str) ; |
---|
208 | parent_->sendCreateChildGroup(child_id_str) ; |
---|
209 | } |
---|
210 | else |
---|
211 | { |
---|
212 | *child_ = parent_->createChildGroup() ; |
---|
213 | parent_->sendCreateChildGroup(child_id_str) ; |
---|
214 | } |
---|
215 | CTimer::get("XIOS").suspend() ; |
---|
216 | } |
---|
217 | |
---|
218 | void cxios_xml_tree_add_gridgroup |
---|
219 | (XGridGroupPtr parent_, XGridGroupPtr * child_, const char * child_id, int child_id_size) |
---|
220 | { |
---|
221 | std::string child_id_str; |
---|
222 | CTimer::get("XIOS").resume() ; |
---|
223 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
224 | { |
---|
225 | *child_ = parent_->createChildGroup(child_id_str) ; |
---|
226 | parent_->sendCreateChildGroup(child_id_str) ; |
---|
227 | } |
---|
228 | else |
---|
229 | { |
---|
230 | *child_ = parent_->createChildGroup() ; |
---|
231 | parent_->sendCreateChildGroup(child_id_str) ; |
---|
232 | } |
---|
233 | CTimer::get("XIOS").suspend() ; |
---|
234 | } |
---|
235 | |
---|
236 | void cxios_xml_tree_add_filegroup |
---|
237 | (XFileGroupPtr parent_, XFileGroupPtr * child_, const char * child_id, int child_id_size) |
---|
238 | { |
---|
239 | std::string child_id_str; |
---|
240 | CTimer::get("XIOS").resume() ; |
---|
241 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
242 | { |
---|
243 | *child_ = parent_->createChildGroup(child_id_str) ; |
---|
244 | parent_->sendCreateChildGroup(child_id_str) ; |
---|
245 | } |
---|
246 | else |
---|
247 | { |
---|
248 | *child_ = parent_->createChildGroup() ; |
---|
249 | parent_->sendCreateChildGroup(child_id_str) ; |
---|
250 | } |
---|
251 | CTimer::get("XIOS").suspend() ; |
---|
252 | } |
---|
253 | |
---|
254 | void cxios_xml_tree_add_axisgroup |
---|
255 | (XAxisGroupPtr parent_, XAxisGroupPtr * child_, const char * child_id, int child_id_size) |
---|
256 | { |
---|
257 | std::string child_id_str; |
---|
258 | CTimer::get("XIOS").resume() ; |
---|
259 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
260 | { |
---|
261 | *child_ = parent_->createChildGroup(child_id_str) ; |
---|
262 | parent_->sendCreateChildGroup(child_id_str) ; |
---|
263 | } |
---|
264 | else |
---|
265 | { |
---|
266 | *child_ = parent_->createChildGroup() ; |
---|
267 | parent_->sendCreateChildGroup(child_id_str) ; |
---|
268 | } |
---|
269 | CTimer::get("XIOS").suspend() ; |
---|
270 | } |
---|
271 | |
---|
272 | void cxios_xml_tree_add_domaingroup |
---|
273 | (XDomainGroupPtr parent_, XDomainGroupPtr * child_, const char * child_id, int child_id_size) |
---|
274 | { |
---|
275 | std::string child_id_str; |
---|
276 | CTimer::get("XIOS").resume() ; |
---|
277 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
278 | { |
---|
279 | *child_ = parent_->createChildGroup(child_id_str) ; |
---|
280 | parent_->sendCreateChildGroup(child_id_str) ; |
---|
281 | } |
---|
282 | else |
---|
283 | { |
---|
284 | *child_ = parent_->createChildGroup() ; |
---|
285 | parent_->sendCreateChildGroup(child_id_str) ; |
---|
286 | } |
---|
287 | CTimer::get("XIOS").suspend() ; |
---|
288 | } |
---|
289 | |
---|
290 | void cxios_xml_tree_add_fieldgrouptofile |
---|
291 | (XFilePtr parent_, XFieldGroupPtr * child_, const char * child_id, int child_id_size) |
---|
292 | { |
---|
293 | std::string child_id_str; |
---|
294 | CTimer::get("XIOS").resume() ; |
---|
295 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
296 | { |
---|
297 | *child_ = parent_->addFieldGroup(child_id_str); |
---|
298 | parent_->sendAddFieldGroup(child_id_str) ; |
---|
299 | } |
---|
300 | else |
---|
301 | { |
---|
302 | *child_ = parent_->addFieldGroup(); |
---|
303 | parent_->sendAddFieldGroup() ; |
---|
304 | } |
---|
305 | CTimer::get("XIOS").suspend() ; |
---|
306 | } |
---|
307 | |
---|
308 | void cxios_xml_tree_add_variablegrouptofile |
---|
309 | (XFilePtr parent_, XVariableGroupPtr * child_, const char * child_id, int child_id_size) |
---|
310 | { |
---|
311 | std::string child_id_str; |
---|
312 | CTimer::get("XIOS").resume() ; |
---|
313 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
314 | { |
---|
315 | *child_ = parent_->addVariableGroup(child_id_str); |
---|
316 | parent_->sendAddVariableGroup(child_id_str) ; |
---|
317 | } |
---|
318 | else |
---|
319 | { |
---|
320 | *child_ = parent_->addVariableGroup(); |
---|
321 | parent_->sendAddVariableGroup() ; |
---|
322 | } |
---|
323 | CTimer::get("XIOS").suspend() ; |
---|
324 | } |
---|
325 | |
---|
326 | void cxios_xml_tree_add_variablegrouptofield |
---|
327 | (XFieldPtr parent_, XVariableGroupPtr * child_, const char * child_id, int child_id_size) |
---|
328 | { |
---|
329 | std::string child_id_str; |
---|
330 | CTimer::get("XIOS").resume() ; |
---|
331 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
332 | { |
---|
333 | *child_ = parent_->addVariableGroup(child_id_str); |
---|
334 | parent_->sendAddVariableGroup(child_id_str) ; |
---|
335 | } |
---|
336 | else |
---|
337 | { |
---|
338 | *child_ = parent_->addVariableGroup(); |
---|
339 | parent_->sendAddVariableGroup() ; |
---|
340 | } |
---|
341 | CTimer::get("XIOS").suspend() ; |
---|
342 | } |
---|
343 | |
---|
344 | |
---|
345 | // ----------------------- Affichage de l'arborescence ---------------------- |
---|
346 | |
---|
347 | // void cxios_xml_tree_show (const char * filename, int filename_size) |
---|
348 | // { |
---|
349 | // std::string filename_str; |
---|
350 | // try |
---|
351 | // { |
---|
352 | // if (cstr2string(filename, filename_size, filename_str)) |
---|
353 | // xios::CTreeManager::PrintTreeToFile(filename_str); |
---|
354 | // else |
---|
355 | // xios::CTreeManager::PrintTreeToStream(std::clog); |
---|
356 | // } |
---|
357 | // catch (xios::CException & exc) |
---|
358 | // { |
---|
359 | // std::cerr << exc.getMessage() << std::endl; |
---|
360 | // exit (EXIT_FAILURE); |
---|
361 | // } |
---|
362 | // } |
---|
363 | |
---|
364 | |
---|
365 | // ----------------------- Parsing de document xml -------------------------- |
---|
366 | |
---|
367 | // void cxios_xml_parse_file (const char * filename , int filename_size)// |
---|
368 | // { |
---|
369 | // std::string filename_str; |
---|
370 | // if (!cstr2string(filename, filename_size, filename_str)) return; |
---|
371 | // |
---|
372 | // try |
---|
373 | // { |
---|
374 | // xios::CTreeManager::ParseFile(filename_str); |
---|
375 | // } |
---|
376 | // catch (xios::CException & exc) |
---|
377 | // { |
---|
378 | // std::cerr << exc.getMessage() << std::endl; |
---|
379 | // exit (EXIT_FAILURE); |
---|
380 | // } |
---|
381 | // } |
---|
382 | |
---|
383 | // void cxios_xml_parse_string(const char * xmlcontent, int xmlcontent_size) |
---|
384 | // { |
---|
385 | // std::string xmlcontent_str; |
---|
386 | // if (!cstr2string(xmlcontent, xmlcontent_size, xmlcontent_str)) return; |
---|
387 | // |
---|
388 | // try |
---|
389 | // { |
---|
390 | // xios::CTreeManager::ParseString(xmlcontent_str); |
---|
391 | // } |
---|
392 | // catch (xios::CException & exc) |
---|
393 | // { |
---|
394 | // std::cerr << exc.getMessage() << std::endl; |
---|
395 | // exit (EXIT_FAILURE); |
---|
396 | // } |
---|
397 | // } |
---|
398 | |
---|
399 | |
---|
400 | |
---|
401 | } // extern "C" |
---|