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

Last change on this file since 187 was 187, checked in by hozdoba, 13 years ago
File size: 9.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
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   bool CField::hasDirectFieldReference(void) const
108   { 
109      return (!this->field_ref.isEmpty()); 
110   }
111
112   //----------------------------------------------------------------
113
114   void CField::solveRefInheritance(void)
115   {
116      std::set<CField *> sset;
117      boost::shared_ptr<CField> refer_sptr;
118      CField * refer_ptr = this;
119     
120      this->baseRefObject = CObjectFactory::GetObject<CField>(this);
121     
122      while (refer_ptr->hasDirectFieldReference())
123      {
124         refer_sptr = refer_ptr->getDirectFieldReference();
125         refer_ptr  = refer_sptr.get();
126
127         if(sset.end() != sset.find(refer_ptr))
128         {
129            DEBUG (<< "Dépendance circulaire stoppée pour l'objet de type CField sur "
130                   << "\"" + refer_ptr->getId() + "\" !");
131            break;
132         }
133
134         SuperClassAttribute::setAttributes(refer_ptr);
135         sset.insert(refer_ptr);
136         baseRefObject = refer_sptr;
137         refObject.push_back(refer_sptr);
138      }
139   }
140
141   //----------------------------------------------------------------
142
143   void  CField::solveOperation(void)
144   {
145      using namespace func;
146      using namespace date;
147       
148      StdString id = this->getBaseFieldReference()->getId();     
149      if (operation.isEmpty() || freq_op.isEmpty() || this->file->output_freq.isEmpty())
150      {
151         ERROR("CField::solveOperation(void)",
152               << "[ id = " << id << "]"
153               << "Impossible de définir une opération pour le champ !");
154      }
155
156      if (CXIOSManager::GetStatus() == CXIOSManager::LOC_SERVER)
157      {
158         this->freq_operation = CDuration::FromString(this->file->output_freq.getValue());
159         this->freq_write     = CDuration::FromString(this->file->output_freq.getValue());
160         //this->foperation = boost::shared_ptr<func::CFunctor>(new CInstant());
161      }
162      else
163      {
164         this->freq_operation = CDuration::FromString(freq_op.getValue());
165         this->freq_write     = CDuration::FromString(this->file->output_freq.getValue());
166         
167#define DECLARE_FUNCTOR(MType, mtype) \
168   if  (operation.getValue().compare(#mtype) == 0){}
169      //this->foperation = boost::shared_ptr<func::CFunctor>(new C##MType());
170   
171#include "functor_type.conf"
172      }
173   }
174   
175   //----------------------------------------------------------------
176   
177   void CField::fromBinary(StdIStream & is)
178   {
179      SuperClass::fromBinary(is);
180#define CLEAR_ATT(name_)\
181      SuperClassAttribute::operator[](#name_)->clear()
182
183         CLEAR_ATT(domain_ref);
184         CLEAR_ATT(axis_ref);
185#undef CLEAR_ATT
186
187   }
188
189   //----------------------------------------------------------------
190
191   void CField::solveGridReference(void)
192   {
193      boost::shared_ptr<CDomain> domain;
194      boost::shared_ptr<CAxis> axis;
195
196      if (!domain_ref.isEmpty())
197      {
198         if (CObjectFactory::HasObject<CDomain>(domain_ref.getValue()))
199            domain = CObjectFactory::GetObject<CDomain>(domain_ref.getValue()) ;
200         else
201            ERROR("CField::solveGridReference(void)",
202                  << "Référence au domaine nommé \'"
203                  << domain_ref.getValue() << "\' incorrecte") ;
204      }
205
206      if (!axis_ref.isEmpty())
207      {
208         if (CObjectFactory::HasObject<CAxis>(axis_ref.getValue()))
209            axis = CObjectFactory::GetObject<CAxis>(axis_ref.getValue()) ;
210         else
211            ERROR("CField::solveGridReference(void)",
212                  << "Référence à l'axe nommé \'"
213                  << axis_ref.getValue() <<"\' incorrecte") ;
214      }
215
216      if (!grid_ref.isEmpty())
217      {
218         if (CObjectFactory::HasObject<CGrid>(grid_ref.getValue()))
219            this->grid = CObjectFactory::GetObject<CGrid>(grid_ref.getValue()) ;
220         else
221            ERROR("CField::solveGridReference(void)",
222                  << "Référence à la grille nommée \'"
223                  << grid_ref.getValue() << "\' incorrecte");
224         if (!domain_ref.isEmpty())
225            DEBUG(<< "Définition conjointe de la grille "
226                  << "et du domaine, la grille prévaut..." );
227         if (!axis_ref.isEmpty())
228            DEBUG(<< "Définition conjointe de la grille "
229                  << "et de l'axe vertical, la grille prévaut...") ;
230      }
231      else
232      {
233         if (!domain_ref.isEmpty())
234         {
235            if (!axis_ref.isEmpty())
236            {
237               this->grid = CGrid::CreateGrid(domain, axis) ;
238               this->grid_ref.setValue(this->grid->getId());
239            }
240            else
241            {
242               this->grid = CGrid::CreateGrid(domain) ;
243               this->grid_ref.setValue(this->grid->getId());
244            }
245         }
246         else
247         {
248            ERROR("CField::solveGridReference(void)",
249                  << "Le domaine horizontal pour le champ X n'est pas défini");
250         }
251      }
252      grid->solveReference() ;
253   }
254
255   } // namespace tree
256
257   ///-------------------------------------------------------------------
258
259   template <>
260      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void)
261   {
262      if (this->group_ref.isEmpty()) return;
263      StdString gref = this->group_ref.getValue();
264
265      if (!CObjectFactory::HasObject<CFieldGroup>(gref))
266         ERROR("CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void)",
267               << "[ gref = " << gref << "]"
268               << " invalid group name !");
269
270      boost::shared_ptr<CFieldGroup> group
271               = CObjectFactory::GetObject<CFieldGroup>(gref);
272      boost::shared_ptr<CFieldGroup> owner
273               = CObjectFactory::GetObject<CFieldGroup>
274                  (boost::polymorphic_downcast<CFieldGroup*>(this));
275
276      std::vector<boost::shared_ptr<CField> > allChildren  = group->getAllChildren();
277      std::vector<boost::shared_ptr<CField> >::iterator
278         it = allChildren.begin(), end = allChildren.end();
279     
280      for (; it != end; it++)
281      {
282         boost::shared_ptr<CField> child = *it;
283         if (child->hasId())
284            CGroupFactory::CreateChild(owner)->field_ref.setValue(child->getId());
285      }
286   }
287
288   ///-------------------------------------------------------------------
289
290} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.