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 | |
---|
14 | namespace xmlioserver { |
---|
15 | namespace 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 | const date::CDuration & getFreqOperation(void) const; |
---|
67 | const date::CDuration & getFreqWrite(void) const; |
---|
68 | |
---|
69 | boost::shared_ptr<date::CDate> getLastWriteDate(void) const; |
---|
70 | boost::shared_ptr<date::CDate> getLastOperationDate(void) const; |
---|
71 | |
---|
72 | boost::shared_ptr<func::CFunctor> getFieldOperation(void) const; |
---|
73 | |
---|
74 | ARRAY(double, 1) getData(void) const; |
---|
75 | |
---|
76 | const StdString & getBaseFieldId(void) const; |
---|
77 | |
---|
78 | /// Mutateur /// |
---|
79 | void setRelFile(const boost::shared_ptr<CFile> _file); |
---|
80 | |
---|
81 | template <StdSize N> |
---|
82 | inline bool updateData |
---|
83 | (const date::CDate & currDate, const ARRAY(double, N) data); |
---|
84 | |
---|
85 | bool updateDataServer |
---|
86 | (const date::CDate & currDate, const std::deque<ARRAY(double, 1)> storedClient); |
---|
87 | |
---|
88 | public : |
---|
89 | |
---|
90 | /// Test /// |
---|
91 | bool hasDirectFieldReference(void) const; |
---|
92 | |
---|
93 | /// Traitements /// |
---|
94 | void solveRefInheritance(void); |
---|
95 | void solveGridReference(void); |
---|
96 | void solveOperation(void); |
---|
97 | |
---|
98 | virtual void fromBinary(StdIStream & is); |
---|
99 | |
---|
100 | /// Destructeur /// |
---|
101 | virtual ~CField(void); |
---|
102 | |
---|
103 | /// Accesseurs statiques /// |
---|
104 | static StdString GetName(void); |
---|
105 | static StdString GetDefName(void); |
---|
106 | |
---|
107 | static ENodeType GetType(void); |
---|
108 | |
---|
109 | private : |
---|
110 | |
---|
111 | /// Propriétés privées /// |
---|
112 | |
---|
113 | std::vector<boost::shared_ptr<CField> > refObject; |
---|
114 | boost::shared_ptr<CField> baseRefObject; |
---|
115 | boost::shared_ptr<CGrid> grid ; |
---|
116 | boost::shared_ptr<CFile> file; |
---|
117 | |
---|
118 | date::CDuration freq_operation, freq_write; |
---|
119 | |
---|
120 | boost::shared_ptr<date::CDate> last_Write, last_operation; |
---|
121 | boost::shared_ptr<func::CFunctor> foperation; |
---|
122 | |
---|
123 | ARRAY(double, 1) data; |
---|
124 | |
---|
125 | }; // class CField |
---|
126 | |
---|
127 | ///-------------------------------------------------------------- |
---|
128 | |
---|
129 | // Declare/Define CFieldGroup and CFieldDefinition |
---|
130 | DECLARE_GROUP(CField); |
---|
131 | |
---|
132 | } // namespace tree |
---|
133 | |
---|
134 | ///----------------------------------------------------------------- |
---|
135 | |
---|
136 | template <> |
---|
137 | void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void); |
---|
138 | |
---|
139 | ///----------------------------------------------------------------- |
---|
140 | } // namespace xmlioserver |
---|
141 | |
---|
142 | #include "grid.hpp" |
---|
143 | |
---|
144 | namespace xmlioserver { |
---|
145 | namespace tree { |
---|
146 | |
---|
147 | template <StdSize N> |
---|
148 | bool CField::updateData(const date::CDate & currDate, const ARRAY(double, N) data) |
---|
149 | { |
---|
150 | if ((*last_operation + freq_operation) >= currDate) |
---|
151 | { |
---|
152 | ARRAY_CREATE(input, double, 1, [0]); |
---|
153 | input->resize(boost::extents[data->size()]); |
---|
154 | this->grid->inputField(data, input); |
---|
155 | (*this->foperation)(input); |
---|
156 | *last_operation = currDate; |
---|
157 | } |
---|
158 | |
---|
159 | if ((*last_Write + freq_write) >= currDate) |
---|
160 | { |
---|
161 | *last_Write = currDate; |
---|
162 | return (true); |
---|
163 | } |
---|
164 | return (false); |
---|
165 | }; |
---|
166 | |
---|
167 | } // namespace tree |
---|
168 | } // namespace xmlioserver |
---|
169 | |
---|
170 | #endif // __XMLIO_CField__ |
---|