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 | |
---|
11 | namespace 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::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 | CVariable::EVarType CVariable::getVarType(void) const |
---|
66 | { |
---|
67 | EVarType ret ; |
---|
68 | |
---|
69 | if (type.isEmpty()) ret=t_undefined ; |
---|
70 | else |
---|
71 | { |
---|
72 | string varType=boost::to_lower_copy(boost::trim_copy(type.getValue())) ; |
---|
73 | if (varType=="int") ret=t_int ; |
---|
74 | else if (varType=="short int" || varType=="short") ret=t_short_int ; |
---|
75 | else if (varType=="long int" || varType=="long") ret=t_long_int ; |
---|
76 | else if (varType=="float") ret=t_float ; |
---|
77 | else if (varType=="double") ret=t_double ; |
---|
78 | else if (varType=="long double") ret=t_long_double ; |
---|
79 | else if (varType=="bool") ret=t_bool ; |
---|
80 | else if (varType=="long double") ret=t_long_double ; |
---|
81 | else if (varType=="string") ret=t_string ; |
---|
82 | } |
---|
83 | return ret ; |
---|
84 | } |
---|
85 | |
---|
86 | /* |
---|
87 | void CVariable::toBinary(StdOStream & os) const |
---|
88 | { |
---|
89 | const StdString & content = this->content; |
---|
90 | const StdSize size = content.size(); |
---|
91 | SuperClass::toBinary(os); |
---|
92 | |
---|
93 | os.write (reinterpret_cast<const char*>(&size), sizeof(StdSize)); |
---|
94 | os.write (content.data(), size * sizeof(char)); |
---|
95 | } |
---|
96 | |
---|
97 | void CVariable::fromBinary(StdIStream & is) |
---|
98 | { |
---|
99 | SuperClass::fromBinary(is); |
---|
100 | StdSize size = 0; |
---|
101 | is.read (reinterpret_cast<char*>(&size), sizeof(StdSize)); |
---|
102 | this->content.assign(size, ' '); |
---|
103 | is.read (const_cast<char *>(this->content.data()), size * sizeof(char)); |
---|
104 | } |
---|
105 | */ |
---|
106 | void CVariableGroup::parse(xml::CXMLNode & node, bool withAttr) |
---|
107 | { |
---|
108 | CVariableGroup* group_ptr = (this->hasId()) |
---|
109 | ? CVariableGroup::get(this->getId()) : CVariableGroup::get(this); |
---|
110 | |
---|
111 | StdString content; |
---|
112 | if (this->getId().compare(CVariableGroup::GetDefName()) != 0 && node.getContent(content)) |
---|
113 | { |
---|
114 | StdSize beginid = 0, endid = 0, begindata = 0, enddata = 0; |
---|
115 | StdString subdata, subid; |
---|
116 | |
---|
117 | while ((beginid = content.find_first_not_of ( " \r\n\t;", enddata)) != StdString::npos) |
---|
118 | { |
---|
119 | endid = content.find_first_of ( " \r\n\t=", beginid ); |
---|
120 | subid = content.substr ( beginid, endid-beginid); |
---|
121 | subid = boost::to_lower_copy(boost::trim_copy(subid)) ; |
---|
122 | |
---|
123 | begindata = content.find_first_of ( "=", endid ) + 1; |
---|
124 | enddata = content.find_first_of ( ";", begindata ); |
---|
125 | subdata = content.substr ( begindata, enddata-begindata); |
---|
126 | subdata = boost::trim_copy(subdata) ; |
---|
127 | group_ptr->createChild(subid)->content = subdata ; |
---|
128 | } |
---|
129 | } |
---|
130 | else |
---|
131 | { |
---|
132 | SuperClass::parse(node, withAttr); |
---|
133 | } |
---|
134 | //SuperClass::parse(node, withAttr); |
---|
135 | |
---|
136 | } |
---|
137 | |
---|
138 | } // namespace xios |
---|