[219] | 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" |
---|
[231] | 12 | #include "calendar_util.hpp" |
---|
[300] | 13 | //#include "context.hpp" |
---|
[219] | 14 | |
---|
[300] | 15 | |
---|
[219] | 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; |
---|
[300] | 27 | class CContext ; |
---|
[219] | 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 | |
---|
[300] | 52 | enum EEventId |
---|
| 53 | { |
---|
| 54 | EVENT_ID_UPDATE_DATA |
---|
| 55 | } ; |
---|
| 56 | |
---|
[219] | 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 | |
---|
[266] | 73 | StdSize getNStep(void) const; |
---|
| 74 | |
---|
[219] | 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); |
---|
[266] | 89 | void incrementNStep(void); |
---|
[219] | 90 | |
---|
[300] | 91 | template <StdSize N> bool updateData(const ARRAY(double, N) data); |
---|
| 92 | |
---|
[219] | 93 | bool updateDataServer |
---|
[268] | 94 | (const date::CDate & currDate, |
---|
| 95 | const std::deque<ARRAY(double, 1)> storedClient); |
---|
[300] | 96 | |
---|
| 97 | public : |
---|
[219] | 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); |
---|
[300] | 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 : |
---|
[219] | 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; |
---|
[300] | 137 | date::CDuration freq_operation_srv, freq_write_srv; |
---|
[219] | 138 | |
---|
[266] | 139 | StdSize nstep; |
---|
[219] | 140 | boost::shared_ptr<date::CDate> last_Write, last_operation; |
---|
[300] | 141 | boost::shared_ptr<date::CDate> last_Write_srv, last_operation_srv; |
---|
| 142 | |
---|
[219] | 143 | boost::shared_ptr<func::CFunctor> foperation; |
---|
[300] | 144 | map<int,boost::shared_ptr<func::CFunctor> > foperation_srv; |
---|
[219] | 145 | |
---|
| 146 | ARRAY(double, 1) data; |
---|
[300] | 147 | map<int,ARRAY(double,1)> data_srv ; |
---|
[219] | 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> |
---|
[300] | 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) |
---|
[266] | 182 | { |
---|
[300] | 183 | shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; |
---|
| 184 | const date::CDate & currDate = context->getCalendar()->getCurrentDate(); |
---|
[266] | 185 | const date::CDate opeDate = *last_operation + freq_operation; |
---|
| 186 | const date::CDate writeDate = *last_Write + freq_write; |
---|
| 187 | |
---|
| 188 | |
---|
[300] | 189 | info(50) << "CField::updateData " << currDate << " : send data to " << this->getBaseFieldId() << std::endl; |
---|
| 190 | info(50) << "Next operation " << opeDate<<std::endl; |
---|
| 191 | |
---|
[266] | 192 | if (opeDate <= currDate) |
---|
[219] | 193 | { |
---|
[300] | 194 | if (this->data->num_elements() != this->grid->storeIndex_client->num_elements()) |
---|
[266] | 195 | { |
---|
[300] | 196 | this->data->resize(boost::extents[this->grid->storeIndex_client ->num_elements()]); |
---|
[266] | 197 | } |
---|
| 198 | |
---|
| 199 | ARRAY_CREATE(input, double, 1, [this->data->num_elements()]); |
---|
| 200 | this->grid->inputField(_data, input); |
---|
[219] | 201 | (*this->foperation)(input); |
---|
[266] | 202 | |
---|
[219] | 203 | *last_operation = currDate; |
---|
[300] | 204 | info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl; |
---|
[219] | 205 | } |
---|
| 206 | |
---|
[266] | 207 | if (writeDate < (currDate + freq_operation)) |
---|
[219] | 208 | { |
---|
[266] | 209 | this->foperation->final(); |
---|
| 210 | *last_Write = writeDate; |
---|
[300] | 211 | info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl; |
---|
| 212 | sendUpdateData() ; |
---|
[266] | 213 | return (true); |
---|
[219] | 214 | } |
---|
[300] | 215 | |
---|
[219] | 216 | return (false); |
---|
[300] | 217 | } |
---|
[219] | 218 | |
---|
| 219 | } // namespace tree |
---|
| 220 | } // namespace xmlioserver |
---|
| 221 | |
---|
| 222 | #endif // __XMLIO_CField__ |
---|