source: XMLIO_V2/dev/dev_rv/src/xmlio/node/field.hpp @ 265

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

Corrections après tests sur titane

File size: 6.5 KB
Line 
1#ifndef __XMLIO_CField__
2#define __XMLIO_CField__
3
4/// xmlioserver headers ///
5#include "xmlioserver_spl.hpp"
6#include "group_factory.hpp"
7#include "functor.hpp"
8#include "functor_type.hpp"
9#include "duration.hpp"
10#include "date.hpp"
11#include "declare_group.hpp"
12#include "calendar_util.hpp"
13
14namespace xmlioserver {
15namespace tree {
16   
17   /// ////////////////////// Déclarations ////////////////////// ///
18
19   class CFieldGroup;
20   class CFieldAttributes;
21   class CField;
22
23   class CFile;
24   class CGrid;
25
26   ///--------------------------------------------------------------
27
28   // Declare/Define CFieldAttribute
29   BEGIN_DECLARE_ATTRIBUTE_MAP(CField)
30#  include "field_attribute.conf"
31   END_DECLARE_ATTRIBUTE_MAP(CField)
32
33   ///--------------------------------------------------------------
34   class CField
35      : public CObjectTemplate<CField>
36      , public CFieldAttributes
37   {
38         /// friend ///
39         friend class CFile;
40
41         /// typedef ///
42         typedef CObjectTemplate<CField>   SuperClass;
43         typedef CFieldAttributes SuperClassAttribute;
44
45      public :
46
47         typedef CFieldAttributes RelAttributes;
48         typedef CFieldGroup      RelGroup;
49
50         /// Constructeurs ///
51         CField(void);
52         explicit CField(const StdString & id);
53         CField(const CField & field);       // Not implemented yet.
54         CField(const CField * const field); // Not implemented yet.
55
56         /// Accesseurs ///
57               boost::shared_ptr<CField> getDirectFieldReference(void) const;
58         const boost::shared_ptr<CField> getBaseFieldReference(void)   const;
59         const std::vector<boost::shared_ptr<CField> > & getAllReference(void) const;
60
61         boost::shared_ptr<CGrid> getRelGrid(void) const ;
62         boost::shared_ptr<CFile> getRelFile(void) const ;
63
64      public :
65
66         StdSize getNStep(void) const;
67
68         const date::CDuration & getFreqOperation(void) const;
69         const date::CDuration & getFreqWrite(void) const;
70
71         boost::shared_ptr<date::CDate> getLastWriteDate(void) const;
72         boost::shared_ptr<date::CDate> getLastOperationDate(void) const;
73
74         boost::shared_ptr<func::CFunctor> getFieldOperation(void) const;
75         
76         ARRAY(double, 1) getData(void) const;
77
78         const StdString & getBaseFieldId(void) const;
79
80         /// Mutateur ///
81         void setRelFile(const boost::shared_ptr<CFile> _file);
82         void incrementNStep(void);
83
84         template <StdSize N>
85            inline bool updateData
86               (const date::CDate & currDate, const date::CDuration & timestep, const ARRAY(double, N) data);
87
88         bool updateDataServer
89               (const date::CDate & currDate, const std::deque<ARRAY(double, 1)> storedClient);
90
91      public :
92
93         /// Test ///
94         bool hasDirectFieldReference(void) const;
95
96         /// Traitements ///
97         void solveRefInheritance(void);
98         void solveGridReference(void);
99         void solveOperation(void);
100
101         virtual void fromBinary(StdIStream & is);
102
103         /// Destructeur ///
104         virtual ~CField(void);
105
106         /// Accesseurs statiques ///
107         static StdString GetName(void);
108         static StdString GetDefName(void);
109         
110         static ENodeType GetType(void);
111
112      private :
113
114         /// Propriétés privées ///
115         
116         std::vector<boost::shared_ptr<CField> > refObject;
117         boost::shared_ptr<CField> baseRefObject;
118         boost::shared_ptr<CGrid>  grid ;
119         boost::shared_ptr<CFile>  file;
120
121         date::CDuration freq_operation, freq_write;
122
123         StdSize nstep;
124         boost::shared_ptr<date::CDate>    last_Write, last_operation;
125         boost::shared_ptr<func::CFunctor> foperation;
126         
127         ARRAY(double, 1) data;
128
129   }; // class CField
130
131   ///--------------------------------------------------------------
132
133   // Declare/Define CFieldGroup and CFieldDefinition
134   DECLARE_GROUP(CField);
135
136   } // namespace tree
137
138   ///-----------------------------------------------------------------
139
140   template <>
141      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
142
143   ///-----------------------------------------------------------------
144} // namespace xmlioserver
145
146#include "grid.hpp"
147
148namespace xmlioserver {
149namespace tree {
150
151   template <StdSize N>
152      bool CField::updateData(const date::CDate & currDate, const date::CDuration & timestep, const ARRAY(double, N) _data)
153   {       
154      const date::CDate opeDate      = *last_operation + freq_operation;
155      const date::CDate writeDate    = *last_Write     + freq_write;       
156
157//      std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
158//      std::cout << "Champ : "     << this->getBaseFieldId() << std::endl;
159//      std::cout << "CurrDate : "  << currDate  << std::endl;
160//      std::cout << "opeDate : "   << opeDate   << " = " << *last_operation << " + " << freq_operation << std::endl;
161//      std::cout       << "writeDate : " << writeDate << " = " << *last_Write     << " + " << freq_write     << std::endl;
162//      std::cout << "(opeDate <= currDate)   = " << std::boolalpha << (opeDate <= currDate)   << std::endl;
163//      std::cout       << "(writeDate <= currDate) = " << std::boolalpha << (writeDate <= currDate) << std::endl;   
164   
165       //std::cout << ">> " << currDate <<  " : Envoi de données " << this->getBaseFieldId() << std::endl;
166      if (opeDate <= currDate)
167      {
168         //std::cout << "> " << currDate << ": Operation du champs" << this->getBaseFieldId() << std::endl;
169         
170         if (this->data->num_elements() != this->grid->storeIndex[0]->num_elements())
171         {
172            this->data->resize(boost::extents[this->grid->storeIndex[0] ->num_elements()]);
173         }
174           
175         ARRAY_CREATE(input, double, 1, [this->data->num_elements()]);
176         this->grid->inputField(_data, input);         
177         (*this->foperation)(input);
178         
179         *last_operation = currDate;
180//         std::cout << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl;
181      }
182     
183      if (writeDate < (currDate + freq_operation))
184      {
185         this->foperation->final();
186         this->incrementNStep();
187         *last_Write = writeDate;
188//         std::cout << "(*last_Write = currDate) : " << *last_Write << " = " << currDate       << std::endl;
189         return (true);       
190      }
191//      std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
192      return (false);
193   };
194
195} // namespace tree
196} // namespace xmlioserver
197
198#endif // __XMLIO_CField__
Note: See TracBrowser for help on using the repository browser.