source: XIOS3/dev/mhedley/buildCompilationPatchesA/src/xml_node.cpp @ 2698

Last change on this file since 2698 was 2629, checked in by jderouillat, 10 months ago

Delete boost dependencies, the few features used are replaced by functions stored in extern/boost_extraction

  • 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: 3.5 KB
Line 
1#include "xml_node.hpp"
2#include <boost_extract.hpp>
3
4namespace xios
5{
6   namespace xml
7   {
8      /// ////////////////////// Définitions ////////////////////// ///
9
10      StdString CXMLNode::RootName("simulation");
11
12      CXMLNode::CXMLNode(rapidxml::xml_node<char> * const root)
13         : node(root)
14         , level(0)
15      { /* Ne rien faire de plus */ }
16
17      CXMLNode::~CXMLNode(void)
18      { /* Ne rien faire de plus */ }
19
20      StdString CXMLNode::getElementName(void) const
21      { 
22         return (this->node->name()); 
23      }
24
25      bool CXMLNode::goToNextElement(void)
26      {
27         bool retvalue = false;
28         for(rapidxml::xml_node<char> * nextElement = this->node->next_sibling();
29                                      ; nextElement = nextElement->next_sibling())
30         {
31            if (nextElement == NULL) break;
32            else if (nextElement->type() == rapidxml::node_element)
33            { 
34               node = nextElement;
35               return (!retvalue);
36            }
37         }
38         return (retvalue);
39      }
40
41      bool CXMLNode::goToChildElement(void)
42      {
43         bool retvalue = false;
44         rapidxml::xml_node<char> * nextElement = this->node->first_node();
45         if (nextElement != NULL)
46         {
47            for(;;nextElement = nextElement->next_sibling())
48            {
49               if (nextElement == NULL) break;
50               else if (nextElement->type() == rapidxml::node_element)
51               { 
52                  node = nextElement;
53                  level++;
54                  return (!retvalue); 
55               }
56            }
57         }
58         return (retvalue);
59      }
60
61      bool CXMLNode::goToParentElement(void)
62      {
63         bool retvalue = false;
64         if (!(this->getElementName().compare(CXMLNode::RootName)) || (level == 0))
65            return (retvalue);
66         node = node->parent();
67         level--;
68         return (!retvalue);
69      }
70/*
71      bool CXMLNode::getContent(StdString & content)
72      {
73         if (this->node->value_size() == 0) return (false);
74         content.assign(this->node->value(), this->node->value_size());
75         return (true);
76      }
77*/
78      bool CXMLNode::getContent(StdString & content)
79      {
80         content="" ;
81         bool retvalue = false;
82         
83         rapidxml::xml_node<char> * nextElement = this->node->first_node();
84         while (nextElement != NULL)
85         {
86             if (nextElement->type() == rapidxml::node_data) content=content+std::string(nextElement->value(),nextElement->value_size());
87             nextElement = nextElement->next_sibling(); 
88         }
89         xios_replace_all(content,"\n"," ") ;
90         content = xios_trim_copy(content); 
91         if (content.size()==0) return false ;
92         else return true ;
93      }
94
95      const StdString & CXMLNode::GetRootName(void)
96      { 
97         return (CXMLNode::RootName); 
98      }
99
100      THashAttributes CXMLNode::getAttributes(void) const
101      {
102         THashAttributes attributes;
103         rapidxml::xml_attribute<char> *currentAttr = NULL;
104
105         if ((currentAttr = this->node->first_attribute()) != NULL)
106         {
107            do 
108            {
109               attributes.insert(std::pair<StdString, StdString>
110                                (StdString(currentAttr->name()),
111                                 StdString(currentAttr->value())));
112            } while ((currentAttr = currentAttr->next_attribute()) != NULL);
113         }
114
115         return (attributes) ;
116      }
117
118   }// namespace xml
119} // namespace xios
Note: See TracBrowser for help on using the repository browser.