[268] | 1 | #include "variable.hpp" |
---|
| 2 | |
---|
[352] | 3 | #include "attribute_template.hpp" |
---|
| 4 | #include "object_template.hpp" |
---|
| 5 | #include "group_template.hpp" |
---|
[268] | 6 | #include "object_factory.hpp" |
---|
[352] | 7 | #include "xmlioserver_spl.hpp" |
---|
| 8 | #include "type.hpp" |
---|
[388] | 9 | #include <boost/algorithm/string.hpp> |
---|
[268] | 10 | |
---|
[335] | 11 | namespace xios { |
---|
[268] | 12 | |
---|
| 13 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 14 | |
---|
| 15 | CVariable::CVariable(void) |
---|
| 16 | : CObjectTemplate<CVariable>() |
---|
| 17 | , CVariableAttributes() |
---|
[274] | 18 | , content() |
---|
[268] | 19 | { /* Ne rien faire de plus */ } |
---|
| 20 | |
---|
| 21 | CVariable::CVariable(const StdString & id) |
---|
| 22 | : CObjectTemplate<CVariable>(id) |
---|
| 23 | , CVariableAttributes() |
---|
[274] | 24 | , content() |
---|
[268] | 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 | |
---|
[274] | 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 | } |
---|
[389] | 44 | content = boost::to_lower_copy(boost::trim_copy(content)) ; |
---|
[274] | 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 | } |
---|
[369] | 64 | /* |
---|
[274] | 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 | } |
---|
[369] | 83 | */ |
---|
[274] | 84 | void CVariableGroup::parse(xml::CXMLNode & node, bool withAttr) |
---|
| 85 | { |
---|
[347] | 86 | CVariableGroup* group_ptr = (this->hasId()) |
---|
[346] | 87 | ? CVariableGroup::get(this->getId()) : CVariableGroup::get(this); |
---|
[274] | 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); |
---|
[387] | 99 | subid = boost::to_lower_copy(boost::trim_copy(subid)) ; |
---|
[274] | 100 | |
---|
| 101 | begindata = content.find_first_of ( "=", endid ) + 1; |
---|
| 102 | enddata = content.find_first_of ( ";", begindata ); |
---|
| 103 | subdata = content.substr ( begindata, enddata-begindata); |
---|
[387] | 104 | subdata = boost::to_lower_copy(boost::trim_copy(subdata)) ; |
---|
[346] | 105 | group_ptr->createChild(subid)->content = subdata ; |
---|
[274] | 106 | } |
---|
| 107 | } |
---|
| 108 | else |
---|
| 109 | { |
---|
| 110 | SuperClass::parse(node, withAttr); |
---|
| 111 | } |
---|
| 112 | //SuperClass::parse(node, withAttr); |
---|
| 113 | |
---|
| 114 | } |
---|
| 115 | |
---|
[335] | 116 | } // namespace xios |
---|