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