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

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