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

Last change on this file since 206 was 206, checked in by hozdoba, 13 years ago
File size: 12.0 KB
RevLine 
[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"
[206]8#include "calendar_util.hpp"
[187]9#include "xios_manager.hpp"
10
[168]11namespace xmlioserver{
12namespace 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()
[206]21      , last_Write(), last_operation()
[187]22      , foperation()
23      , data()
[168]24   { /* Ne rien faire de plus */ }
25
26   CField::CField(const StdString & id)
27      : CObjectTemplate<CField>(id), CFieldAttributes()
[187]28      , refObject(), baseRefObject()
29      , grid(), file()
30      , freq_operation(), freq_write()
[206]31      , last_Write(), last_operation()
[187]32      , foperation()
33      , data()
[168]34   { /* Ne rien faire de plus */ }
35
36   CField::~CField(void)
[152]37   {
[182]38      this->grid.reset() ;
39      this->file.reset() ;
[187]40      this->foperation.reset() ;
41      this->data.reset() ;
[168]42   }
[152]43
[168]44   //----------------------------------------------------------------
[152]45
[206]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
[168]67   void CField::setRelFile(const boost::shared_ptr<CFile> _file)
68   { 
69      this->file = _file; 
70   }
[152]71
[168]72   //----------------------------------------------------------------
[152]73
[168]74   StdString CField::GetName(void)   { return (StdString("field")); }
75   StdString CField::GetDefName(void){ return (CField::GetName()); }
76   ENodeType CField::GetType(void)   { return (eField); }
[152]77
[168]78   //----------------------------------------------------------------
[152]79
[168]80   boost::shared_ptr<CGrid> CField::getRelGrid(void) const
81   { 
82      return (this->grid); 
83   }
[152]84
[168]85   //----------------------------------------------------------------
[152]86
[168]87   boost::shared_ptr<CFile> CField::getRelFile(void) const
88   { 
89      return (this->file);
90   }
[152]91
[168]92   //----------------------------------------------------------------
[152]93
[168]94   boost::shared_ptr<CField> CField::getDirectFieldReference(void) const
95   {
96      if (this->field_ref.isEmpty())
97         return (this->getBaseFieldReference());
[152]98
[168]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 !");
[152]103
[168]104      return (CObjectFactory::GetObject<CField>(this->field_ref.getValue()));
105   }
[152]106
[168]107   //----------------------------------------------------------------
[152]108
[168]109   const boost::shared_ptr<CField> CField::getBaseFieldReference(void) const
110   { 
111      return (baseRefObject); 
112   }
[152]113
[168]114   //----------------------------------------------------------------
[152]115
[168]116   const std::vector<boost::shared_ptr<CField> > & CField::getAllReference(void) const 
117   { 
118      return (refObject);
119   }
[152]120
[168]121   //----------------------------------------------------------------
122
123   const StdString & CField::getBaseFieldId(void) const
124   { 
125      return (this->getBaseFieldReference()->getId());
126   }
[188]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   }
[168]147
148   //----------------------------------------------------------------
149
150   bool CField::hasDirectFieldReference(void) const
151   { 
152      return (!this->field_ref.isEmpty()); 
153   }
[189]154   
155   //----------------------------------------------------------------
156   
[206]157   ARRAY(double, 1) CField::getData(void) const
[189]158   {
159      return(this->data);
160   }
[168]161
162   //----------------------------------------------------------------
163
[206]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
[168]178   void CField::solveRefInheritance(void)
179   {
180      std::set<CField *> sset;
181      boost::shared_ptr<CField> refer_sptr;
182      CField * refer_ptr = this;
[187]183     
[168]184      this->baseRefObject = CObjectFactory::GetObject<CField>(this);
[187]185     
[168]186      while (refer_ptr->hasDirectFieldReference())
[152]187      {
[168]188         refer_sptr = refer_ptr->getDirectFieldReference();
189         refer_ptr  = refer_sptr.get();
190
191         if(sset.end() != sset.find(refer_ptr))
[152]192         {
[168]193            DEBUG (<< "Dépendance circulaire stoppée pour l'objet de type CField sur "
194                   << "\"" + refer_ptr->getId() + "\" !");
195            break;
196         }
[152]197
[168]198         SuperClassAttribute::setAttributes(refer_ptr);
199         sset.insert(refer_ptr);
200         baseRefObject = refer_sptr;
201         refObject.push_back(refer_sptr);
[152]202      }
[168]203   }
[152]204
[168]205   //----------------------------------------------------------------
[152]206
[168]207   void  CField::solveOperation(void)
208   {
[187]209      using namespace func;
210      using namespace date;
211       
[206]212      StdString id = this->getBaseFieldReference()->getId();
213      boost::shared_ptr<CContext> _context =
214         CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId());
215
[187]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      {
[205]225         this->freq_operation =
226             CDuration::FromString(this->file->output_freq.getValue());
227         this->freq_write     =
228             CDuration::FromString(this->file->output_freq.getValue());
[206]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()));
[205]233         this->foperation     =
234             boost::shared_ptr<func::CFunctor>(new CInstant(this->data));
[187]235      }
236      else
237      {
238         this->freq_operation = CDuration::FromString(freq_op.getValue());
239         this->freq_write     = CDuration::FromString(this->file->output_freq.getValue());
[206]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()));
[187]244         
[205]245#define DECLARE_FUNCTOR(MType, mtype)              \
[188]246   if  (operation.getValue().compare(#mtype) == 0) \
[205]247   {                                               \
248      boost::shared_ptr<func::CFunctor>            \
249            foperation_(new C##MType(this->data)); \
250      this->foperation = foperation_;              \
251      return;                                      \
252   }
[187]253   
254#include "functor_type.conf"
[188]255         
256         ERROR("CField::solveOperation(void)",
257               << "[ operation = " << operation.getValue() << "]"
258               << "L'opération n'est pas définie dans le code !");
[187]259      }
[168]260   }
[181]261   
262   //----------------------------------------------------------------
263   
264   void CField::fromBinary(StdIStream & is)
265   {
266      SuperClass::fromBinary(is);
267#define CLEAR_ATT(name_)\
268      SuperClassAttribute::operator[](#name_)->clear()
[168]269
[181]270         CLEAR_ATT(domain_ref);
271         CLEAR_ATT(axis_ref);
272#undef CLEAR_ATT
273
274   }
275
[168]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())
[152]284      {
[168]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") ;
[152]291      }
292
[168]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      }
[152]302
[168]303      if (!grid_ref.isEmpty())
[152]304      {
[168]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");
[152]311         if (!domain_ref.isEmpty())
[168]312            DEBUG(<< "Définition conjointe de la grille "
313                  << "et du domaine, la grille prévaut..." );
[152]314         if (!axis_ref.isEmpty())
[168]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())
[152]321         {
322            if (!axis_ref.isEmpty())
323            {
[168]324               this->grid = CGrid::CreateGrid(domain, axis) ;
325               this->grid_ref.setValue(this->grid->getId());
[152]326            }
327            else
328            {
[168]329               this->grid = CGrid::CreateGrid(domain) ;
330               this->grid_ref.setValue(this->grid->getId());
[152]331            }
332         }
[168]333         else
334         {
335            ERROR("CField::solveGridReference(void)",
336                  << "Le domaine horizontal pour le champ X n'est pas défini");
337         }
[152]338      }
[168]339      grid->solveReference() ;
340   }
341
[152]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.