1 | #include "variable.hpp" |
---|
2 | |
---|
3 | #include "attribute_template_impl.hpp" |
---|
4 | #include "object_template_impl.hpp" |
---|
5 | #include "group_template_impl.hpp" |
---|
6 | |
---|
7 | #include "object_factory.hpp" |
---|
8 | #include "object_factory_impl.hpp" |
---|
9 | |
---|
10 | namespace xmlioserver { |
---|
11 | namespace tree { |
---|
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 | } |
---|
45 | |
---|
46 | const StdString & CVariable::getContent (void) const |
---|
47 | { |
---|
48 | return (this->content); |
---|
49 | } |
---|
50 | |
---|
51 | StdString CVariable::toString(void) const |
---|
52 | { |
---|
53 | StdOStringStream oss; |
---|
54 | |
---|
55 | oss << "<" << CVariable::GetName() << " "; |
---|
56 | if (this->hasId()) |
---|
57 | oss << " id=\"" << this->getId() << "\" "; |
---|
58 | oss << SuperClassAttribute::toString() << ">" << std::endl |
---|
59 | << this->content /*<< std::endl*/; |
---|
60 | oss << "</" << CVariable::GetName() << " >"; |
---|
61 | return (oss.str()); |
---|
62 | } |
---|
63 | |
---|
64 | void CVariable::toBinary(StdOStream & os) const |
---|
65 | { |
---|
66 | const StdString & content = this->content; |
---|
67 | const StdSize size = content.size(); |
---|
68 | SuperClass::toBinary(os); |
---|
69 | |
---|
70 | os.write (reinterpret_cast<const char*>(&size), sizeof(StdSize)); |
---|
71 | os.write (content.data(), size * sizeof(char)); |
---|
72 | } |
---|
73 | |
---|
74 | void CVariable::fromBinary(StdIStream & is) |
---|
75 | { |
---|
76 | SuperClass::fromBinary(is); |
---|
77 | StdSize size = 0; |
---|
78 | is.read (reinterpret_cast<char*>(&size), sizeof(StdSize)); |
---|
79 | this->content.assign(size, ' '); |
---|
80 | is.read (const_cast<char *>(this->content.data()), size * sizeof(char)); |
---|
81 | } |
---|
82 | |
---|
83 | void CVariableGroup::parse(xml::CXMLNode & node, bool withAttr) |
---|
84 | { |
---|
85 | boost::shared_ptr<CVariableGroup> group_ptr = (this->hasId()) |
---|
86 | ? CObjectFactory::GetObject<CVariableGroup>(this->getId()) |
---|
87 | : CObjectFactory::GetObject(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 | |
---|
100 | begindata = content.find_first_of ( "=", endid ) + 1; |
---|
101 | enddata = content.find_first_of ( ";", begindata ); |
---|
102 | subdata = content.substr ( begindata, enddata-begindata); |
---|
103 | |
---|
104 | CGroupFactory::CreateChild(group_ptr, subid)->content = subdata; |
---|
105 | } |
---|
106 | } |
---|
107 | else |
---|
108 | { |
---|
109 | SuperClass::parse(node, withAttr); |
---|
110 | } |
---|
111 | //SuperClass::parse(node, withAttr); |
---|
112 | |
---|
113 | } |
---|
114 | |
---|
115 | } // namespace tree |
---|
116 | } // namespace xmlioserver |
---|