source: XMLIO_V2/dev/dev_rv/src/xmlio/node/field.cpp @ 205

Last change on this file since 205 was 205, checked in by hozdoba, 13 years ago
File size: 10.2 KB
Line 
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#include "xios_manager.hpp"
10
11namespace xmlioserver{
12namespace tree {
13   
14   /// ////////////////////// Définitions ////////////////////// ///
15
16   CField::CField(void)
17      : CObjectTemplate<CField>(), CFieldAttributes()
18      , refObject(), baseRefObject()
19      , grid(), file()
20      , freq_operation(), freq_write()
21      , foperation()
22      , data()
23   { /* Ne rien faire de plus */ }
24
25   CField::CField(const StdString & id)
26      : CObjectTemplate<CField>(id), CFieldAttributes()
27      , refObject(), baseRefObject()
28      , grid(), file()
29      , freq_operation(), freq_write()
30      , foperation()
31      , data()
32   { /* Ne rien faire de plus */ }
33
34   CField::~CField(void)
35   {
36      this->grid.reset() ;
37      this->file.reset() ;
38      this->foperation.reset() ;
39      this->data.reset() ;
40   }
41
42   //----------------------------------------------------------------
43
44   void CField::setRelFile(const boost::shared_ptr<CFile> _file)
45   { 
46      this->file = _file; 
47   }
48
49   //----------------------------------------------------------------
50
51   StdString CField::GetName(void)   { return (StdString("field")); }
52   StdString CField::GetDefName(void){ return (CField::GetName()); }
53   ENodeType CField::GetType(void)   { return (eField); }
54
55   //----------------------------------------------------------------
56
57   boost::shared_ptr<CGrid> CField::getRelGrid(void) const
58   { 
59      return (this->grid); 
60   }
61
62   //----------------------------------------------------------------
63
64   boost::shared_ptr<CFile> CField::getRelFile(void) const
65   { 
66      return (this->file);
67   }
68
69   //----------------------------------------------------------------
70
71   boost::shared_ptr<CField> CField::getDirectFieldReference(void) const
72   {
73      if (this->field_ref.isEmpty())
74         return (this->getBaseFieldReference());
75
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 !");
80
81      return (CObjectFactory::GetObject<CField>(this->field_ref.getValue()));
82   }
83
84   //----------------------------------------------------------------
85
86   const boost::shared_ptr<CField> CField::getBaseFieldReference(void) const
87   { 
88      return (baseRefObject); 
89   }
90
91   //----------------------------------------------------------------
92
93   const std::vector<boost::shared_ptr<CField> > & CField::getAllReference(void) const 
94   { 
95      return (refObject);
96   }
97
98   //----------------------------------------------------------------
99
100   const StdString & CField::getBaseFieldId(void) const
101   { 
102      return (this->getBaseFieldReference()->getId());
103   }
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   }
124
125   //----------------------------------------------------------------
126
127   bool CField::hasDirectFieldReference(void) const
128   { 
129      return (!this->field_ref.isEmpty()); 
130   }
131   
132   //----------------------------------------------------------------
133   
134   ARRAY(double, 1)  CField::getData(void) const
135   {
136      return(this->data);
137   }
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;
146     
147      this->baseRefObject = CObjectFactory::GetObject<CField>(this);
148     
149      while (refer_ptr->hasDirectFieldReference())
150      {
151         refer_sptr = refer_ptr->getDirectFieldReference();
152         refer_ptr  = refer_sptr.get();
153
154         if(sset.end() != sset.find(refer_ptr))
155         {
156            DEBUG (<< "Dépendance circulaire stoppée pour l'objet de type CField sur "
157                   << "\"" + refer_ptr->getId() + "\" !");
158            break;
159         }
160
161         SuperClassAttribute::setAttributes(refer_ptr);
162         sset.insert(refer_ptr);
163         baseRefObject = refer_sptr;
164         refObject.push_back(refer_sptr);
165      }
166   }
167
168   //----------------------------------------------------------------
169
170   void  CField::solveOperation(void)
171   {
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      {
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));
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         
197#define DECLARE_FUNCTOR(MType, mtype)              \
198   if  (operation.getValue().compare(#mtype) == 0) \
199   {                                               \
200      boost::shared_ptr<func::CFunctor>            \
201            foperation_(new C##MType(this->data)); \
202      this->foperation = foperation_;              \
203      return;                                      \
204   }
205   
206#include "functor_type.conf"
207         
208         ERROR("CField::solveOperation(void)",
209               << "[ operation = " << operation.getValue() << "]"
210               << "L'opération n'est pas définie dans le code !");
211      }
212   }
213   
214   //----------------------------------------------------------------
215   
216   void CField::fromBinary(StdIStream & is)
217   {
218      SuperClass::fromBinary(is);
219#define CLEAR_ATT(name_)\
220      SuperClassAttribute::operator[](#name_)->clear()
221
222         CLEAR_ATT(domain_ref);
223         CLEAR_ATT(axis_ref);
224#undef CLEAR_ATT
225
226   }
227
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())
236      {
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") ;
243      }
244
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      }
254
255      if (!grid_ref.isEmpty())
256      {
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");
263         if (!domain_ref.isEmpty())
264            DEBUG(<< "Définition conjointe de la grille "
265                  << "et du domaine, la grille prévaut..." );
266         if (!axis_ref.isEmpty())
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())
273         {
274            if (!axis_ref.isEmpty())
275            {
276               this->grid = CGrid::CreateGrid(domain, axis) ;
277               this->grid_ref.setValue(this->grid->getId());
278            }
279            else
280            {
281               this->grid = CGrid::CreateGrid(domain) ;
282               this->grid_ref.setValue(this->grid->getId());
283            }
284         }
285         else
286         {
287            ERROR("CField::solveGridReference(void)",
288                  << "Le domaine horizontal pour le champ X n'est pas défini");
289         }
290      }
291      grid->solveReference() ;
292   }
293
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
Note: See TracBrowser for help on using the repository browser.