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