source: XIOS1/branches/xios-1.0-alpha1/src/fortran/icxml_tree.cpp @ 2357

Last change on this file since 2357 was 286, checked in by ymipsl, 13 years ago

reprise en main de la version de H. Ozdoba. Correction de différentes erreurs de conception et bug.
Version NEMO operationnel en client/server, interoperabilita avec OASIS, reconstition de fichiers via netcdf4/HDF5

YM

File size: 10.0 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      boost::shared_ptr<xmlioserver::tree::CFieldGroup> fieldgroup =
46         xmlioserver::CObjectFactory::GetObject<xmlioserver::tree::CFieldGroup>(parent_);
47
48      if (cstr2string(child_id, child_id_size, child_id_str))
49         *child_ = xmlioserver::CGroupFactory::CreateChild(fieldgroup, child_id_str).get();
50      else
51         *child_ = xmlioserver::CGroupFactory::CreateChild(fieldgroup).get();
52   }
53   
54   void cxios_xml_tree_add_grid
55      (XGridGroupPtr   parent_, XGridPtr * child_, const char * child_id, int child_id_size)
56   {
57      std::string child_id_str; 
58      boost::shared_ptr<xmlioserver::tree::CGridGroup> gridgroup =
59         xmlioserver::CObjectFactory::GetObject<xmlioserver::tree::CGridGroup>(parent_);
60
61      if (cstr2string(child_id, child_id_size, child_id_str))
62         *child_ = xmlioserver::CGroupFactory::CreateChild(gridgroup, child_id_str).get();
63      else
64         *child_ = xmlioserver::CGroupFactory::CreateChild(gridgroup).get();
65   }
66   
67   void cxios_xml_tree_add_file
68      (XFileGroupPtr parent_, XFilePtr * child_, const char * child_id, int child_id_size)
69   {
70      std::string child_id_str; 
71      boost::shared_ptr<xmlioserver::tree::CFileGroup> filegroup =
72         xmlioserver::CObjectFactory::GetObject<xmlioserver::tree::CFileGroup>(parent_);
73
74      if (cstr2string(child_id, child_id_size, child_id_str))
75         *child_ = xmlioserver::CGroupFactory::CreateChild(filegroup, child_id_str).get();
76      else
77         *child_ = xmlioserver::CGroupFactory::CreateChild(filegroup).get();
78   }
79   
80   void cxios_xml_tree_add_axis
81      (XAxisGroupPtr parent_, XAxisPtr * child_, const char * child_id, int child_id_size)
82   {
83      std::string child_id_str; 
84      boost::shared_ptr<xmlioserver::tree::CAxisGroup> axisgroup =
85         xmlioserver::CObjectFactory::GetObject<xmlioserver::tree::CAxisGroup>(parent_);
86
87      if (cstr2string(child_id, child_id_size, child_id_str))
88         *child_ = xmlioserver::CGroupFactory::CreateChild(axisgroup, child_id_str).get();
89      else
90         *child_ = xmlioserver::CGroupFactory::CreateChild(axisgroup).get();
91   }
92   
93   void cxios_xml_tree_add_domain
94      (XDomainGroupPtr parent_, XDomainPtr * child_, const char * child_id, int child_id_size)
95   {
96      std::string child_id_str; 
97      boost::shared_ptr<xmlioserver::tree::CDomainGroup> domaingroup =
98         xmlioserver::CObjectFactory::GetObject<xmlioserver::tree::CDomainGroup>(parent_);
99
100      if (cstr2string(child_id, child_id_size, child_id_str))
101         *child_ = xmlioserver::CGroupFactory::CreateChild(domaingroup, child_id_str).get();
102      else
103         *child_ = xmlioserver::CGroupFactory::CreateChild(domaingroup).get();
104   }
105   
106   void cxios_xml_tree_add_fieldtofile
107      (XFilePtr parent_, XFieldPtr * child_, const char * child_id, int child_id_size)
108   {
109      std::string child_id_str; 
110      boost::shared_ptr<xmlioserver::tree::CFile> file =
111         xmlioserver::CObjectFactory::GetObject<xmlioserver::tree::CFile>(parent_);
112
113      if (file->getVirtualFieldGroup().get() == 0 )
114          file->setVirtualFieldGroup(file->getId());
115
116      if (cstr2string(child_id, child_id_size, child_id_str))
117         *child_ = xmlioserver::CGroupFactory::CreateChild(file->getVirtualFieldGroup(), child_id_str).get();
118      else
119         *child_ = xmlioserver::CGroupFactory::CreateChild(file->getVirtualFieldGroup()).get();
120   }
121
122   // ----------------------- Ajout de groupe à un parent ----------------------
123
124   void cxios_xml_tree_add_fieldgroup
125      (XFieldGroupPtr  parent_, XFieldGroupPtr * child_, const char * child_id, int child_id_size)
126   {
127      std::string child_id_str;
128      boost::shared_ptr<xmlioserver::tree::CFieldGroup> fieldgroup =
129         xmlioserver::CObjectFactory::GetObject<xmlioserver::tree::CFieldGroup>(parent_);
130
131      if (cstr2string(child_id, child_id_size, child_id_str))
132         *child_ = xmlioserver::CGroupFactory::CreateGroup(fieldgroup, child_id_str).get();
133      else
134         *child_ = xmlioserver::CGroupFactory::CreateGroup(fieldgroup).get();
135   }
136
137   void cxios_xml_tree_add_gridgroup
138      (XGridGroupPtr   parent_, XGridGroupPtr * child_, const char * child_id, int child_id_size)
139   {
140      std::string child_id_str;
141      boost::shared_ptr<xmlioserver::tree::CGridGroup> gridgroup =
142         xmlioserver::CObjectFactory::GetObject<xmlioserver::tree::CGridGroup>(parent_);
143
144      if (cstr2string(child_id, child_id_size, child_id_str))
145         *child_ = xmlioserver::CGroupFactory::CreateGroup(gridgroup, child_id_str).get();
146      else
147         *child_ = xmlioserver::CGroupFactory::CreateGroup(gridgroup).get();
148   }
149
150   void cxios_xml_tree_add_filegroup
151      (XFileGroupPtr parent_, XFileGroupPtr * child_, const char * child_id, int child_id_size)
152   {
153      std::string child_id_str;
154      boost::shared_ptr<xmlioserver::tree::CFileGroup> filegroup =
155         xmlioserver::CObjectFactory::GetObject<xmlioserver::tree::CFileGroup>(parent_);
156
157      if (cstr2string(child_id, child_id_size, child_id_str))
158         *child_ = xmlioserver::CGroupFactory::CreateGroup(filegroup, child_id_str).get();
159      else
160         *child_ = xmlioserver::CGroupFactory::CreateGroup(filegroup).get();
161   }
162
163   void cxios_xml_tree_add_axisgroup
164      (XAxisGroupPtr parent_, XAxisGroupPtr * child_, const char * child_id, int child_id_size)
165   {
166      std::string child_id_str;
167      boost::shared_ptr<xmlioserver::tree::CAxisGroup> axisgroup =
168         xmlioserver::CObjectFactory::GetObject<xmlioserver::tree::CAxisGroup>(parent_);
169
170      if (cstr2string(child_id, child_id_size, child_id_str))
171         *child_ = xmlioserver::CGroupFactory::CreateGroup(axisgroup, child_id_str).get();
172      else
173         *child_ = xmlioserver::CGroupFactory::CreateGroup(axisgroup).get();
174   }
175
176   void cxios_xml_tree_add_domaingroup
177      (XDomainGroupPtr parent_, XDomainGroupPtr * child_, const char * child_id, int child_id_size)
178   {
179      std::string child_id_str;
180      boost::shared_ptr<xmlioserver::tree::CDomainGroup> domaingroup =
181         xmlioserver::CObjectFactory::GetObject<xmlioserver::tree::CDomainGroup>(parent_);
182
183      if (cstr2string(child_id, child_id_size, child_id_str))
184         *child_ = xmlioserver::CGroupFactory::CreateGroup(domaingroup, child_id_str).get();
185      else
186         *child_ = xmlioserver::CGroupFactory::CreateGroup(domaingroup).get();
187   }
188
189   void cxios_xml_tree_add_fieldgrouptofile
190      (XFilePtr parent_, XFieldGroupPtr * child_, const char * child_id, int child_id_size)
191   {
192      std::string child_id_str; 
193      boost::shared_ptr<xmlioserver::tree::CFile> file =
194         xmlioserver::CObjectFactory::GetObject<xmlioserver::tree::CFile>(parent_);
195
196      if (file->getVirtualFieldGroup().get() == 0 )
197          file->setVirtualFieldGroup(file->getId());
198     
199      if (cstr2string(child_id, child_id_size, child_id_str))
200         *child_ = xmlioserver::CGroupFactory::CreateGroup(file->getVirtualFieldGroup(), child_id_str).get();
201      else
202         *child_ = xmlioserver::CGroupFactory::CreateGroup(file->getVirtualFieldGroup()).get();
203   }
204   
205   
206   // ----------------------- Affichage de l'arborescence ----------------------
207   
208   void cxios_xml_tree_show   (const char * filename, int filename_size) 
209   {
210      std::string filename_str;
211      try
212      {
213         if (cstr2string(filename, filename_size, filename_str))
214            xmlioserver::CTreeManager::PrintTreeToFile(filename_str);
215         else
216            xmlioserver::CTreeManager::PrintTreeToStream(std::clog);
217      }
218      catch (xmlioserver::CException & exc)
219      {
220         std::cerr << exc.getMessage() << std::endl;
221         exit (EXIT_FAILURE);
222      }
223   }
224     
225   
226   // ----------------------- Parsing de document xml --------------------------
227   
228   void cxios_xml_parse_file  (const char * filename  , int filename_size)
229   {
230      std::string filename_str; 
231      if (!cstr2string(filename, filename_size, filename_str)) return;
232
233      try
234      {
235         xmlioserver::CTreeManager::ParseFile(filename_str);
236      }
237      catch (xmlioserver::CException & exc)
238      {
239         std::cerr << exc.getMessage() << std::endl;
240         exit (EXIT_FAILURE);
241      }
242   }
243   
244   void cxios_xml_parse_string(const char * xmlcontent, int xmlcontent_size)
245   {
246      std::string xmlcontent_str; 
247      if (!cstr2string(xmlcontent, xmlcontent_size, xmlcontent_str)) return;
248
249      try
250      {
251         xmlioserver::CTreeManager::ParseString(xmlcontent_str);
252      }
253      catch (xmlioserver::CException & exc)
254      {
255         std::cerr << exc.getMessage() << std::endl;
256         exit (EXIT_FAILURE);
257      }
258   }
259   
260
261
262} // extern "C"
Note: See TracBrowser for help on using the repository browser.