[152] | 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" |
---|
[157] | 8 | #include "functor_type.hpp" |
---|
[187] | 9 | #include "duration.hpp" |
---|
[206] | 10 | #include "date.hpp" |
---|
[152] | 11 | #include "declare_group.hpp" |
---|
[229] | 12 | #include "calendar_util.hpp" |
---|
[152] | 13 | |
---|
[168] | 14 | namespace xmlioserver { |
---|
| 15 | namespace tree { |
---|
| 16 | |
---|
| 17 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
[152] | 18 | |
---|
[168] | 19 | class CFieldGroup; |
---|
| 20 | class CFieldAttributes; |
---|
| 21 | class CField; |
---|
[152] | 22 | |
---|
[168] | 23 | class CFile; |
---|
| 24 | class CGrid; |
---|
[152] | 25 | |
---|
[168] | 26 | ///-------------------------------------------------------------- |
---|
[152] | 27 | |
---|
[168] | 28 | // Declare/Define CFieldAttribute |
---|
| 29 | BEGIN_DECLARE_ATTRIBUTE_MAP(CField) |
---|
[173] | 30 | # include "field_attribute.conf" |
---|
[168] | 31 | END_DECLARE_ATTRIBUTE_MAP(CField) |
---|
[152] | 32 | |
---|
[168] | 33 | ///-------------------------------------------------------------- |
---|
| 34 | class CField |
---|
| 35 | : public CObjectTemplate<CField> |
---|
| 36 | , public CFieldAttributes |
---|
| 37 | { |
---|
| 38 | /// friend /// |
---|
| 39 | friend class CFile; |
---|
[152] | 40 | |
---|
[168] | 41 | /// typedef /// |
---|
| 42 | typedef CObjectTemplate<CField> SuperClass; |
---|
| 43 | typedef CFieldAttributes SuperClassAttribute; |
---|
[152] | 44 | |
---|
[168] | 45 | public : |
---|
[152] | 46 | |
---|
[168] | 47 | typedef CFieldAttributes RelAttributes; |
---|
| 48 | typedef CFieldGroup RelGroup; |
---|
[152] | 49 | |
---|
[168] | 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. |
---|
[152] | 55 | |
---|
[168] | 56 | /// Accesseurs /// |
---|
[214] | 57 | boost::shared_ptr<CField> getDirectFieldReference(void) const; |
---|
| 58 | const boost::shared_ptr<CField> getBaseFieldReference(void) const; |
---|
[168] | 59 | const std::vector<boost::shared_ptr<CField> > & getAllReference(void) const; |
---|
[152] | 60 | |
---|
[168] | 61 | boost::shared_ptr<CGrid> getRelGrid(void) const ; |
---|
| 62 | boost::shared_ptr<CFile> getRelFile(void) const ; |
---|
[208] | 63 | |
---|
| 64 | public : |
---|
| 65 | |
---|
[265] | 66 | StdSize getNStep(void) const; |
---|
| 67 | |
---|
[188] | 68 | const date::CDuration & getFreqOperation(void) const; |
---|
| 69 | const date::CDuration & getFreqWrite(void) const; |
---|
[206] | 70 | |
---|
| 71 | boost::shared_ptr<date::CDate> getLastWriteDate(void) const; |
---|
| 72 | boost::shared_ptr<date::CDate> getLastOperationDate(void) const; |
---|
| 73 | |
---|
[188] | 74 | boost::shared_ptr<func::CFunctor> getFieldOperation(void) const; |
---|
| 75 | |
---|
| 76 | ARRAY(double, 1) getData(void) const; |
---|
[152] | 77 | |
---|
[168] | 78 | const StdString & getBaseFieldId(void) const; |
---|
[152] | 79 | |
---|
[168] | 80 | /// Mutateur /// |
---|
| 81 | void setRelFile(const boost::shared_ptr<CFile> _file); |
---|
[265] | 82 | void incrementNStep(void); |
---|
[152] | 83 | |
---|
[206] | 84 | template <StdSize N> |
---|
| 85 | inline bool updateData |
---|
[265] | 86 | (const date::CDate & currDate, const date::CDuration & timestep, const ARRAY(double, N) data); |
---|
[206] | 87 | |
---|
| 88 | bool updateDataServer |
---|
| 89 | (const date::CDate & currDate, const std::deque<ARRAY(double, 1)> storedClient); |
---|
| 90 | |
---|
[168] | 91 | public : |
---|
[152] | 92 | |
---|
[168] | 93 | /// Test /// |
---|
| 94 | bool hasDirectFieldReference(void) const; |
---|
[152] | 95 | |
---|
[168] | 96 | /// Traitements /// |
---|
| 97 | void solveRefInheritance(void); |
---|
| 98 | void solveGridReference(void); |
---|
| 99 | void solveOperation(void); |
---|
[152] | 100 | |
---|
[181] | 101 | virtual void fromBinary(StdIStream & is); |
---|
| 102 | |
---|
[168] | 103 | /// Destructeur /// |
---|
| 104 | virtual ~CField(void); |
---|
[152] | 105 | |
---|
[168] | 106 | /// Accesseurs statiques /// |
---|
| 107 | static StdString GetName(void); |
---|
| 108 | static StdString GetDefName(void); |
---|
| 109 | |
---|
| 110 | static ENodeType GetType(void); |
---|
[152] | 111 | |
---|
[168] | 112 | private : |
---|
[152] | 113 | |
---|
[168] | 114 | /// Propriétés privées /// |
---|
[187] | 115 | |
---|
| 116 | std::vector<boost::shared_ptr<CField> > refObject; |
---|
[168] | 117 | boost::shared_ptr<CField> baseRefObject; |
---|
[187] | 118 | boost::shared_ptr<CGrid> grid ; |
---|
| 119 | boost::shared_ptr<CFile> file; |
---|
[152] | 120 | |
---|
[187] | 121 | date::CDuration freq_operation, freq_write; |
---|
[206] | 122 | |
---|
[265] | 123 | StdSize nstep; |
---|
[206] | 124 | boost::shared_ptr<date::CDate> last_Write, last_operation; |
---|
[187] | 125 | boost::shared_ptr<func::CFunctor> foperation; |
---|
| 126 | |
---|
| 127 | ARRAY(double, 1) data; |
---|
[152] | 128 | |
---|
[168] | 129 | }; // class CField |
---|
[152] | 130 | |
---|
[168] | 131 | ///-------------------------------------------------------------- |
---|
[152] | 132 | |
---|
[168] | 133 | // Declare/Define CFieldGroup and CFieldDefinition |
---|
| 134 | DECLARE_GROUP(CField); |
---|
[152] | 135 | |
---|
| 136 | } // namespace tree |
---|
| 137 | |
---|
| 138 | ///----------------------------------------------------------------- |
---|
| 139 | |
---|
| 140 | template <> |
---|
| 141 | void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void); |
---|
| 142 | |
---|
[206] | 143 | ///----------------------------------------------------------------- |
---|
[152] | 144 | } // namespace xmlioserver |
---|
| 145 | |
---|
[206] | 146 | #include "grid.hpp" |
---|
| 147 | |
---|
| 148 | namespace xmlioserver { |
---|
| 149 | namespace tree { |
---|
| 150 | |
---|
| 151 | template <StdSize N> |
---|
[265] | 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) |
---|
[206] | 167 | { |
---|
[265] | 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); |
---|
[206] | 177 | (*this->foperation)(input); |
---|
[265] | 178 | |
---|
[206] | 179 | *last_operation = currDate; |
---|
[265] | 180 | // std::cout << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl; |
---|
[206] | 181 | } |
---|
| 182 | |
---|
[265] | 183 | if (writeDate < (currDate + freq_operation)) |
---|
[206] | 184 | { |
---|
[265] | 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); |
---|
[206] | 190 | } |
---|
[265] | 191 | // std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl; |
---|
[206] | 192 | return (false); |
---|
| 193 | }; |
---|
| 194 | |
---|
| 195 | } // namespace tree |
---|
| 196 | } // namespace xmlioserver |
---|
| 197 | |
---|
[152] | 198 | #endif // __XMLIO_CField__ |
---|