source: XIOS/trunk/src/interface/c/icxml_tree.cpp @ 369

Last change on this file since 369 was 352, checked in by ymipsl, 12 years ago
  • Property svn:eol-style set to native
File size: 9.5 KB
RevLine 
[325]1/* ************************************************************************** *
[335]2 *      Copyright © IPSL/LSCE, xios, Avril 2010 - Octobre 2011         *
[325]3 * ************************************************************************** */
4
5#include <boost/multi_array.hpp>
6#include <boost/shared_ptr.hpp>
7
8#include "xmlioserver.hpp"
9
[352]10#include "attribute_template.hpp"
11#include "object_template.hpp"
12#include "group_template.hpp"
[325]13
14#include "icutil.hpp"
[347]15#include "timer.hpp"
[352]16#include "context.hpp"
17#include "grid.hpp"
18#include "file.hpp"
19#include "field.hpp"
20#include "axis.hpp"
21#include "domain.hpp"
[325]22
23extern "C"
24{
25// /////////////////////////////// Définitions ////////////////////////////// //
26
27   // ----------------------- Redéfinition de types ----------------------------
28
[345]29   typedef xios::CContext * XContextPtr;
[325]30
[345]31   typedef xios::CGrid      * XGridPtr;
32   typedef xios::CGridGroup * XGridGroupPtr;
[325]33
[345]34   typedef xios::CFile      * XFilePtr;
35   typedef xios::CFileGroup * XFileGroupPtr;
[325]36
[345]37   typedef xios::CField      * XFieldPtr;
38   typedef xios::CFieldGroup * XFieldGroupPtr;
[325]39
[345]40   typedef xios::CDomain      * XDomainPtr;
41   typedef xios::CDomainGroup * XDomainGroupPtr;
[325]42
[345]43   typedef xios::CAxis      * XAxisPtr;
44   typedef xios::CAxisGroup * XAxisGroupPtr;
[325]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; 
[347]52      CTimer::get("XIOS").resume() ;
[325]53      if (cstr2string(child_id, child_id_size, child_id_str))
54      {
[347]55         *child_ = parent_->createChild(child_id_str) ;
[325]56         parent_->sendCreateChild(child_id_str) ;
57      }
58      else
59      {
[347]60         *child_ = parent_->createChild() ;
[325]61         parent_->sendCreateChild() ;
62      }
[347]63      CTimer::get("XIOS").suspend() ;
[325]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; 
[347]70      CTimer::get("XIOS").resume() ;
[325]71      if (cstr2string(child_id, child_id_size, child_id_str))
72      {
[347]73         *child_ = parent_->createChild(child_id_str) ;
[325]74         parent_->sendCreateChild(child_id_str) ;
75      }
76      else
77      {
[347]78         *child_ = parent_->createChild() ;
[325]79         parent_->sendCreateChild() ;
80      }
[347]81      CTimer::get("XIOS").suspend() ;
[325]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; 
[347]88      CTimer::get("XIOS").resume() ;
[325]89      if (cstr2string(child_id, child_id_size, child_id_str))
90      {
[347]91         *child_ = parent_->createChild(child_id_str) ;
[325]92         parent_->sendCreateChild(child_id_str) ;
93      }
94      else
95      {
[347]96         *child_ = parent_->createChild() ;
[325]97         parent_->sendCreateChild() ;
98      }
[347]99      CTimer::get("XIOS").suspend() ;
[325]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; 
[347]106      CTimer::get("XIOS").resume() ;
[325]107      if (cstr2string(child_id, child_id_size, child_id_str))
108      {
[347]109         *child_ = parent_->createChild(child_id_str) ;
[325]110         parent_->sendCreateChild(child_id_str) ;
111      }
112      else
113      {
[347]114         *child_ = parent_->createChild() ;
[325]115         parent_->sendCreateChild() ;
116      }
[347]117      CTimer::get("XIOS").suspend() ;
[325]118   }
119   
120   void cxios_xml_tree_add_domain
121      (XDomainGroupPtr parent_, XDomainPtr * child_, const char * child_id, int child_id_size)
122   {
[347]123      std::string child_id_str;
124      CTimer::get("XIOS").resume() ;
[325]125      if (cstr2string(child_id, child_id_size, child_id_str))
126      {
[347]127         *child_ = parent_->createChild(child_id_str) ;
[325]128         parent_->sendCreateChild(child_id_str) ;
129      }
130      else
131      {
[347]132         *child_ = parent_->createChild() ;
[325]133         parent_->sendCreateChild() ;
134      }
[347]135      CTimer::get("XIOS").suspend() ;
[325]136   }
137   
138   void cxios_xml_tree_add_fieldtofile
139      (XFilePtr parent_, XFieldPtr * child_, const char * child_id, int child_id_size)
140   {
[347]141      std::string child_id_str;
142      CTimer::get("XIOS").resume() ;
[325]143 
144      if (cstr2string(child_id, child_id_size, child_id_str))
145      {
[347]146         *child_ = parent_->addField(child_id_str);
[325]147         parent_->sendAddField(child_id_str) ;
148      }
149      else
150      {
[347]151         *child_ = parent_->addField();
[325]152         parent_->sendAddField() ;
153      }
[347]154      CTimer::get("XIOS").suspend() ;
[325]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; 
[347]163      CTimer::get("XIOS").resume() ;
[325]164      if (cstr2string(child_id, child_id_size, child_id_str))
165      {
[347]166         *child_ = parent_->createChildGroup(child_id_str) ;
[325]167         parent_->sendCreateChildGroup(child_id_str) ;
168      }
169      else
170      {
[347]171         *child_ = parent_->createChildGroup() ;
[325]172         parent_->sendCreateChildGroup(child_id_str) ;
173      }
[347]174      CTimer::get("XIOS").suspend() ;
[325]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;
[347]181      CTimer::get("XIOS").resume() ;
[325]182      if (cstr2string(child_id, child_id_size, child_id_str))
183      {
[347]184         *child_ = parent_->createChildGroup(child_id_str) ;
[325]185         parent_->sendCreateChildGroup(child_id_str) ;
186      }
187      else
188      {
[347]189         *child_ = parent_->createChildGroup() ;
[325]190         parent_->sendCreateChildGroup(child_id_str) ;
191      }
[347]192      CTimer::get("XIOS").suspend() ;
[325]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;
[347]199      CTimer::get("XIOS").resume() ;
[325]200      if (cstr2string(child_id, child_id_size, child_id_str))
201      {
[347]202         *child_ = parent_->createChildGroup(child_id_str) ;
[325]203         parent_->sendCreateChildGroup(child_id_str) ;
204      }
205      else
206      {
[347]207         *child_ = parent_->createChildGroup() ;
[325]208         parent_->sendCreateChildGroup(child_id_str) ;
209      }
[347]210      CTimer::get("XIOS").suspend() ;
[325]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;
[347]217      CTimer::get("XIOS").resume() ;
[325]218      if (cstr2string(child_id, child_id_size, child_id_str))
219      {
[347]220         *child_ = parent_->createChildGroup(child_id_str) ;
[325]221         parent_->sendCreateChildGroup(child_id_str) ;
222      }
223      else
224      {
[347]225         *child_ = parent_->createChildGroup() ;
[325]226         parent_->sendCreateChildGroup(child_id_str) ;
227      }
[347]228      CTimer::get("XIOS").suspend() ;
[325]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;
[347]235      CTimer::get("XIOS").resume() ;
[325]236      if (cstr2string(child_id, child_id_size, child_id_str))
237      {
[347]238         *child_ = parent_->createChildGroup(child_id_str) ;
[325]239         parent_->sendCreateChildGroup(child_id_str) ;
240      }
241      else
242      {
[347]243         *child_ = parent_->createChildGroup() ;
[325]244         parent_->sendCreateChildGroup(child_id_str) ;
245      }
[347]246      CTimer::get("XIOS").suspend() ;
[325]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; 
[347]253      CTimer::get("XIOS").resume() ;
[325]254      if (cstr2string(child_id, child_id_size, child_id_str))
255      {
[347]256         *child_ = parent_->addFieldGroup(child_id_str);
[325]257         parent_->sendAddFieldGroup(child_id_str) ;
258      }
259      else
260      {
[347]261         *child_ = parent_->addFieldGroup();
[325]262         parent_->sendAddFieldGroup() ;
263      }
[347]264      CTimer::get("XIOS").suspend() ;
[325]265   }
266   
267   
268   // ----------------------- Affichage de l'arborescence ----------------------
269   
[346]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//  }
[325]286     
287   
288   // ----------------------- Parsing de document xml --------------------------
289   
[346]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//   }
[325]305   
[346]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//   }
[325]321   
322
323
324} // extern "C"
Note: See TracBrowser for help on using the repository browser.