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

Last change on this file since 501 was 501, checked in by ymipsl, 10 years ago

Add licence copyright to all file ond directory src using the command :
svn propset -R copyright -F header_licence src

XIOS is now officialy under CeCILL licence

YM

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
  • Property svn:eol-style set to native
File size: 11.8 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"
[472]22#include "variable.hpp"
[325]23
24extern "C"
25{
26// /////////////////////////////// Définitions ////////////////////////////// //
27
28   // ----------------------- Redéfinition de types ----------------------------
29
[345]30   typedef xios::CContext * XContextPtr;
[325]31
[345]32   typedef xios::CGrid      * XGridPtr;
33   typedef xios::CGridGroup * XGridGroupPtr;
[325]34
[345]35   typedef xios::CFile      * XFilePtr;
36   typedef xios::CFileGroup * XFileGroupPtr;
[325]37
[345]38   typedef xios::CField      * XFieldPtr;
39   typedef xios::CFieldGroup * XFieldGroupPtr;
[325]40
[345]41   typedef xios::CDomain      * XDomainPtr;
42   typedef xios::CDomainGroup * XDomainGroupPtr;
[325]43
[345]44   typedef xios::CAxis      * XAxisPtr;
45   typedef xios::CAxisGroup * XAxisGroupPtr;
[472]46 
47   typedef xios::CVariable      *  XVariablePtr;
48   typedef xios::CVariableGroup *  XVariableGroupPtr;
49 
[325]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; 
[347]56      CTimer::get("XIOS").resume() ;
[325]57      if (cstr2string(child_id, child_id_size, child_id_str))
58      {
[347]59         *child_ = parent_->createChild(child_id_str) ;
[325]60         parent_->sendCreateChild(child_id_str) ;
61      }
62      else
63      {
[347]64         *child_ = parent_->createChild() ;
[325]65         parent_->sendCreateChild() ;
66      }
[347]67      CTimer::get("XIOS").suspend() ;
[325]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; 
[347]74      CTimer::get("XIOS").resume() ;
[325]75      if (cstr2string(child_id, child_id_size, child_id_str))
76      {
[347]77         *child_ = parent_->createChild(child_id_str) ;
[325]78         parent_->sendCreateChild(child_id_str) ;
79      }
80      else
81      {
[347]82         *child_ = parent_->createChild() ;
[325]83         parent_->sendCreateChild() ;
84      }
[347]85      CTimer::get("XIOS").suspend() ;
[325]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; 
[347]92      CTimer::get("XIOS").resume() ;
[325]93      if (cstr2string(child_id, child_id_size, child_id_str))
94      {
[347]95         *child_ = parent_->createChild(child_id_str) ;
[325]96         parent_->sendCreateChild(child_id_str) ;
97      }
98      else
99      {
[347]100         *child_ = parent_->createChild() ;
[325]101         parent_->sendCreateChild() ;
102      }
[347]103      CTimer::get("XIOS").suspend() ;
[325]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; 
[347]110      CTimer::get("XIOS").resume() ;
[325]111      if (cstr2string(child_id, child_id_size, child_id_str))
112      {
[347]113         *child_ = parent_->createChild(child_id_str) ;
[325]114         parent_->sendCreateChild(child_id_str) ;
115      }
116      else
117      {
[347]118         *child_ = parent_->createChild() ;
[325]119         parent_->sendCreateChild() ;
120      }
[347]121      CTimer::get("XIOS").suspend() ;
[325]122   }
123   
124   void cxios_xml_tree_add_domain
125      (XDomainGroupPtr parent_, XDomainPtr * child_, const char * child_id, int child_id_size)
126   {
[347]127      std::string child_id_str;
128      CTimer::get("XIOS").resume() ;
[325]129      if (cstr2string(child_id, child_id_size, child_id_str))
130      {
[347]131         *child_ = parent_->createChild(child_id_str) ;
[325]132         parent_->sendCreateChild(child_id_str) ;
133      }
134      else
135      {
[347]136         *child_ = parent_->createChild() ;
[325]137         parent_->sendCreateChild() ;
138      }
[347]139      CTimer::get("XIOS").suspend() ;
[325]140   }
141   
142   void cxios_xml_tree_add_fieldtofile
143      (XFilePtr parent_, XFieldPtr * child_, const char * child_id, int child_id_size)
144   {
[347]145      std::string child_id_str;
146      CTimer::get("XIOS").resume() ;
[325]147 
148      if (cstr2string(child_id, child_id_size, child_id_str))
149      {
[347]150         *child_ = parent_->addField(child_id_str);
[325]151         parent_->sendAddField(child_id_str) ;
152      }
153      else
154      {
[347]155         *child_ = parent_->addField();
[325]156         parent_->sendAddField() ;
157      }
[347]158      CTimer::get("XIOS").suspend() ;
[325]159   }
160
[472]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   } 
[325]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; 
[347]204      CTimer::get("XIOS").resume() ;
[325]205      if (cstr2string(child_id, child_id_size, child_id_str))
206      {
[347]207         *child_ = parent_->createChildGroup(child_id_str) ;
[325]208         parent_->sendCreateChildGroup(child_id_str) ;
209      }
210      else
211      {
[347]212         *child_ = parent_->createChildGroup() ;
[325]213         parent_->sendCreateChildGroup(child_id_str) ;
214      }
[347]215      CTimer::get("XIOS").suspend() ;
[325]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;
[347]222      CTimer::get("XIOS").resume() ;
[325]223      if (cstr2string(child_id, child_id_size, child_id_str))
224      {
[347]225         *child_ = parent_->createChildGroup(child_id_str) ;
[325]226         parent_->sendCreateChildGroup(child_id_str) ;
227      }
228      else
229      {
[347]230         *child_ = parent_->createChildGroup() ;
[325]231         parent_->sendCreateChildGroup(child_id_str) ;
232      }
[347]233      CTimer::get("XIOS").suspend() ;
[325]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;
[347]240      CTimer::get("XIOS").resume() ;
[325]241      if (cstr2string(child_id, child_id_size, child_id_str))
242      {
[347]243         *child_ = parent_->createChildGroup(child_id_str) ;
[325]244         parent_->sendCreateChildGroup(child_id_str) ;
245      }
246      else
247      {
[347]248         *child_ = parent_->createChildGroup() ;
[325]249         parent_->sendCreateChildGroup(child_id_str) ;
250      }
[347]251      CTimer::get("XIOS").suspend() ;
[325]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;
[347]258      CTimer::get("XIOS").resume() ;
[325]259      if (cstr2string(child_id, child_id_size, child_id_str))
260      {
[347]261         *child_ = parent_->createChildGroup(child_id_str) ;
[325]262         parent_->sendCreateChildGroup(child_id_str) ;
263      }
264      else
265      {
[347]266         *child_ = parent_->createChildGroup() ;
[325]267         parent_->sendCreateChildGroup(child_id_str) ;
268      }
[347]269      CTimer::get("XIOS").suspend() ;
[325]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;
[347]276      CTimer::get("XIOS").resume() ;
[325]277      if (cstr2string(child_id, child_id_size, child_id_str))
278      {
[347]279         *child_ = parent_->createChildGroup(child_id_str) ;
[325]280         parent_->sendCreateChildGroup(child_id_str) ;
281      }
282      else
283      {
[347]284         *child_ = parent_->createChildGroup() ;
[325]285         parent_->sendCreateChildGroup(child_id_str) ;
286      }
[347]287      CTimer::get("XIOS").suspend() ;
[325]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; 
[347]294      CTimer::get("XIOS").resume() ;
[325]295      if (cstr2string(child_id, child_id_size, child_id_str))
296      {
[347]297         *child_ = parent_->addFieldGroup(child_id_str);
[325]298         parent_->sendAddFieldGroup(child_id_str) ;
299      }
300      else
301      {
[347]302         *child_ = parent_->addFieldGroup();
[325]303         parent_->sendAddFieldGroup() ;
304      }
[347]305      CTimer::get("XIOS").suspend() ;
[325]306   }
307   
[472]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]325   
[472]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   
[325]345   // ----------------------- Affichage de l'arborescence ----------------------
346   
[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//  }
[325]363     
364   
365   // ----------------------- Parsing de document xml --------------------------
366   
[346]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//   }
[325]382   
[346]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//   }
[325]398   
399
400
401} // extern "C"
Note: See TracBrowser for help on using the repository browser.