New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
variable.cpp in vendors/XIOS/current/src/node – NEMO

source: vendors/XIOS/current/src/node/variable.cpp @ 3428

Last change on this file since 3428 was 3428, checked in by rblod, 12 years ago

importing initial XIOS vendor drop

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