1 | #include "context.hpp" |
---|
2 | |
---|
3 | #include "attribute_template_impl.hpp" |
---|
4 | #include "object_template_impl.hpp" |
---|
5 | #include "group_template_impl.hpp" |
---|
6 | |
---|
7 | namespace xmlioserver { |
---|
8 | namespace tree { |
---|
9 | |
---|
10 | /// ////////////////////// Définitions ////////////////////// /// |
---|
11 | |
---|
12 | CContext::CContext(void) |
---|
13 | : CObjectTemplate<CContext>(), CContextAttributes() |
---|
14 | { /* Ne rien faire de plus */ } |
---|
15 | |
---|
16 | CContext::CContext(const StdString & id) |
---|
17 | : CObjectTemplate<CContext>(id), CContextAttributes() |
---|
18 | { /* Ne rien faire de plus */ } |
---|
19 | |
---|
20 | CContext::~CContext(void) |
---|
21 | { /* Ne rien faire de plus */ } |
---|
22 | |
---|
23 | //---------------------------------------------------------------- |
---|
24 | |
---|
25 | StdString CContext::GetName(void) { return (StdString("context")); } |
---|
26 | StdString CContext::GetDefName(void){ return (CContext::GetName()); } |
---|
27 | ENodeType CContext::GetType(void) { return (eContext); } |
---|
28 | |
---|
29 | //---------------------------------------------------------------- |
---|
30 | |
---|
31 | boost::shared_ptr<CContextGroup> CContext::GetContextGroup(void) |
---|
32 | { |
---|
33 | static boost::shared_ptr<CContextGroup> group_context |
---|
34 | (new CContextGroup(xml::CXMLNode::GetRootName())); |
---|
35 | return (group_context); |
---|
36 | } |
---|
37 | |
---|
38 | //---------------------------------------------------------------- |
---|
39 | |
---|
40 | void CContext::parse(xml::CXMLNode & node) |
---|
41 | { |
---|
42 | CContext::SuperClass::parse(node); |
---|
43 | |
---|
44 | // PARSING POUR GESTION DES ENFANTS |
---|
45 | xml::THashAttributes attributes; |
---|
46 | |
---|
47 | if (node.getElementName().compare(CContext::GetName())) |
---|
48 | DEBUG("Le noeud est mal nommé mais sera traité comme un contexte !"); |
---|
49 | |
---|
50 | if (!(node.goToChildElement())) |
---|
51 | { |
---|
52 | DEBUG("Le context ne contient pas d'enfant !"); |
---|
53 | } |
---|
54 | else |
---|
55 | { |
---|
56 | do { // Parcours des contextes pour traitement. |
---|
57 | |
---|
58 | StdString name = node.getElementName(); |
---|
59 | attributes.clear(); |
---|
60 | attributes = node.getAttributes(); |
---|
61 | |
---|
62 | if (attributes.end() != attributes.find("id")) |
---|
63 | { DEBUG(<< "Le noeud de définition possÚde un identifiant," |
---|
64 | << " ce dernier ne sera pas pris en compte lors du traitement !"); } |
---|
65 | |
---|
66 | #define DECLARE_NODE(Name_, name_) \ |
---|
67 | if (name.compare(C##Name_##Definition::GetDefName()) == 0) \ |
---|
68 | { CObjectFactory::CreateObject<C##Name_##Definition>(C##Name_##Definition::GetDefName()) -> parse(node); \ |
---|
69 | continue; } |
---|
70 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
71 | #include "node_type.conf" |
---|
72 | |
---|
73 | DEBUG(<< "L'élément nommé \'" << name |
---|
74 | << "\' dans le contexte \'" << CObjectFactory::GetCurrentContextId() |
---|
75 | << "\' ne représente pas une définition !"); |
---|
76 | |
---|
77 | } while (node.goToNextElement()); |
---|
78 | |
---|
79 | node.goToParentElement(); // Retour au parent |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | //---------------------------------------------------------------- |
---|
84 | |
---|
85 | void CContext::ShowTree(StdOStream & out) |
---|
86 | { |
---|
87 | StdString currentContextId = |
---|
88 | CObjectFactory::GetCurrentContextId(); |
---|
89 | std::vector<boost::shared_ptr<CContext> > def_vector = |
---|
90 | CContext::GetContextGroup()->getChildList(); |
---|
91 | std::vector<boost::shared_ptr<CContext> >::iterator |
---|
92 | it = def_vector.begin(), end = def_vector.end(); |
---|
93 | |
---|
94 | out << "<? xml version=\"1.0\" ?>" << std::endl; |
---|
95 | out << "< " << xml::CXMLNode::GetRootName() << " >" << std::endl; |
---|
96 | |
---|
97 | for (; it != end; it++) |
---|
98 | { |
---|
99 | boost::shared_ptr<CContext> context = *it; |
---|
100 | CObjectFactory::SetCurrentContextId(context->getId()); |
---|
101 | CGroupFactory::SetCurrentContextId(context->getId()); |
---|
102 | out << *context << std::endl; |
---|
103 | } |
---|
104 | |
---|
105 | out << "</ " << xml::CXMLNode::GetRootName() << " >" << std::endl; |
---|
106 | |
---|
107 | CObjectFactory::SetCurrentContextId(currentContextId); |
---|
108 | CGroupFactory::SetCurrentContextId(currentContextId); |
---|
109 | } |
---|
110 | |
---|
111 | //---------------------------------------------------------------- |
---|
112 | |
---|
113 | StdString CContext::toString(void) const |
---|
114 | { |
---|
115 | StdOStringStream oss; |
---|
116 | oss << "< " << CContext::GetName() |
---|
117 | << " id=\"" << this->getId() << "\" " |
---|
118 | << SuperClassAttribute::toString() << ">" << std::endl; |
---|
119 | if (!this->hasChild()) |
---|
120 | { |
---|
121 | //oss << "<!-- No definition -->" << std::endl; // fait planter l'incrémentation |
---|
122 | } |
---|
123 | else |
---|
124 | { |
---|
125 | |
---|
126 | #define DECLARE_NODE(Name_, name_) \ |
---|
127 | if (CObjectFactory::HasObject<C##Name_##Definition>(C##Name_##Definition::GetDefName())) \ |
---|
128 | oss << *CObjectFactory::GetObject<C##Name_##Definition>(C##Name_##Definition::GetDefName()) << std::endl; |
---|
129 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
130 | #include "node_type.conf" |
---|
131 | |
---|
132 | } |
---|
133 | |
---|
134 | oss << "</ " << CContext::GetName() << " >"; |
---|
135 | |
---|
136 | return (oss.str()); |
---|
137 | } |
---|
138 | |
---|
139 | //---------------------------------------------------------------- |
---|
140 | |
---|
141 | void CContext::solveDescInheritance(const CAttributeMap * const UNUSED(parent)) |
---|
142 | { |
---|
143 | #define DECLARE_NODE(Name_, name_) \ |
---|
144 | if (CObjectFactory::HasObject<C##Name_##Definition>(C##Name_##Definition::GetDefName())) \ |
---|
145 | CObjectFactory::GetObject<C##Name_##Definition>(C##Name_##Definition::GetDefName())->solveDescInheritance(); |
---|
146 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
147 | #include "node_type.conf" |
---|
148 | } |
---|
149 | |
---|
150 | //---------------------------------------------------------------- |
---|
151 | |
---|
152 | bool CContext::hasChild(void) const |
---|
153 | { |
---|
154 | return (false || |
---|
155 | #define DECLARE_NODE(Name_, name_) \ |
---|
156 | CObjectFactory::HasObject<C##Name_##Definition> (C##Name_##Definition::GetDefName()) || |
---|
157 | #define DECLARE_NODE_PAR(Name_, name_) |
---|
158 | #include "node_type.conf" |
---|
159 | false); |
---|
160 | } |
---|
161 | |
---|
162 | //---------------------------------------------------------------- |
---|
163 | |
---|
164 | void CContext::solveFieldRefInheritance(void) |
---|
165 | { |
---|
166 | if (!this->hasId()) return; |
---|
167 | std::vector<boost::shared_ptr<CField> > allField |
---|
168 | = CObjectTemplate<CField>::GetAllVectobject(this->getId()); |
---|
169 | std::vector<boost::shared_ptr<CField> >::iterator |
---|
170 | it = allField.begin(), end = allField.end(); |
---|
171 | |
---|
172 | for (; it != end; it++) |
---|
173 | { |
---|
174 | boost::shared_ptr<CField> field = *it; |
---|
175 | field->solveRefInheritance(); |
---|
176 | } |
---|
177 | } |
---|
178 | |
---|
179 | ///--------------------------------------------------------------- |
---|
180 | |
---|
181 | } // namespace tree |
---|
182 | } // namespace xmlioserver |
---|