[152] | 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 | |
---|
[187] | 9 | #include "xios_manager.hpp" |
---|
| 10 | |
---|
[168] | 11 | namespace xmlioserver{ |
---|
| 12 | namespace tree { |
---|
| 13 | |
---|
| 14 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 15 | |
---|
| 16 | CField::CField(void) |
---|
| 17 | : CObjectTemplate<CField>(), CFieldAttributes() |
---|
[187] | 18 | , refObject(), baseRefObject() |
---|
| 19 | , grid(), file() |
---|
| 20 | , freq_operation(), freq_write() |
---|
| 21 | , foperation() |
---|
| 22 | , data() |
---|
[168] | 23 | { /* Ne rien faire de plus */ } |
---|
| 24 | |
---|
| 25 | CField::CField(const StdString & id) |
---|
| 26 | : CObjectTemplate<CField>(id), CFieldAttributes() |
---|
[187] | 27 | , refObject(), baseRefObject() |
---|
| 28 | , grid(), file() |
---|
| 29 | , freq_operation(), freq_write() |
---|
| 30 | , foperation() |
---|
| 31 | , data() |
---|
[168] | 32 | { /* Ne rien faire de plus */ } |
---|
| 33 | |
---|
| 34 | CField::~CField(void) |
---|
[152] | 35 | { |
---|
[182] | 36 | this->grid.reset() ; |
---|
| 37 | this->file.reset() ; |
---|
[187] | 38 | this->foperation.reset() ; |
---|
| 39 | this->data.reset() ; |
---|
[168] | 40 | } |
---|
[152] | 41 | |
---|
[168] | 42 | //---------------------------------------------------------------- |
---|
[152] | 43 | |
---|
[168] | 44 | void CField::setRelFile(const boost::shared_ptr<CFile> _file) |
---|
| 45 | { |
---|
| 46 | this->file = _file; |
---|
| 47 | } |
---|
[152] | 48 | |
---|
[168] | 49 | //---------------------------------------------------------------- |
---|
[152] | 50 | |
---|
[168] | 51 | StdString CField::GetName(void) { return (StdString("field")); } |
---|
| 52 | StdString CField::GetDefName(void){ return (CField::GetName()); } |
---|
| 53 | ENodeType CField::GetType(void) { return (eField); } |
---|
[152] | 54 | |
---|
[168] | 55 | //---------------------------------------------------------------- |
---|
[152] | 56 | |
---|
[168] | 57 | boost::shared_ptr<CGrid> CField::getRelGrid(void) const |
---|
| 58 | { |
---|
| 59 | return (this->grid); |
---|
| 60 | } |
---|
[152] | 61 | |
---|
[168] | 62 | //---------------------------------------------------------------- |
---|
[152] | 63 | |
---|
[168] | 64 | boost::shared_ptr<CFile> CField::getRelFile(void) const |
---|
| 65 | { |
---|
| 66 | return (this->file); |
---|
| 67 | } |
---|
[152] | 68 | |
---|
[168] | 69 | //---------------------------------------------------------------- |
---|
[152] | 70 | |
---|
[168] | 71 | boost::shared_ptr<CField> CField::getDirectFieldReference(void) const |
---|
| 72 | { |
---|
| 73 | if (this->field_ref.isEmpty()) |
---|
| 74 | return (this->getBaseFieldReference()); |
---|
[152] | 75 | |
---|
[168] | 76 | if (! CObjectFactory::HasObject<CField>(this->field_ref.getValue())) |
---|
| 77 | ERROR("CField::getDirectFieldReference(void)", |
---|
| 78 | << "[ ref_name = " << this->field_ref.getValue() << "]" |
---|
| 79 | << " invalid field name !"); |
---|
[152] | 80 | |
---|
[168] | 81 | return (CObjectFactory::GetObject<CField>(this->field_ref.getValue())); |
---|
| 82 | } |
---|
[152] | 83 | |
---|
[168] | 84 | //---------------------------------------------------------------- |
---|
[152] | 85 | |
---|
[168] | 86 | const boost::shared_ptr<CField> CField::getBaseFieldReference(void) const |
---|
| 87 | { |
---|
| 88 | return (baseRefObject); |
---|
| 89 | } |
---|
[152] | 90 | |
---|
[168] | 91 | //---------------------------------------------------------------- |
---|
[152] | 92 | |
---|
[168] | 93 | const std::vector<boost::shared_ptr<CField> > & CField::getAllReference(void) const |
---|
| 94 | { |
---|
| 95 | return (refObject); |
---|
| 96 | } |
---|
[152] | 97 | |
---|
[168] | 98 | //---------------------------------------------------------------- |
---|
| 99 | |
---|
| 100 | const StdString & CField::getBaseFieldId(void) const |
---|
| 101 | { |
---|
| 102 | return (this->getBaseFieldReference()->getId()); |
---|
| 103 | } |
---|
[188] | 104 | |
---|
| 105 | //---------------------------------------------------------------- |
---|
| 106 | |
---|
| 107 | const date::CDuration & CField::getFreqOperation(void) const |
---|
| 108 | { |
---|
| 109 | return (this->freq_operation); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | //---------------------------------------------------------------- |
---|
| 113 | const date::CDuration & CField::getFreqWrite(void) const |
---|
| 114 | { |
---|
| 115 | return (this->freq_write); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | //---------------------------------------------------------------- |
---|
| 119 | |
---|
| 120 | boost::shared_ptr<func::CFunctor> CField::getFieldOperation(void) const |
---|
| 121 | { |
---|
| 122 | return (this->foperation); |
---|
| 123 | } |
---|
[168] | 124 | |
---|
| 125 | //---------------------------------------------------------------- |
---|
| 126 | |
---|
| 127 | bool CField::hasDirectFieldReference(void) const |
---|
| 128 | { |
---|
| 129 | return (!this->field_ref.isEmpty()); |
---|
| 130 | } |
---|
[189] | 131 | |
---|
| 132 | //---------------------------------------------------------------- |
---|
| 133 | |
---|
| 134 | ARRAY(double, 1) CField::getData(void) const |
---|
| 135 | { |
---|
| 136 | return(this->data); |
---|
| 137 | } |
---|
[168] | 138 | |
---|
| 139 | //---------------------------------------------------------------- |
---|
| 140 | |
---|
| 141 | void CField::solveRefInheritance(void) |
---|
| 142 | { |
---|
| 143 | std::set<CField *> sset; |
---|
| 144 | boost::shared_ptr<CField> refer_sptr; |
---|
| 145 | CField * refer_ptr = this; |
---|
[187] | 146 | |
---|
[168] | 147 | this->baseRefObject = CObjectFactory::GetObject<CField>(this); |
---|
[187] | 148 | |
---|
[168] | 149 | while (refer_ptr->hasDirectFieldReference()) |
---|
[152] | 150 | { |
---|
[168] | 151 | refer_sptr = refer_ptr->getDirectFieldReference(); |
---|
| 152 | refer_ptr = refer_sptr.get(); |
---|
| 153 | |
---|
| 154 | if(sset.end() != sset.find(refer_ptr)) |
---|
[152] | 155 | { |
---|
[168] | 156 | DEBUG (<< "Dépendance circulaire stoppée pour l'objet de type CField sur " |
---|
| 157 | << "\"" + refer_ptr->getId() + "\" !"); |
---|
| 158 | break; |
---|
| 159 | } |
---|
[152] | 160 | |
---|
[168] | 161 | SuperClassAttribute::setAttributes(refer_ptr); |
---|
| 162 | sset.insert(refer_ptr); |
---|
| 163 | baseRefObject = refer_sptr; |
---|
| 164 | refObject.push_back(refer_sptr); |
---|
[152] | 165 | } |
---|
[168] | 166 | } |
---|
[152] | 167 | |
---|
[168] | 168 | //---------------------------------------------------------------- |
---|
[152] | 169 | |
---|
[168] | 170 | void CField::solveOperation(void) |
---|
| 171 | { |
---|
[187] | 172 | using namespace func; |
---|
| 173 | using namespace date; |
---|
| 174 | |
---|
| 175 | StdString id = this->getBaseFieldReference()->getId(); |
---|
| 176 | if (operation.isEmpty() || freq_op.isEmpty() || this->file->output_freq.isEmpty()) |
---|
| 177 | { |
---|
| 178 | ERROR("CField::solveOperation(void)", |
---|
| 179 | << "[ id = " << id << "]" |
---|
| 180 | << "Impossible de définir une opération pour le champ !"); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | if (CXIOSManager::GetStatus() == CXIOSManager::LOC_SERVER) |
---|
| 184 | { |
---|
[205] | 185 | this->freq_operation = |
---|
| 186 | CDuration::FromString(this->file->output_freq.getValue()); |
---|
| 187 | this->freq_write = |
---|
| 188 | CDuration::FromString(this->file->output_freq.getValue()); |
---|
| 189 | this->foperation = |
---|
| 190 | boost::shared_ptr<func::CFunctor>(new CInstant(this->data)); |
---|
[187] | 191 | } |
---|
| 192 | else |
---|
| 193 | { |
---|
| 194 | this->freq_operation = CDuration::FromString(freq_op.getValue()); |
---|
| 195 | this->freq_write = CDuration::FromString(this->file->output_freq.getValue()); |
---|
| 196 | |
---|
[205] | 197 | #define DECLARE_FUNCTOR(MType, mtype) \ |
---|
[188] | 198 | if (operation.getValue().compare(#mtype) == 0) \ |
---|
[205] | 199 | { \ |
---|
| 200 | boost::shared_ptr<func::CFunctor> \ |
---|
| 201 | foperation_(new C##MType(this->data)); \ |
---|
| 202 | this->foperation = foperation_; \ |
---|
| 203 | return; \ |
---|
| 204 | } |
---|
[187] | 205 | |
---|
| 206 | #include "functor_type.conf" |
---|
[188] | 207 | |
---|
| 208 | ERROR("CField::solveOperation(void)", |
---|
| 209 | << "[ operation = " << operation.getValue() << "]" |
---|
| 210 | << "L'opération n'est pas définie dans le code !"); |
---|
[187] | 211 | } |
---|
[168] | 212 | } |
---|
[181] | 213 | |
---|
| 214 | //---------------------------------------------------------------- |
---|
| 215 | |
---|
| 216 | void CField::fromBinary(StdIStream & is) |
---|
| 217 | { |
---|
| 218 | SuperClass::fromBinary(is); |
---|
| 219 | #define CLEAR_ATT(name_)\ |
---|
| 220 | SuperClassAttribute::operator[](#name_)->clear() |
---|
[168] | 221 | |
---|
[181] | 222 | CLEAR_ATT(domain_ref); |
---|
| 223 | CLEAR_ATT(axis_ref); |
---|
| 224 | #undef CLEAR_ATT |
---|
| 225 | |
---|
| 226 | } |
---|
| 227 | |
---|
[168] | 228 | //---------------------------------------------------------------- |
---|
| 229 | |
---|
| 230 | void CField::solveGridReference(void) |
---|
| 231 | { |
---|
| 232 | boost::shared_ptr<CDomain> domain; |
---|
| 233 | boost::shared_ptr<CAxis> axis; |
---|
| 234 | |
---|
| 235 | if (!domain_ref.isEmpty()) |
---|
[152] | 236 | { |
---|
[168] | 237 | if (CObjectFactory::HasObject<CDomain>(domain_ref.getValue())) |
---|
| 238 | domain = CObjectFactory::GetObject<CDomain>(domain_ref.getValue()) ; |
---|
| 239 | else |
---|
| 240 | ERROR("CField::solveGridReference(void)", |
---|
| 241 | << "Référence au domaine nommé \'" |
---|
| 242 | << domain_ref.getValue() << "\' incorrecte") ; |
---|
[152] | 243 | } |
---|
| 244 | |
---|
[168] | 245 | if (!axis_ref.isEmpty()) |
---|
| 246 | { |
---|
| 247 | if (CObjectFactory::HasObject<CAxis>(axis_ref.getValue())) |
---|
| 248 | axis = CObjectFactory::GetObject<CAxis>(axis_ref.getValue()) ; |
---|
| 249 | else |
---|
| 250 | ERROR("CField::solveGridReference(void)", |
---|
| 251 | << "Référence à l'axe nommé \'" |
---|
| 252 | << axis_ref.getValue() <<"\' incorrecte") ; |
---|
| 253 | } |
---|
[152] | 254 | |
---|
[168] | 255 | if (!grid_ref.isEmpty()) |
---|
[152] | 256 | { |
---|
[168] | 257 | if (CObjectFactory::HasObject<CGrid>(grid_ref.getValue())) |
---|
| 258 | this->grid = CObjectFactory::GetObject<CGrid>(grid_ref.getValue()) ; |
---|
| 259 | else |
---|
| 260 | ERROR("CField::solveGridReference(void)", |
---|
| 261 | << "Référence à la grille nommée \'" |
---|
| 262 | << grid_ref.getValue() << "\' incorrecte"); |
---|
[152] | 263 | if (!domain_ref.isEmpty()) |
---|
[168] | 264 | DEBUG(<< "Définition conjointe de la grille " |
---|
| 265 | << "et du domaine, la grille prévaut..." ); |
---|
[152] | 266 | if (!axis_ref.isEmpty()) |
---|
[168] | 267 | DEBUG(<< "Définition conjointe de la grille " |
---|
| 268 | << "et de l'axe vertical, la grille prévaut...") ; |
---|
| 269 | } |
---|
| 270 | else |
---|
| 271 | { |
---|
| 272 | if (!domain_ref.isEmpty()) |
---|
[152] | 273 | { |
---|
| 274 | if (!axis_ref.isEmpty()) |
---|
| 275 | { |
---|
[168] | 276 | this->grid = CGrid::CreateGrid(domain, axis) ; |
---|
| 277 | this->grid_ref.setValue(this->grid->getId()); |
---|
[152] | 278 | } |
---|
| 279 | else |
---|
| 280 | { |
---|
[168] | 281 | this->grid = CGrid::CreateGrid(domain) ; |
---|
| 282 | this->grid_ref.setValue(this->grid->getId()); |
---|
[152] | 283 | } |
---|
| 284 | } |
---|
[168] | 285 | else |
---|
| 286 | { |
---|
| 287 | ERROR("CField::solveGridReference(void)", |
---|
| 288 | << "Le domaine horizontal pour le champ X n'est pas défini"); |
---|
| 289 | } |
---|
[152] | 290 | } |
---|
[168] | 291 | grid->solveReference() ; |
---|
| 292 | } |
---|
| 293 | |
---|
[152] | 294 | } // namespace tree |
---|
| 295 | |
---|
| 296 | ///------------------------------------------------------------------- |
---|
| 297 | |
---|
| 298 | template <> |
---|
| 299 | void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void) |
---|
| 300 | { |
---|
| 301 | if (this->group_ref.isEmpty()) return; |
---|
| 302 | StdString gref = this->group_ref.getValue(); |
---|
| 303 | |
---|
| 304 | if (!CObjectFactory::HasObject<CFieldGroup>(gref)) |
---|
| 305 | ERROR("CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void)", |
---|
| 306 | << "[ gref = " << gref << "]" |
---|
| 307 | << " invalid group name !"); |
---|
| 308 | |
---|
| 309 | boost::shared_ptr<CFieldGroup> group |
---|
| 310 | = CObjectFactory::GetObject<CFieldGroup>(gref); |
---|
| 311 | boost::shared_ptr<CFieldGroup> owner |
---|
| 312 | = CObjectFactory::GetObject<CFieldGroup> |
---|
| 313 | (boost::polymorphic_downcast<CFieldGroup*>(this)); |
---|
| 314 | |
---|
| 315 | std::vector<boost::shared_ptr<CField> > allChildren = group->getAllChildren(); |
---|
| 316 | std::vector<boost::shared_ptr<CField> >::iterator |
---|
| 317 | it = allChildren.begin(), end = allChildren.end(); |
---|
| 318 | |
---|
| 319 | for (; it != end; it++) |
---|
| 320 | { |
---|
| 321 | boost::shared_ptr<CField> child = *it; |
---|
| 322 | if (child->hasId()) |
---|
| 323 | CGroupFactory::CreateChild(owner)->field_ref.setValue(child->getId()); |
---|
| 324 | } |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | ///------------------------------------------------------------------- |
---|
| 328 | |
---|
| 329 | } // namespace xmlioserver |
---|