source: XIOS/trunk/src/group_parser.hpp @ 631

Last change on this file since 631 was 591, checked in by rlacroix, 9 years ago

Remove leftovers from the XMLIO age.

  • 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
File size: 4.6 KB
RevLine 
[591]1#ifndef __XIOS_GroupParser__
2#define __XIOS_GroupParser__
[219]3
4/// boost headers ///
5#include <boost/cast.hpp>
6
[335]7namespace xios
[219]8{
9   /// ////////////////////// Définitions ////////////////////// ///
10   template <class U, class V, class W>
11      void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr)
12   {
13
14      StdString name = node.getElementName();
[278]15      xml::THashAttributes attributes = node.getAttributes();
[219]16      if (withAttr)
[278]17      {
[219]18         CGroupTemplate<U, V, W>::SuperClass::parse(node);
[278]19         if (attributes.end() != attributes.find("src"))
20         {
21            StdIFStream ifs ( attributes["src"].c_str() , StdIFStream::in );
[462]22            if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 )
23               ERROR(" void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr)",
24                     <<endl<< "Can not open <"<<attributes["src"].c_str()<<"> file" );
[278]25            if (!ifs.good())
26               ERROR("CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr)",
27                     << "[ filename = " << attributes["src"] << " ] Bad xml stream !");
[462]28            xml::CXMLParser::ParseInclude(ifs, attributes["src"].c_str(), *this);
[278]29         }
30      }
[219]31
32      // PARSING POUR GESTION DES ENFANTS
[347]33           V* group_ptr = (this->hasId()) 
34         ? V::get(this->getId())
35         : boost::polymorphic_downcast<V*>(this);
[219]36
37      if (!(node.goToChildElement()))
38      {
39         if (this->hasId())
40         {
41            DEBUG(<< "L'objet de type \'" << V::GetName()
42                  << "\' nommé \'" << this->getId()
43                  << "\' ne contient pas d\'enfant !");
44         }
45      }
46      else
47      {
48         do { // Parcours pour traitement.
49
50            StdString name = node.getElementName();
51            attributes.clear();
52            attributes = node.getAttributes();
53
54            if (name.compare(V::GetName()) == 0)
55            {
56               if (attributes.end() == attributes.find("id"))
[347]57                  CGroupFactory::CreateGroup(group_ptr->getShared())->parse(node);
[219]58               else
[347]59                  CGroupFactory::CreateGroup(group_ptr->getShared(), attributes["id"])->parse(node);
[219]60               continue;
61            }
62
63            if (name.compare(U::GetName()) == 0)
64            {
65               if (attributes.end() == attributes.find("id"))
[347]66                  CGroupFactory::CreateChild(group_ptr->getShared())->parse(node);
[219]67               else
[347]68                  CGroupFactory::CreateChild(group_ptr->getShared(), attributes["id"])->parse(node);
[219]69               continue;
70            }
71
[346]72            DEBUG(<< "Dans le contexte \'" << CContext::getCurrent()->getId()
[219]73                  << "\', un objet de type \'" << V::GetName()
74                  << "\' ne peut contenir qu'un objet de type \'" << V::GetName()
75                  << "\' ou de type \'" << U::GetName()
[278]76                  << "\' (reçu : " << name << ") !");
[219]77
78         } while (node.goToNextElement());
79         node.goToParentElement(); // Retour au parent
80      }
81   }
[472]82 
83  /// ////////////////////// Définitions ////////////////////// ///
84   template <class U, class V, class W>
85      void CGroupTemplate<U, V, W>::parseChild(xml::CXMLNode & node)
86   {
[219]87
[472]88
89      // PARSING POUR GESTION DES ENFANTS
90           V* group_ptr = (this->hasId()) 
91         ? V::get(this->getId())
92         : boost::polymorphic_downcast<V*>(this);
93
94          StdString name = node.getElementName();
95          attributes.clear();
96          attributes = node.getAttributes();
97
98          if (name.compare(V::GetName()) == 0)
99          {
100             if (attributes.end() == attributes.find("id"))
101                CGroupFactory::CreateGroup(group_ptr->getShared())->parse(node);
102                return ;
103             else
104                CGroupFactory::CreateGroup(group_ptr->getShared(), attributes["id"])->parse(node);
105             continue;
106          }
107
108          if (name.compare(U::GetName()) == 0)
109          {
110             if (attributes.end() == attributes.find("id"))
111                CGroupFactory::CreateChild(group_ptr->getShared())->parse(node);
112                return ;
113             else
114                CGroupFactory::CreateChild(group_ptr->getShared(), attributes["id"])->parse(node);
115             continue;
116          }
117
118          DEBUG(<< "Dans le contexte \'" << CContext::getCurrent()->getId()
119                << "\', un objet de type \'" << V::GetName()
120                << "\' ne peut contenir qu'un objet de type \'" << V::GetName()
121                << "\' ou de type \'" << U::GetName()
122                << "\' (reçu : " << name << ") !");
123
124   }
[335]125} // namespace xios
[219]126
[591]127#endif // __XIOS_GroupParser__
Note: See TracBrowser for help on using the repository browser.