kangaroo  1.0
the cbls library
scalarrecord.hpp
Go to the documentation of this file.
1 
12 #ifndef ScalarRecordHppIncluded
13 #define ScalarRecordHppIncluded
14 
15 
16 
19 
20 
21 
23 
24 
25 
32 template <typename data>
33 class ScalarRecord : public ScalarBase
34 {
35  public:
36 
37  typedef data DataType;
38 
41 
42  ~ScalarRecord();
43  ScalarRecord();
44  ScalarRecord(ScalarRecord<data> && that) noexcept;
45  ScalarRecord(ScalarRecord<data> const & that);
46  ScalarRecord<data> & operator = (ScalarRecord<data> && that) noexcept;
47  ScalarRecord<data> & operator = (ScalarRecord<data> const & that);
48 
50 
53 
54  virtual Serial DataTypeSerial() const override final;
55  data const & ExecData() const;
56  Bool PrevDiff(Clock const ExecClock) const;
57  data const & PrevData(Clock const ExecClock) const;
58  data const & ExecBuffer() const;
59  data const & PrevBuffer() const;
60 
62 
65 
66  void finaliseRecord(data const & Data);
67  void initialiseExecData(data const & Data);
68  void updateExecData(Clock const ExecClock, data const & Data);
69  void swapExecData(Clock const ExecClock, ScalarRecord<data> & that);
70 
72 
75 
76  void syncExecClock();
77 
79 
80  protected:
81 
84 
85  data mPrevBuffer;
86  data mExecBuffer;
87  Clock mPrevClock;
88 
90 };
91 
92 
93 
97 template <typename data>
98 inline ScalarRecord<data>::~ScalarRecord()
99 {
100  WatchError
101  // Nothing to be done.
102  CatchError
103 }
104 
105 
106 
110 template <typename data>
112 {
113  WatchError
114  // Nothing to be done.
115  CatchError
116 }
117 
118 
119 
123 template <typename data>
125  mExecBuffer(move(that.mExecBuffer)), mPrevClock(move(that.mPrevClock))
126 {
127  WatchError
128  // Nothing to be done.
129  CatchError
130 }
131 
132 
133 
134 
138 template <typename data>
141 {
142  WatchError
143  // Nothing to be done.
144  CatchError
145 }
146 
147 
148 
152 template <typename data>
154 {
155  WatchError
156  if (this == &that) return *this;
157  mPrevBuffer = move(that.mPrevBuffer);
158  mExecBuffer = move(that.mExecBuffer);
159  mPrevClock = move(that.mPrevClock);
160  return *this;
161  CatchError
162 }
163 
164 
165 
169 template <typename data>
171 {
172  WatchError
173  if (this == &that) return *this;
174  mPrevBuffer = that.mPrevBuffer;
175  mExecBuffer = that.mExecBuffer;
176  mPrevClock = that.mPrevClock;
177  return *this;
178  CatchError
179 }
180 
181 
182 
186 template<typename data>
188 {
189  WatchError
190  if (mPrevClock < InvalidClock) mPrevClock = InitialClock;
191  CatchError
192 }
193 
194 
195 
199 template<typename data>
200 inline void ScalarRecord<data>::finaliseRecord(data const & Data)
201 {
202  WatchError
203  mExecBuffer = Data;
204  mPrevClock = EternalClock;
205  CatchError
206 }
207 
208 
209 
213 template<typename data>
214 inline void ScalarRecord<data>::initialiseExecData(data const & Data)
215 {
216  WatchError
217  mExecBuffer = Data;
218  mPrevClock = InitialClock;
219  CatchError
220 }
221 
222 
223 
227 template<typename data>
228 inline void ScalarRecord<data>::updateExecData(Clock const ExecClock, data const & Data)
229 {
230  WatchError
231  Warn(ExecClock < mPrevClock, eClockConflict);
232 
233  if (eq<data,Bool>::iof(mExecBuffer, Data))
234  mPrevClock = InitialClock;
235  else
236  {
237  mPrevClock = ExecClock;
239  mExecBuffer = Data;
240  }
241  CatchError
242 }
243 
244 
245 
249 template<typename data>
250 inline void ScalarRecord<data>::swapExecData(Clock const ExecClock, ScalarRecord<data> & that)
251 {
252  WatchError
253  Warn(ExecClock < mPrevClock, eClockConflict);
254  Warn(ExecClock < that.mPrevClock, eClockConflict);
255 
256  if (eq<data,Bool>::iof(mExecBuffer, that.mExecBuffer))
257  mPrevClock = that.mPrevClock = InitialClock;
258  else
259  {
260  mPrevClock = that.mPrevClock = ExecClock;
262  that.mPrevBuffer = that.mExecBuffer;
263  mExecBuffer = that.mPrevBuffer;
264  that.mExecBuffer = mPrevBuffer;
265  }
266 
267  CatchError
268 }
269 
270 
274 template<typename data>
276 {
277  WatchError
279  CatchError
280 }
281 
282 
286 template<typename data>
287 inline data const & ScalarRecord<data>::ExecData() const
288 {
289  WatchError
290  return mExecBuffer;
291  CatchError
292 }
293 
294 
295 
299 template<typename data>
300 inline data const & ScalarRecord<data>::PrevData(Clock const ExecClock) const
301 {
302  WatchError
303  return mPrevClock == ExecClock ? mPrevBuffer : mExecBuffer;
304  CatchError
305 }
306 
307 
308 
312 template<typename data>
313 inline Bool ScalarRecord<data>::PrevDiff(Clock const ExecClock) const
314 {
315  WatchError
316  return mPrevClock == ExecClock;
317  CatchError
318 }
319 
320 
321 
325 template<typename data>
326 inline data const & ScalarRecord<data>::ExecBuffer() const
327 {
328  WatchError
329  return mExecBuffer;
330  CatchError
331 }
332 
333 
334 
338 template<typename data>
339 inline data const & ScalarRecord<data>::PrevBuffer() const
340 {
341  WatchError
342  return mPrevBuffer;
343  CatchError
344 }
345 
346 
347 
348 
350 
351 
352 
353 #endif//ScalarRecordHppIncluded
void updateExecData(Clock const ExecClock, data const &Data)
Update the execution data.
Definition: scalarrecord.hpp:228
ScalarRecord()
Default constructor.
Definition: scalarrecord.hpp:111
Scalar records store expression scalar metrics.
Definition: scalarrecord.hpp:33
#define openKangarooSpace
Open the project namespace.
Definition: project.hpp:74
void initialiseExecData(data const &Data)
Initialise the execution data.
Definition: scalarrecord.hpp:214
data mExecBuffer
ExecBuffer is valid after initialisation.
Definition: scalarrecord.hpp:86
data const & PrevData(Clock const ExecClock) const
PrevData = PrevDiff ? PrevBuffer : ExecBuffer().
Definition: scalarrecord.hpp:300
Bool PrevDiff(Clock const ExecClock) const
PrevDiff = (PrevClock == ExecClock).
Definition: scalarrecord.hpp:313
Data types, metadata types, limits, and ordering.
data const & ExecData() const
Return execution data in execution buffer.
Definition: scalarrecord.hpp:287
Scalar base is the base class for scalar metrics.
Definition: scalarbase.hpp:31
void finaliseRecord(data const &Data)
Finalise the record for constants.
Definition: scalarrecord.hpp:200
virtual Serial DataTypeSerial() const overridefinal
Data type serial.
Definition: scalarrecord.hpp:275
data const & PrevBuffer() const
Return previous data in previous buffer: validity depends on PrevDiff.
Definition: scalarrecord.hpp:339
Clock mPrevClock
PrevClock determines validity of PrevBuffer.
Definition: scalarrecord.hpp:87
void syncExecClock()
Synchronise with the execution clock.
Definition: scalarrecord.hpp:187
data DataType
Data type.
Definition: scalarrecord.hpp:37
Scalar base is the base class for scalar metrics.
data const & ExecBuffer() const
Return execution data in execution buffer.
Definition: scalarrecord.hpp:326
data mPrevBuffer
PrevBuffer is valid only at PrevClock.
Definition: scalarrecord.hpp:85
ScalarRecord< data > & operator=(ScalarRecord< data > &&that) noexcept
Move assignment.
Definition: scalarrecord.hpp:153
#define closeKangarooSpace
Close the project namespace.
Definition: project.hpp:75
void swapExecData(Clock const ExecClock, ScalarRecord< data > &that)
Swap two execution data.
Definition: scalarrecord.hpp:250
Represents data type meta.
Definition: datatypes.hpp:73
~ScalarRecord()
Destructor.
Definition: scalarrecord.hpp:98