New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
icxml_tree.cpp in vendors/XIOS/current/src/interface/c – NEMO

source: vendors/XIOS/current/src/interface/c/icxml_tree.cpp @ 3428

Last change on this file since 3428 was 3428, checked in by rblod, 12 years ago

importing initial XIOS vendor drop

File size: 9.5 KB
Line 
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
23extern "C"
24{
25// /////////////////////////////// Définitions ////////////////////////////// //
26
27   // ----------------------- Redéfinition de types ----------------------------
28
29   typedef xios::CContext * XContextPtr;
30
31   typedef xios::CGrid      * XGridPtr;
32   typedef xios::CGridGroup * XGridGroupPtr;
33
34   typedef xios::CFile      * XFilePtr;
35   typedef xios::CFileGroup * XFileGroupPtr;
36
37   typedef xios::CField      * XFieldPtr;
38   typedef xios::CFieldGroup * XFieldGroupPtr;
39
40   typedef xios::CDomain      * XDomainPtr;
41   typedef xios::CDomainGroup * XDomainGroupPtr;
42
43   typedef xios::CAxis      * XAxisPtr;
44   typedef xios::CAxisGroup * XAxisGroupPtr;
45   
46   // ----------------------- Ajout d'enfant à un parent -----------------------
47   
48   void cxios_xml_tree_add_field
49      (XFieldGroupPtr  parent_, XFieldPtr * child_, const char * child_id, int child_id_size)
50   {
51      std::string child_id_str; 
52      CTimer::get("XIOS").resume() ;
53      if (cstr2string(child_id, child_id_size, child_id_str))
54      {
55         *child_ = parent_->createChild(child_id_str) ;
56         parent_->sendCreateChild(child_id_str) ;
57      }
58      else
59      {
60         *child_ = parent_->createChild() ;
61         parent_->sendCreateChild() ;
62      }
63      CTimer::get("XIOS").suspend() ;
64  }
65   
66   void cxios_xml_tree_add_grid
67      (XGridGroupPtr   parent_, XGridPtr * child_, const char * child_id, int child_id_size)
68   {
69      std::string child_id_str; 
70      CTimer::get("XIOS").resume() ;
71      if (cstr2string(child_id, child_id_size, child_id_str))
72      {
73         *child_ = parent_->createChild(child_id_str) ;
74         parent_->sendCreateChild(child_id_str) ;
75      }
76      else
77      {
78         *child_ = parent_->createChild() ;
79         parent_->sendCreateChild() ;
80      }
81      CTimer::get("XIOS").suspend() ;
82   }
83   
84   void cxios_xml_tree_add_file
85      (XFileGroupPtr parent_, XFilePtr * child_, const char * child_id, int child_id_size)
86   {
87      std::string child_id_str; 
88      CTimer::get("XIOS").resume() ;
89      if (cstr2string(child_id, child_id_size, child_id_str))
90      {
91         *child_ = parent_->createChild(child_id_str) ;
92         parent_->sendCreateChild(child_id_str) ;
93      }
94      else
95      {
96         *child_ = parent_->createChild() ;
97         parent_->sendCreateChild() ;
98      }
99      CTimer::get("XIOS").suspend() ;
100   }
101   
102   void cxios_xml_tree_add_axis
103      (XAxisGroupPtr parent_, XAxisPtr * child_, const char * child_id, int child_id_size)
104   {
105      std::string child_id_str; 
106      CTimer::get("XIOS").resume() ;
107      if (cstr2string(child_id, child_id_size, child_id_str))
108      {
109         *child_ = parent_->createChild(child_id_str) ;
110         parent_->sendCreateChild(child_id_str) ;
111      }
112      else
113      {
114         *child_ = parent_->createChild() ;
115         parent_->sendCreateChild() ;
116      }
117      CTimer::get("XIOS").suspend() ;
118   }
119   
120   void cxios_xml_tree_add_domain
121      (XDomainGroupPtr parent_, XDomainPtr * child_, const char * child_id, int child_id_size)
122   {
123      std::string child_id_str;
124      CTimer::get("XIOS").resume() ;
125      if (cstr2string(child_id, child_id_size, child_id_str))
126      {
127         *child_ = parent_->createChild(child_id_str) ;
128         parent_->sendCreateChild(child_id_str) ;
129      }
130      else
131      {
132         *child_ = parent_->createChild() ;
133         parent_->sendCreateChild() ;
134      }
135      CTimer::get("XIOS").suspend() ;
136   }
137   
138   void cxios_xml_tree_add_fieldtofile
139      (XFilePtr parent_, XFieldPtr * child_, const char * child_id, int child_id_size)
140   {
141      std::string child_id_str;
142      CTimer::get("XIOS").resume() ;
143 
144      if (cstr2string(child_id, child_id_size, child_id_str))
145      {
146         *child_ = parent_->addField(child_id_str);
147         parent_->sendAddField(child_id_str) ;
148      }
149      else
150      {
151         *child_ = parent_->addField();
152         parent_->sendAddField() ;
153      }
154      CTimer::get("XIOS").suspend() ;
155   }
156
157   // ----------------------- Ajout de groupe à un parent ----------------------
158
159   void cxios_xml_tree_add_fieldgroup
160      (XFieldGroupPtr  parent_, XFieldGroupPtr * child_, const char * child_id, int child_id_size)
161   {
162     std::string child_id_str; 
163      CTimer::get("XIOS").resume() ;
164      if (cstr2string(child_id, child_id_size, child_id_str))
165      {
166         *child_ = parent_->createChildGroup(child_id_str) ;
167         parent_->sendCreateChildGroup(child_id_str) ;
168      }
169      else
170      {
171         *child_ = parent_->createChildGroup() ;
172         parent_->sendCreateChildGroup(child_id_str) ;
173      }
174      CTimer::get("XIOS").suspend() ;
175   }
176
177   void cxios_xml_tree_add_gridgroup
178      (XGridGroupPtr   parent_, XGridGroupPtr * child_, const char * child_id, int child_id_size)
179   {
180      std::string child_id_str;
181      CTimer::get("XIOS").resume() ;
182      if (cstr2string(child_id, child_id_size, child_id_str))
183      {
184         *child_ = parent_->createChildGroup(child_id_str) ;
185         parent_->sendCreateChildGroup(child_id_str) ;
186      }
187      else
188      {
189         *child_ = parent_->createChildGroup() ;
190         parent_->sendCreateChildGroup(child_id_str) ;
191      }
192      CTimer::get("XIOS").suspend() ;
193   }
194
195   void cxios_xml_tree_add_filegroup
196      (XFileGroupPtr parent_, XFileGroupPtr * child_, const char * child_id, int child_id_size)
197   {
198      std::string child_id_str;
199      CTimer::get("XIOS").resume() ;
200      if (cstr2string(child_id, child_id_size, child_id_str))
201      {
202         *child_ = parent_->createChildGroup(child_id_str) ;
203         parent_->sendCreateChildGroup(child_id_str) ;
204      }
205      else
206      {
207         *child_ = parent_->createChildGroup() ;
208         parent_->sendCreateChildGroup(child_id_str) ;
209      }
210      CTimer::get("XIOS").suspend() ;
211   }
212
213   void cxios_xml_tree_add_axisgroup
214      (XAxisGroupPtr parent_, XAxisGroupPtr * child_, const char * child_id, int child_id_size)
215   {
216      std::string child_id_str;
217      CTimer::get("XIOS").resume() ;
218      if (cstr2string(child_id, child_id_size, child_id_str))
219      {
220         *child_ = parent_->createChildGroup(child_id_str) ;
221         parent_->sendCreateChildGroup(child_id_str) ;
222      }
223      else
224      {
225         *child_ = parent_->createChildGroup() ;
226         parent_->sendCreateChildGroup(child_id_str) ;
227      }
228      CTimer::get("XIOS").suspend() ;
229   }
230
231   void cxios_xml_tree_add_domaingroup
232      (XDomainGroupPtr parent_, XDomainGroupPtr * child_, const char * child_id, int child_id_size)
233   {
234      std::string child_id_str;
235      CTimer::get("XIOS").resume() ;
236      if (cstr2string(child_id, child_id_size, child_id_str))
237      {
238         *child_ = parent_->createChildGroup(child_id_str) ;
239         parent_->sendCreateChildGroup(child_id_str) ;
240      }
241      else
242      {
243         *child_ = parent_->createChildGroup() ;
244         parent_->sendCreateChildGroup(child_id_str) ;
245      }
246      CTimer::get("XIOS").suspend() ;
247   }
248
249   void cxios_xml_tree_add_fieldgrouptofile
250      (XFilePtr parent_, XFieldGroupPtr * child_, const char * child_id, int child_id_size)
251   {
252      std::string child_id_str; 
253      CTimer::get("XIOS").resume() ;
254      if (cstr2string(child_id, child_id_size, child_id_str))
255      {
256         *child_ = parent_->addFieldGroup(child_id_str);
257         parent_->sendAddFieldGroup(child_id_str) ;
258      }
259      else
260      {
261         *child_ = parent_->addFieldGroup();
262         parent_->sendAddFieldGroup() ;
263      }
264      CTimer::get("XIOS").suspend() ;
265   }
266   
267   
268   // ----------------------- Affichage de l'arborescence ----------------------
269   
270//   void cxios_xml_tree_show   (const char * filename, int filename_size)
271//   {
272//      std::string filename_str;
273//      try
274//      {
275//         if (cstr2string(filename, filename_size, filename_str))
276//            xios::CTreeManager::PrintTreeToFile(filename_str);
277//         else
278//            xios::CTreeManager::PrintTreeToStream(std::clog);
279//      }
280//      catch (xios::CException & exc)
281//      {
282//         std::cerr << exc.getMessage() << std::endl;
283//         exit (EXIT_FAILURE);
284//      }
285//  }
286     
287   
288   // ----------------------- Parsing de document xml --------------------------
289   
290//   void cxios_xml_parse_file  (const char * filename  , int filename_size)//
291//   {
292//      std::string filename_str;
293//      if (!cstr2string(filename, filename_size, filename_str)) return;
294//
295//      try
296//      {
297//         xios::CTreeManager::ParseFile(filename_str);
298//      }
299//      catch (xios::CException & exc)
300//      {
301//         std::cerr << exc.getMessage() << std::endl;
302//         exit (EXIT_FAILURE);
303//      }
304//   }
305   
306//   void cxios_xml_parse_string(const char * xmlcontent, int xmlcontent_size)
307//   {
308//      std::string xmlcontent_str;
309//      if (!cstr2string(xmlcontent, xmlcontent_size, xmlcontent_str)) return;
310//
311//      try
312//      {
313//         xios::CTreeManager::ParseString(xmlcontent_str);
314//      }
315//      catch (xios::CException & exc)
316//      {
317//         std::cerr << exc.getMessage() << std::endl;
318//         exit (EXIT_FAILURE);
319//      }
320//   }
321   
322
323
324} // extern "C"
Note: See TracBrowser for help on using the repository browser.