source: XMLIO_V2/dev/common/src/fortran/icxml_tree.cpp @ 300

Last change on this file since 300 was 300, checked in by ymipsl, 12 years ago

nouvelle version de developpement de xios

  • nouvelle interface fortran
  • recodage complet de la couche de communication
  • et bien d'autres choses...

YM

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