1 | #include "field.hpp" |
---|
2 | |
---|
3 | #include "attribute_template_impl.hpp" |
---|
4 | #include "object_template_impl.hpp" |
---|
5 | #include "group_template_impl.hpp" |
---|
6 | |
---|
7 | #include "node_type.hpp" |
---|
8 | |
---|
9 | namespace xmlioserver{ |
---|
10 | namespace tree { |
---|
11 | |
---|
12 | /// ////////////////////// Définitions ////////////////////// /// |
---|
13 | |
---|
14 | CField::CField(void) |
---|
15 | : CObjectTemplate<CField>(), CFieldAttributes() |
---|
16 | , baseRefObject(), refObject(), grid(), file(), foperation(NULL) |
---|
17 | { /* Ne rien faire de plus */ } |
---|
18 | |
---|
19 | CField::CField(const StdString & id) |
---|
20 | : CObjectTemplate<CField>(id), CFieldAttributes() |
---|
21 | , baseRefObject(), refObject(), foperation(NULL) |
---|
22 | { /* Ne rien faire de plus */ } |
---|
23 | |
---|
24 | CField::~CField(void) |
---|
25 | { |
---|
26 | if (this->foperation == NULL) |
---|
27 | delete this->foperation; |
---|
28 | } |
---|
29 | |
---|
30 | //---------------------------------------------------------------- |
---|
31 | |
---|
32 | void CField::setRelFile(const boost::shared_ptr<CFile> _file) |
---|
33 | { |
---|
34 | this->file = _file; |
---|
35 | } |
---|
36 | |
---|
37 | //---------------------------------------------------------------- |
---|
38 | |
---|
39 | StdString CField::GetName(void) { return (StdString("field")); } |
---|
40 | StdString CField::GetDefName(void){ return (CField::GetName()); } |
---|
41 | ENodeType CField::GetType(void) { return (eField); } |
---|
42 | |
---|
43 | //---------------------------------------------------------------- |
---|
44 | |
---|
45 | boost::shared_ptr<CGrid> CField::getRelGrid(void) const |
---|
46 | { |
---|
47 | return (this->grid); |
---|
48 | } |
---|
49 | |
---|
50 | //---------------------------------------------------------------- |
---|
51 | |
---|
52 | boost::shared_ptr<CFile> CField::getRelFile(void) const |
---|
53 | { |
---|
54 | return (this->file); |
---|
55 | } |
---|
56 | |
---|
57 | //---------------------------------------------------------------- |
---|
58 | |
---|
59 | boost::shared_ptr<CField> CField::getDirectFieldReference(void) const |
---|
60 | { |
---|
61 | if (this->field_ref.isEmpty()) |
---|
62 | return (this->getBaseFieldReference()); |
---|
63 | |
---|
64 | if (! CObjectFactory::HasObject<CField>(this->field_ref.getValue())) |
---|
65 | ERROR("CField::getDirectFieldReference(void)", |
---|
66 | << "[ ref_name = " << this->field_ref.getValue() << "]" |
---|
67 | << " invalid field name !"); |
---|
68 | |
---|
69 | return (CObjectFactory::GetObject<CField>(this->field_ref.getValue())); |
---|
70 | } |
---|
71 | |
---|
72 | //---------------------------------------------------------------- |
---|
73 | |
---|
74 | const boost::shared_ptr<CField> CField::getBaseFieldReference(void) const |
---|
75 | { |
---|
76 | return (baseRefObject); |
---|
77 | } |
---|
78 | |
---|
79 | //---------------------------------------------------------------- |
---|
80 | |
---|
81 | const std::vector<boost::shared_ptr<CField> > & CField::getAllReference(void) const |
---|
82 | { |
---|
83 | return (refObject); |
---|
84 | } |
---|
85 | |
---|
86 | //---------------------------------------------------------------- |
---|
87 | |
---|
88 | const StdString & CField::getBaseFieldId(void) const |
---|
89 | { |
---|
90 | return (this->getBaseFieldReference()->getId()); |
---|
91 | } |
---|
92 | |
---|
93 | //---------------------------------------------------------------- |
---|
94 | |
---|
95 | bool CField::hasDirectFieldReference(void) const |
---|
96 | { |
---|
97 | return (!this->field_ref.isEmpty()); |
---|
98 | } |
---|
99 | |
---|
100 | //---------------------------------------------------------------- |
---|
101 | |
---|
102 | void CField::solveRefInheritance(void) |
---|
103 | { |
---|
104 | std::set<CField *> sset; |
---|
105 | boost::shared_ptr<CField> refer_sptr; |
---|
106 | CField * refer_ptr = this; |
---|
107 | this->baseRefObject = CObjectFactory::GetObject<CField>(this); |
---|
108 | while (refer_ptr->hasDirectFieldReference()) |
---|
109 | { |
---|
110 | refer_sptr = refer_ptr->getDirectFieldReference(); |
---|
111 | refer_ptr = refer_sptr.get(); |
---|
112 | |
---|
113 | if(sset.end() != sset.find(refer_ptr)) |
---|
114 | { |
---|
115 | DEBUG (<< "Dépendance circulaire stoppée pour l'objet de type CField sur " |
---|
116 | << "\"" + refer_ptr->getId() + "\" !"); |
---|
117 | break; |
---|
118 | } |
---|
119 | |
---|
120 | SuperClassAttribute::setAttributes(refer_ptr); |
---|
121 | sset.insert(refer_ptr); |
---|
122 | baseRefObject = refer_sptr; |
---|
123 | refObject.push_back(refer_sptr); |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | //---------------------------------------------------------------- |
---|
128 | |
---|
129 | void CField::solveOperation(void) |
---|
130 | { |
---|
131 | // TODO : à compléter; |
---|
132 | } |
---|
133 | |
---|
134 | //---------------------------------------------------------------- |
---|
135 | |
---|
136 | void CField::solveGridReference(void) |
---|
137 | { |
---|
138 | boost::shared_ptr<CDomain> domain; |
---|
139 | boost::shared_ptr<CAxis> axis; |
---|
140 | |
---|
141 | if (!domain_ref.isEmpty()) |
---|
142 | { |
---|
143 | if (CObjectFactory::HasObject<CDomain>(domain_ref.getValue())) |
---|
144 | domain = CObjectFactory::GetObject<CDomain>(domain_ref.getValue()) ; |
---|
145 | else |
---|
146 | ERROR("CField::solveGridReference(void)", |
---|
147 | << "Référence au domaine nommé \'" |
---|
148 | << domain_ref.getValue() << "\' incorrecte") ; |
---|
149 | } |
---|
150 | |
---|
151 | if (!axis_ref.isEmpty()) |
---|
152 | { |
---|
153 | if (CObjectFactory::HasObject<CAxis>(axis_ref.getValue())) |
---|
154 | axis = CObjectFactory::GetObject<CAxis>(axis_ref.getValue()) ; |
---|
155 | else |
---|
156 | ERROR("CField::solveGridReference(void)", |
---|
157 | << "Référence à l'axe nommé \'" |
---|
158 | << axis_ref.getValue() <<"\' incorrecte") ; |
---|
159 | } |
---|
160 | |
---|
161 | if (!grid_ref.isEmpty()) |
---|
162 | { |
---|
163 | if (CObjectFactory::HasObject<CGrid>(grid_ref.getValue())) |
---|
164 | this->grid = CObjectFactory::GetObject<CGrid>(grid_ref.getValue()) ; |
---|
165 | else |
---|
166 | ERROR("CField::solveGridReference(void)", |
---|
167 | << "Référence à la grille nommée \'" |
---|
168 | << grid_ref.getValue() << "\' incorrecte"); |
---|
169 | if (!domain_ref.isEmpty()) |
---|
170 | DEBUG(<< "Définition conjointe de la grille " |
---|
171 | << "et du domaine, la grille prévaut..." ); |
---|
172 | if (!axis_ref.isEmpty()) |
---|
173 | DEBUG(<< "Définition conjointe de la grille " |
---|
174 | << "et de l'axe vertical, la grille prévaut...") ; |
---|
175 | } |
---|
176 | else |
---|
177 | { |
---|
178 | if (!domain_ref.isEmpty()) |
---|
179 | { |
---|
180 | if (!axis_ref.isEmpty()) |
---|
181 | { |
---|
182 | this->grid = CGrid::CreateGrid(domain, axis) ; |
---|
183 | this->grid_ref.setValue(this->grid->getId()); |
---|
184 | } |
---|
185 | else |
---|
186 | { |
---|
187 | this->grid = CGrid::CreateGrid(domain) ; |
---|
188 | this->grid_ref.setValue(this->grid->getId()); |
---|
189 | } |
---|
190 | } |
---|
191 | else |
---|
192 | { |
---|
193 | ERROR("CField::solveGridReference(void)", |
---|
194 | << "Le domaine horizontal pour le champ X n'est pas défini"); |
---|
195 | } |
---|
196 | } |
---|
197 | grid->solveReference() ; |
---|
198 | } |
---|
199 | |
---|
200 | } // namespace tree |
---|
201 | |
---|
202 | ///------------------------------------------------------------------- |
---|
203 | |
---|
204 | template <> |
---|
205 | void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void) |
---|
206 | { |
---|
207 | if (this->group_ref.isEmpty()) return; |
---|
208 | StdString gref = this->group_ref.getValue(); |
---|
209 | |
---|
210 | if (!CObjectFactory::HasObject<CFieldGroup>(gref)) |
---|
211 | ERROR("CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void)", |
---|
212 | << "[ gref = " << gref << "]" |
---|
213 | << " invalid group name !"); |
---|
214 | |
---|
215 | boost::shared_ptr<CFieldGroup> group |
---|
216 | = CObjectFactory::GetObject<CFieldGroup>(gref); |
---|
217 | boost::shared_ptr<CFieldGroup> owner |
---|
218 | = CObjectFactory::GetObject<CFieldGroup> |
---|
219 | (boost::polymorphic_downcast<CFieldGroup*>(this)); |
---|
220 | |
---|
221 | std::vector<boost::shared_ptr<CField> > allChildren = group->getAllChildren(); |
---|
222 | std::vector<boost::shared_ptr<CField> >::iterator |
---|
223 | it = allChildren.begin(), end = allChildren.end(); |
---|
224 | |
---|
225 | for (; it != end; it++) |
---|
226 | { |
---|
227 | boost::shared_ptr<CField> child = *it; |
---|
228 | if (child->hasId()) |
---|
229 | CGroupFactory::CreateChild(owner)->field_ref.setValue(child->getId()); |
---|
230 | } |
---|
231 | } |
---|
232 | |
---|
233 | ///------------------------------------------------------------------- |
---|
234 | |
---|
235 | } // namespace xmlioserver |
---|