source: XMLIO_V2/dev/common/src/xmlio/node/field.cpp @ 219

Last change on this file since 219 was 219, checked in by hozdoba, 13 years ago

Préparation nouvelle arborescence

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