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 | //#include "context.hpp" |
---|
14 | |
---|
15 | |
---|
16 | namespace xmlioserver { |
---|
17 | namespace tree { |
---|
18 | |
---|
19 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
20 | |
---|
21 | class CFieldGroup; |
---|
22 | class CFieldAttributes; |
---|
23 | class CField; |
---|
24 | |
---|
25 | class CFile; |
---|
26 | class CGrid; |
---|
27 | class CContext ; |
---|
28 | ///-------------------------------------------------------------- |
---|
29 | |
---|
30 | // Declare/Define CFieldAttribute |
---|
31 | BEGIN_DECLARE_ATTRIBUTE_MAP(CField) |
---|
32 | # include "field_attribute.conf" |
---|
33 | END_DECLARE_ATTRIBUTE_MAP(CField) |
---|
34 | |
---|
35 | ///-------------------------------------------------------------- |
---|
36 | class CField |
---|
37 | : public CObjectTemplate<CField> |
---|
38 | , public CFieldAttributes |
---|
39 | { |
---|
40 | /// friend /// |
---|
41 | friend class CFile; |
---|
42 | |
---|
43 | /// typedef /// |
---|
44 | typedef CObjectTemplate<CField> SuperClass; |
---|
45 | typedef CFieldAttributes SuperClassAttribute; |
---|
46 | |
---|
47 | public : |
---|
48 | |
---|
49 | typedef CFieldAttributes RelAttributes; |
---|
50 | typedef CFieldGroup RelGroup; |
---|
51 | |
---|
52 | enum EEventId |
---|
53 | { |
---|
54 | EVENT_ID_UPDATE_DATA |
---|
55 | } ; |
---|
56 | |
---|
57 | /// Constructeurs /// |
---|
58 | CField(void); |
---|
59 | explicit CField(const StdString & id); |
---|
60 | CField(const CField & field); // Not implemented yet. |
---|
61 | CField(const CField * const field); // Not implemented yet. |
---|
62 | |
---|
63 | /// Accesseurs /// |
---|
64 | boost::shared_ptr<CField> getDirectFieldReference(void) const; |
---|
65 | const boost::shared_ptr<CField> getBaseFieldReference(void) const; |
---|
66 | const std::vector<boost::shared_ptr<CField> > & getAllReference(void) const; |
---|
67 | |
---|
68 | boost::shared_ptr<CGrid> getRelGrid(void) const ; |
---|
69 | boost::shared_ptr<CFile> getRelFile(void) const ; |
---|
70 | |
---|
71 | public : |
---|
72 | |
---|
73 | StdSize getNStep(void) const; |
---|
74 | |
---|
75 | const date::CDuration & getFreqOperation(void) const; |
---|
76 | const date::CDuration & getFreqWrite(void) const; |
---|
77 | |
---|
78 | boost::shared_ptr<date::CDate> getLastWriteDate(void) const; |
---|
79 | boost::shared_ptr<date::CDate> getLastOperationDate(void) const; |
---|
80 | |
---|
81 | boost::shared_ptr<func::CFunctor> getFieldOperation(void) const; |
---|
82 | |
---|
83 | ARRAY(double, 1) getData(void) const; |
---|
84 | |
---|
85 | const StdString & getBaseFieldId(void) const; |
---|
86 | |
---|
87 | /// Mutateur /// |
---|
88 | void setRelFile(const boost::shared_ptr<CFile> _file); |
---|
89 | void incrementNStep(void); |
---|
90 | |
---|
91 | template <StdSize N> bool updateData(const ARRAY(double, N) data); |
---|
92 | |
---|
93 | bool updateDataServer |
---|
94 | (const date::CDate & currDate, |
---|
95 | const std::deque<ARRAY(double, 1)> storedClient); |
---|
96 | |
---|
97 | public : |
---|
98 | |
---|
99 | /// Test /// |
---|
100 | bool hasDirectFieldReference(void) const; |
---|
101 | |
---|
102 | /// Traitements /// |
---|
103 | void solveRefInheritance(void); |
---|
104 | void solveGridReference(void); |
---|
105 | void solveOperation(void); |
---|
106 | |
---|
107 | virtual void fromBinary(StdIStream & is); |
---|
108 | |
---|
109 | /// Destructeur /// |
---|
110 | virtual ~CField(void); |
---|
111 | |
---|
112 | /// Accesseurs statiques /// |
---|
113 | static StdString GetName(void); |
---|
114 | static StdString GetDefName(void); |
---|
115 | |
---|
116 | static ENodeType GetType(void); |
---|
117 | |
---|
118 | template <StdSize N> void setData(const ARRAY(double, N) _data) ; |
---|
119 | static bool dispatchEvent(CEventServer& event) ; |
---|
120 | void sendUpdateData(void) ; |
---|
121 | static void recvUpdateData(CEventServer& event) ; |
---|
122 | void recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers) ; |
---|
123 | void writeField(void) ; |
---|
124 | void outputField(ARRAY(double,3) fieldOut) ; |
---|
125 | void outputField(ARRAY(double,2) fieldOut) ; |
---|
126 | |
---|
127 | public : |
---|
128 | |
---|
129 | /// Propriétés privées /// |
---|
130 | |
---|
131 | std::vector<boost::shared_ptr<CField> > refObject; |
---|
132 | boost::shared_ptr<CField> baseRefObject; |
---|
133 | boost::shared_ptr<CGrid> grid ; |
---|
134 | boost::shared_ptr<CFile> file; |
---|
135 | |
---|
136 | date::CDuration freq_operation, freq_write; |
---|
137 | date::CDuration freq_operation_srv, freq_write_srv; |
---|
138 | |
---|
139 | StdSize nstep; |
---|
140 | boost::shared_ptr<date::CDate> last_Write, last_operation; |
---|
141 | boost::shared_ptr<date::CDate> last_Write_srv, last_operation_srv; |
---|
142 | |
---|
143 | boost::shared_ptr<func::CFunctor> foperation; |
---|
144 | map<int,boost::shared_ptr<func::CFunctor> > foperation_srv; |
---|
145 | |
---|
146 | ARRAY(double, 1) data; |
---|
147 | map<int,ARRAY(double,1)> data_srv ; |
---|
148 | |
---|
149 | }; // class CField |
---|
150 | |
---|
151 | ///-------------------------------------------------------------- |
---|
152 | |
---|
153 | // Declare/Define CFieldGroup and CFieldDefinition |
---|
154 | DECLARE_GROUP(CField); |
---|
155 | |
---|
156 | } // namespace tree |
---|
157 | |
---|
158 | ///----------------------------------------------------------------- |
---|
159 | |
---|
160 | template <> |
---|
161 | void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void); |
---|
162 | |
---|
163 | ///----------------------------------------------------------------- |
---|
164 | } // namespace xmlioserver |
---|
165 | |
---|
166 | #include "grid.hpp" |
---|
167 | |
---|
168 | namespace xmlioserver { |
---|
169 | namespace tree { |
---|
170 | |
---|
171 | template <StdSize N> |
---|
172 | void CField::setData(const ARRAY(double, N) _data) |
---|
173 | { |
---|
174 | const std::vector<boost::shared_ptr<CField> > & refField=getAllReference(); |
---|
175 | std::vector<boost::shared_ptr<CField> >::const_iterator it = refField.begin(), end = refField.end(); |
---|
176 | |
---|
177 | for (; it != end; it++) (*it)->updateData(_data) ; |
---|
178 | } |
---|
179 | |
---|
180 | template <StdSize N> |
---|
181 | bool CField::updateData(const ARRAY(double, N) _data) |
---|
182 | { |
---|
183 | shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; |
---|
184 | const date::CDate & currDate = context->getCalendar()->getCurrentDate(); |
---|
185 | const date::CDate opeDate = *last_operation + freq_operation; |
---|
186 | const date::CDate writeDate = *last_Write + freq_write; |
---|
187 | |
---|
188 | |
---|
189 | info(50) << "CField::updateData " << currDate << " : send data to " << this->getBaseFieldId() << std::endl; |
---|
190 | info(50) << "Next operation " << opeDate<<std::endl; |
---|
191 | |
---|
192 | if (opeDate <= currDate) |
---|
193 | { |
---|
194 | if (this->data->num_elements() != this->grid->storeIndex_client->num_elements()) |
---|
195 | { |
---|
196 | this->data->resize(boost::extents[this->grid->storeIndex_client ->num_elements()]); |
---|
197 | } |
---|
198 | |
---|
199 | ARRAY_CREATE(input, double, 1, [this->data->num_elements()]); |
---|
200 | this->grid->inputField(_data, input); |
---|
201 | (*this->foperation)(input); |
---|
202 | |
---|
203 | *last_operation = currDate; |
---|
204 | info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl; |
---|
205 | } |
---|
206 | |
---|
207 | if (writeDate < (currDate + freq_operation)) |
---|
208 | { |
---|
209 | this->foperation->final(); |
---|
210 | *last_Write = writeDate; |
---|
211 | info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl; |
---|
212 | sendUpdateData() ; |
---|
213 | return (true); |
---|
214 | } |
---|
215 | |
---|
216 | return (false); |
---|
217 | } |
---|
218 | |
---|
219 | } // namespace tree |
---|
220 | } // namespace xmlioserver |
---|
221 | |
---|
222 | #endif // __XMLIO_CField__ |
---|