source: XIOS/trunk/src/node/variable.cpp @ 436

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

Eliminate space on variable.

YM

File size: 3.6 KB
Line 
1#include "variable.hpp"
2
3#include "attribute_template.hpp"
4#include "object_template.hpp"
5#include "group_template.hpp"
6#include "object_factory.hpp"
7#include "xmlioserver_spl.hpp"
8#include "type.hpp"
9#include <boost/algorithm/string.hpp>
10
11namespace xios {
12
13   /// ////////////////////// Définitions ////////////////////// ///
14
15   CVariable::CVariable(void)
16      : CObjectTemplate<CVariable>()
17      , CVariableAttributes()
18      , content()
19   { /* Ne rien faire de plus */ }
20
21   CVariable::CVariable(const StdString & id)
22      : CObjectTemplate<CVariable>(id)
23      , CVariableAttributes()
24      , content()
25   { /* Ne rien faire de plus */ }
26
27   CVariable::~CVariable(void)
28   { /* Ne rien faire de plus */ }
29
30   StdString CVariable::GetName(void)   { return (StdString("variable")); }
31   StdString CVariable::GetDefName(void){ return (CVariable::GetName()); }
32   ENodeType CVariable::GetType(void)   { return (eVariable); }
33
34   void CVariable::parse(xml::CXMLNode & node)
35   {
36      SuperClass::parse(node);
37      StdString id = (this->hasId()) ? this->getId() : StdString("undefined");
38      if (!node.getContent(this->content))
39      {
40         ERROR("CVariable::parse(xml::CXMLNode & node)",
41               << "[ variable id = " << id
42               << " ] variable is not defined !");
43      }
44      content = boost::to_lower_copy(boost::trim_copy(content)) ;
45   }
46
47   const StdString & CVariable::getContent (void) const
48   {
49      return (this->content);
50   }
51
52   StdString CVariable::toString(void) const
53   {
54      StdOStringStream oss;
55
56      oss << "<" << CVariable::GetName() << " ";
57      if (this->hasId())
58         oss << " id=\"" << this->getId() << "\" ";
59      oss << SuperClassAttribute::toString() << ">" << std::endl
60          << this->content /*<< std::endl*/;
61      oss << "</" << CVariable::GetName() << " >";
62      return (oss.str());
63   }
64/*
65   void CVariable::toBinary(StdOStream & os) const
66   {
67     const StdString & content = this->content;
68     const StdSize size        =  content.size();
69     SuperClass::toBinary(os);
70
71     os.write (reinterpret_cast<const char*>(&size), sizeof(StdSize));
72     os.write (content.data(), size * sizeof(char));
73   }
74
75   void CVariable::fromBinary(StdIStream & is)
76   {
77      SuperClass::fromBinary(is);
78      StdSize size  = 0;
79      is.read (reinterpret_cast<char*>(&size), sizeof(StdSize));
80      this->content.assign(size, ' ');
81      is.read (const_cast<char *>(this->content.data()), size * sizeof(char));
82   }
83*/
84   void CVariableGroup::parse(xml::CXMLNode & node, bool withAttr)
85   {
86      CVariableGroup* group_ptr = (this->hasId())
87         ? CVariableGroup::get(this->getId()) : CVariableGroup::get(this);
88
89      StdString content;
90      if (this->getId().compare(CVariableGroup::GetDefName()) != 0 && node.getContent(content))
91      {
92        StdSize beginid = 0, endid = 0, begindata = 0, enddata = 0;
93        StdString subdata, subid;
94
95        while ((beginid = content.find_first_not_of ( " \r\n\t;", enddata)) != StdString::npos)
96        {
97           endid   = content.find_first_of ( " \r\n\t=", beginid );
98           subid   = content.substr ( beginid, endid-beginid);
99           subid   = boost::to_lower_copy(boost::trim_copy(subid)) ;
100
101           begindata = content.find_first_of ( "=", endid ) + 1;
102           enddata   = content.find_first_of ( ";", begindata );
103           subdata   = content.substr ( begindata, enddata-begindata);
104           subdata   = boost::to_lower_copy(boost::trim_copy(subdata)) ;
105           group_ptr->createChild(subid)->content = subdata ;
106        }
107      }
108      else
109      {
110         SuperClass::parse(node, withAttr);
111      }
112      //SuperClass::parse(node, withAttr);
113
114   }
115
116} // namespace xios
Note: See TracBrowser for help on using the repository browser.