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

Last change on this file since 200 was 189, checked in by hozdoba, 13 years ago
File size: 9.9 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 = CDuration::FromString(this->file->output_freq.getValue());
186         this->freq_write     = CDuration::FromString(this->file->output_freq.getValue());
187         //this->foperation = boost::shared_ptr<func::CFunctor>(new CInstant());
188      }
189      else
190      {
191         this->freq_operation = CDuration::FromString(freq_op.getValue());
192         this->freq_write     = CDuration::FromString(this->file->output_freq.getValue());
193         
194#define DECLARE_FUNCTOR(MType, mtype) \
195   if  (operation.getValue().compare(#mtype) == 0) \
196   { return; }
197      //this->foperation = boost::shared_ptr<func::CFunctor>(new C##MType());
198   
199#include "functor_type.conf"
200         
201         ERROR("CField::solveOperation(void)",
202               << "[ operation = " << operation.getValue() << "]"
203               << "L'opération n'est pas définie dans le code !");
204      }
205   }
206   
207   //----------------------------------------------------------------
208   
209   void CField::fromBinary(StdIStream & is)
210   {
211      SuperClass::fromBinary(is);
212#define CLEAR_ATT(name_)\
213      SuperClassAttribute::operator[](#name_)->clear()
214
215         CLEAR_ATT(domain_ref);
216         CLEAR_ATT(axis_ref);
217#undef CLEAR_ATT
218
219   }
220
221   //----------------------------------------------------------------
222
223   void CField::solveGridReference(void)
224   {
225      boost::shared_ptr<CDomain> domain;
226      boost::shared_ptr<CAxis> axis;
227
228      if (!domain_ref.isEmpty())
229      {
230         if (CObjectFactory::HasObject<CDomain>(domain_ref.getValue()))
231            domain = CObjectFactory::GetObject<CDomain>(domain_ref.getValue()) ;
232         else
233            ERROR("CField::solveGridReference(void)",
234                  << "Référence au domaine nommé \'"
235                  << domain_ref.getValue() << "\' incorrecte") ;
236      }
237
238      if (!axis_ref.isEmpty())
239      {
240         if (CObjectFactory::HasObject<CAxis>(axis_ref.getValue()))
241            axis = CObjectFactory::GetObject<CAxis>(axis_ref.getValue()) ;
242         else
243            ERROR("CField::solveGridReference(void)",
244                  << "Référence à l'axe nommé \'"
245                  << axis_ref.getValue() <<"\' incorrecte") ;
246      }
247
248      if (!grid_ref.isEmpty())
249      {
250         if (CObjectFactory::HasObject<CGrid>(grid_ref.getValue()))
251            this->grid = CObjectFactory::GetObject<CGrid>(grid_ref.getValue()) ;
252         else
253            ERROR("CField::solveGridReference(void)",
254                  << "Référence à la grille nommée \'"
255                  << grid_ref.getValue() << "\' incorrecte");
256         if (!domain_ref.isEmpty())
257            DEBUG(<< "Définition conjointe de la grille "
258                  << "et du domaine, la grille prévaut..." );
259         if (!axis_ref.isEmpty())
260            DEBUG(<< "Définition conjointe de la grille "
261                  << "et de l'axe vertical, la grille prévaut...") ;
262      }
263      else
264      {
265         if (!domain_ref.isEmpty())
266         {
267            if (!axis_ref.isEmpty())
268            {
269               this->grid = CGrid::CreateGrid(domain, axis) ;
270               this->grid_ref.setValue(this->grid->getId());
271            }
272            else
273            {
274               this->grid = CGrid::CreateGrid(domain) ;
275               this->grid_ref.setValue(this->grid->getId());
276            }
277         }
278         else
279         {
280            ERROR("CField::solveGridReference(void)",
281                  << "Le domaine horizontal pour le champ X n'est pas défini");
282         }
283      }
284      grid->solveReference() ;
285   }
286
287   } // namespace tree
288
289   ///-------------------------------------------------------------------
290
291   template <>
292      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void)
293   {
294      if (this->group_ref.isEmpty()) return;
295      StdString gref = this->group_ref.getValue();
296
297      if (!CObjectFactory::HasObject<CFieldGroup>(gref))
298         ERROR("CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void)",
299               << "[ gref = " << gref << "]"
300               << " invalid group name !");
301
302      boost::shared_ptr<CFieldGroup> group
303               = CObjectFactory::GetObject<CFieldGroup>(gref);
304      boost::shared_ptr<CFieldGroup> owner
305               = CObjectFactory::GetObject<CFieldGroup>
306                  (boost::polymorphic_downcast<CFieldGroup*>(this));
307
308      std::vector<boost::shared_ptr<CField> > allChildren  = group->getAllChildren();
309      std::vector<boost::shared_ptr<CField> >::iterator
310         it = allChildren.begin(), end = allChildren.end();
311     
312      for (; it != end; it++)
313      {
314         boost::shared_ptr<CField> child = *it;
315         if (child->hasId())
316            CGroupFactory::CreateChild(owner)->field_ref.setValue(child->getId());
317      }
318   }
319
320   ///-------------------------------------------------------------------
321
322} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.