[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); |
---|
[321] | 90 | void resetNStep() ; |
---|
[219] | 91 | |
---|
[300] | 92 | template <StdSize N> bool updateData(const ARRAY(double, N) data); |
---|
| 93 | |
---|
[219] | 94 | bool updateDataServer |
---|
[268] | 95 | (const date::CDate & currDate, |
---|
| 96 | const std::deque<ARRAY(double, 1)> storedClient); |
---|
[300] | 97 | |
---|
| 98 | public : |
---|
[219] | 99 | |
---|
| 100 | /// Test /// |
---|
| 101 | bool hasDirectFieldReference(void) const; |
---|
[310] | 102 | bool isActive(void) const; |
---|
[219] | 103 | |
---|
| 104 | /// Traitements /// |
---|
| 105 | void solveRefInheritance(void); |
---|
| 106 | void solveGridReference(void); |
---|
| 107 | void solveOperation(void); |
---|
| 108 | |
---|
| 109 | virtual void fromBinary(StdIStream & is); |
---|
| 110 | |
---|
| 111 | /// Destructeur /// |
---|
| 112 | virtual ~CField(void); |
---|
| 113 | |
---|
| 114 | /// Accesseurs statiques /// |
---|
| 115 | static StdString GetName(void); |
---|
| 116 | static StdString GetDefName(void); |
---|
| 117 | |
---|
| 118 | static ENodeType GetType(void); |
---|
[300] | 119 | |
---|
| 120 | template <StdSize N> void setData(const ARRAY(double, N) _data) ; |
---|
| 121 | static bool dispatchEvent(CEventServer& event) ; |
---|
| 122 | void sendUpdateData(void) ; |
---|
| 123 | static void recvUpdateData(CEventServer& event) ; |
---|
| 124 | void recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers) ; |
---|
| 125 | void writeField(void) ; |
---|
| 126 | void outputField(ARRAY(double,3) fieldOut) ; |
---|
| 127 | void outputField(ARRAY(double,2) fieldOut) ; |
---|
| 128 | |
---|
| 129 | public : |
---|
[219] | 130 | |
---|
| 131 | /// Propriétés privées /// |
---|
| 132 | |
---|
| 133 | std::vector<boost::shared_ptr<CField> > refObject; |
---|
| 134 | boost::shared_ptr<CField> baseRefObject; |
---|
| 135 | boost::shared_ptr<CGrid> grid ; |
---|
| 136 | boost::shared_ptr<CFile> file; |
---|
| 137 | |
---|
| 138 | date::CDuration freq_operation, freq_write; |
---|
[300] | 139 | date::CDuration freq_operation_srv, freq_write_srv; |
---|
[219] | 140 | |
---|
[266] | 141 | StdSize nstep; |
---|
[219] | 142 | boost::shared_ptr<date::CDate> last_Write, last_operation; |
---|
[300] | 143 | boost::shared_ptr<date::CDate> last_Write_srv, last_operation_srv; |
---|
| 144 | |
---|
[219] | 145 | boost::shared_ptr<func::CFunctor> foperation; |
---|
[300] | 146 | map<int,boost::shared_ptr<func::CFunctor> > foperation_srv; |
---|
[219] | 147 | |
---|
| 148 | ARRAY(double, 1) data; |
---|
[300] | 149 | map<int,ARRAY(double,1)> data_srv ; |
---|
[219] | 150 | |
---|
| 151 | }; // class CField |
---|
| 152 | |
---|
| 153 | ///-------------------------------------------------------------- |
---|
| 154 | |
---|
| 155 | // Declare/Define CFieldGroup and CFieldDefinition |
---|
| 156 | DECLARE_GROUP(CField); |
---|
| 157 | |
---|
| 158 | } // namespace tree |
---|
| 159 | |
---|
| 160 | ///----------------------------------------------------------------- |
---|
| 161 | |
---|
| 162 | template <> |
---|
| 163 | void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void); |
---|
| 164 | |
---|
| 165 | ///----------------------------------------------------------------- |
---|
| 166 | } // namespace xmlioserver |
---|
| 167 | |
---|
| 168 | #include "grid.hpp" |
---|
| 169 | |
---|
| 170 | namespace xmlioserver { |
---|
| 171 | namespace tree { |
---|
| 172 | |
---|
| 173 | template <StdSize N> |
---|
[300] | 174 | void CField::setData(const ARRAY(double, N) _data) |
---|
| 175 | { |
---|
| 176 | const std::vector<boost::shared_ptr<CField> > & refField=getAllReference(); |
---|
| 177 | std::vector<boost::shared_ptr<CField> >::const_iterator it = refField.begin(), end = refField.end(); |
---|
| 178 | |
---|
| 179 | for (; it != end; it++) (*it)->updateData(_data) ; |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | template <StdSize N> |
---|
| 183 | bool CField::updateData(const ARRAY(double, N) _data) |
---|
[266] | 184 | { |
---|
[300] | 185 | shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; |
---|
| 186 | const date::CDate & currDate = context->getCalendar()->getCurrentDate(); |
---|
[266] | 187 | const date::CDate opeDate = *last_operation + freq_operation; |
---|
| 188 | const date::CDate writeDate = *last_Write + freq_write; |
---|
| 189 | |
---|
| 190 | |
---|
[300] | 191 | info(50) << "CField::updateData " << currDate << " : send data to " << this->getBaseFieldId() << std::endl; |
---|
| 192 | info(50) << "Next operation " << opeDate<<std::endl; |
---|
| 193 | |
---|
[266] | 194 | if (opeDate <= currDate) |
---|
[219] | 195 | { |
---|
[300] | 196 | if (this->data->num_elements() != this->grid->storeIndex_client->num_elements()) |
---|
[266] | 197 | { |
---|
[300] | 198 | this->data->resize(boost::extents[this->grid->storeIndex_client ->num_elements()]); |
---|
[266] | 199 | } |
---|
| 200 | |
---|
| 201 | ARRAY_CREATE(input, double, 1, [this->data->num_elements()]); |
---|
| 202 | this->grid->inputField(_data, input); |
---|
[219] | 203 | (*this->foperation)(input); |
---|
[266] | 204 | |
---|
[219] | 205 | *last_operation = currDate; |
---|
[300] | 206 | info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl; |
---|
[219] | 207 | } |
---|
| 208 | |
---|
[266] | 209 | if (writeDate < (currDate + freq_operation)) |
---|
[219] | 210 | { |
---|
[266] | 211 | this->foperation->final(); |
---|
| 212 | *last_Write = writeDate; |
---|
[300] | 213 | info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl; |
---|
| 214 | sendUpdateData() ; |
---|
[266] | 215 | return (true); |
---|
[219] | 216 | } |
---|
[300] | 217 | |
---|
[219] | 218 | return (false); |
---|
[300] | 219 | } |
---|
[219] | 220 | |
---|
| 221 | } // namespace tree |
---|
| 222 | } // namespace xmlioserver |
---|
| 223 | |
---|
| 224 | #endif // __XMLIO_CField__ |
---|