[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" |
---|
[268] | 9 | |
---|
[335] | 10 | namespace xios { |
---|
[268] | 11 | |
---|
| 12 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 13 | |
---|
| 14 | CVariable::CVariable(void) |
---|
| 15 | : CObjectTemplate<CVariable>() |
---|
| 16 | , CVariableAttributes() |
---|
[274] | 17 | , content() |
---|
[268] | 18 | { /* Ne rien faire de plus */ } |
---|
| 19 | |
---|
| 20 | CVariable::CVariable(const StdString & id) |
---|
| 21 | : CObjectTemplate<CVariable>(id) |
---|
| 22 | , CVariableAttributes() |
---|
[274] | 23 | , content() |
---|
[268] | 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 | |
---|
[274] | 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 | } |
---|
[369] | 62 | /* |
---|
[274] | 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 | } |
---|
[369] | 81 | */ |
---|
[274] | 82 | void CVariableGroup::parse(xml::CXMLNode & node, bool withAttr) |
---|
| 83 | { |
---|
[347] | 84 | CVariableGroup* group_ptr = (this->hasId()) |
---|
[346] | 85 | ? CVariableGroup::get(this->getId()) : CVariableGroup::get(this); |
---|
[274] | 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); |
---|
[387] | 97 | subid = boost::to_lower_copy(boost::trim_copy(subid)) ; |
---|
[274] | 98 | |
---|
| 99 | begindata = content.find_first_of ( "=", endid ) + 1; |
---|
| 100 | enddata = content.find_first_of ( ";", begindata ); |
---|
| 101 | subdata = content.substr ( begindata, enddata-begindata); |
---|
[387] | 102 | subdata = boost::to_lower_copy(boost::trim_copy(subdata)) ; |
---|
[274] | 103 | |
---|
[346] | 104 | group_ptr->createChild(subid)->content = subdata ; |
---|
[274] | 105 | } |
---|
| 106 | } |
---|
| 107 | else |
---|
| 108 | { |
---|
| 109 | SuperClass::parse(node, withAttr); |
---|
| 110 | } |
---|
| 111 | //SuperClass::parse(node, withAttr); |
---|
| 112 | |
---|
| 113 | } |
---|
| 114 | |
---|
[335] | 115 | } // namespace xios |
---|