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