DUDS
Distributed Update of Data from Something
Sample.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
11 #include <boost/uuid/nil_generator.hpp>
12 #include <limits>
13 
14 namespace duds { namespace data {
15 
20 namespace _it_needs_to_go_somewhere_ {
27  template <class T>
28  struct infinity {
29  static constexpr T value = std::numeric_limits<T>::infinity();
30  };
37  template <class T>
38  struct lowest {
39  static constexpr T value = std::numeric_limits<T>::lowest();
40  };
41 }
42 
51 template <typename QT>
52 static constexpr QT unspecified() {
53  return std::conditional<std::numeric_limits<QT>::has_infinity,
56  >::type::value;
57 }
58 
59 template <class VT = GenericValue, class QT = double>
61 
80 template <class VT, class QT>
81 struct GenericSample {
82  typedef VT Value;
83  typedef QT Quality;
88  static constexpr QT unspecified() {
89  return duds::data::unspecified<QT>();
90  }
96  boost::uuids::uuid origin;
102  VT value;
132  CompactSample<VT, QT> makeCompactSample() const;
136  operator CompactSample<VT, QT> () const {
137  return makeCompactSample();
138  }
143  void clear() {
144  origin = boost::uuids::nil_uuid();
145  //value = std::string(); // good idea, but template types kills it
146  accuracy = precision = estError = resolution = unspecified();
147  }
154  bool isClear() const {
155  // constraining the value is a nice idea, but is type specific
156  return /*(value.which() == 0) &&*/ origin.is_nil();
157  }
158 };
159 
167 
185 template <class VT, class QT> // default types in forward declaration above
186 struct CompactSample {
187  typedef VT Value;
188  typedef QT Quality;
193  static constexpr QT Unspecified = std::numeric_limits<QT>::infinity();
197  VT value;
218  /*
219  * Produce a Sample using the data in this CompactSample and the given units.
220  * @param unit The units used in the CompactSample; used to fill the units
221  * field of the procuded Sample object.
222  */
223  /*
224  Sample<VT, QT> makeSample(const Unit unit) const {
225  Sample<VT, QT> s = { value, accuracy, precision, resolution, unit };
226  return s;
227  }
228  */
229 };
230 
231 // no units
232 template <class VT, class QT> // default types in forward declaration above
233 struct SampleNU {
234  typedef VT Value;
235  typedef QT Quality;
240  static constexpr QT Unspecified = std::numeric_limits<QT>::infinity();
244  boost::uuids::uuid origin;
248  VT value;
269  /*
270  * Produce a Sample using the data in this CompactSample and the given units.
271  * @param unit The units used in the CompactSample; used to fill the units
272  * field of the procuded Sample object.
273  */
274  /*
275  Sample<VT, QT> makeSample(const Unit unit) const {
276  Sample<VT, QT> s = { value, accuracy, precision, resolution, unit };
277  return s;
278  }
279  */
280 };
281 
282 
283 template <class VT, class QT>
285  CompactSample<VT, QT> cs = { value, accuracy, precision, resolution };
286  return cs;
287 }
288 
289 template <class VT>
294  VT value;
295 };
296 
297 } }
QT resolution
The expected resolution of the instrument under the conditions in which the sample was taken...
Definition: Sample.hpp:217
CompactSample< VT, QT > makeCompactSample() const
Produce a CompactSample using the data in this Sample.
Definition: Sample.hpp:284
void clear()
Initializes the sample to hold no data.
Definition: Sample.hpp:143
QT resolution
The expected resolution of the instrument under the conditions in which the sample was taken...
Definition: Sample.hpp:268
QT estError
The estimated error of the observation.
Definition: Sample.hpp:120
A template for a sample from an insturment.
Definition: Sample.hpp:81
QT precision
The expected precision of the instrument under the conditions in which the sample was taken...
Definition: Sample.hpp:260
QT resolution
The expected resolution of the instrument under the conditions in which the sample was taken...
Definition: Sample.hpp:128
VT value
The value sampled from the insturment.
Definition: Sample.hpp:102
GenericSample< GenericValue, double > Sample
A sample type that is good for general purpose use.
Definition: Sample.hpp:166
boost::uuids::uuid origin
The UUID for the source instrument of this sample.
Definition: Sample.hpp:96
QT accuracy
The expected accuracy of the instrument under the conditions in which the sample was taken...
Definition: Sample.hpp:202
VT value
The value sampled from the insturment.
Definition: Sample.hpp:294
QT accuracy
The expected accuracy of the instrument under the conditions in which the sample was taken...
Definition: Sample.hpp:107
bool isClear() const
Returns true when this object contains no sample data.
Definition: Sample.hpp:154
static constexpr QT unspecified()
Returns the value used to represent an unspecified or unknown accuracy, precision, resolution, or error.
Definition: Sample.hpp:52
QT precision
The expected precision of the instrument under the conditions in which the sample was taken...
Definition: Sample.hpp:209
static constexpr QT unspecified()
Returns the value used to represent an unspecified or unknown accuracy, precision, resolution, or error.
Definition: Sample.hpp:88
boost::uuids::uuid origin
The source of this sample.
Definition: Sample.hpp:244
VT value
The value sampled from the insturment.
Definition: Sample.hpp:197
VT value
The value sampled from the insturment.
Definition: Sample.hpp:248
QT precision
The expected precision of the instrument under the conditions in which the sample was taken...
Definition: Sample.hpp:114
QT accuracy
The expected accuracy of the instrument under the conditions in which the sample was taken...
Definition: Sample.hpp:253
A template for a sample from an insturment that does not store units or the origin.
Definition: Sample.hpp:60