17 namespace duds {
namespace data {
59 constexpr
Quantity(
const double &v,
const Unit &u) : value(v), unit(u) { }
66 template <
class Duration>
68 std::chrono::duration<double> sec =
69 std::chrono::duration_cast<std::chrono::seconds>(d);
166 return (unit == q.
unit) && (value == q.
value);
172 return (unit != q.
unit) || (value != q.
value);
183 template <
class Duration>
188 d = Duration(
typename Duration::rep(value *
189 (
double)(Duration::period::num) /
190 (
double)(Duration::period::den)
202 template <
class Duration>
207 return Duration(
typename Duration::rep(value *
208 (
double)(Duration::period::num) /
209 (
double)(Duration::period::den)
217 a & BOOST_SERIALIZATION_NVP(value);
218 a & BOOST_SERIALIZATION_NVP(unit);
256 #endif // #ifndef QUANTITY_HPP A container for a value and a unit to better describe the value.
Duration toDuration() const
Returns a duration with the seconds stored in this quantity.
Unit unit
The units describing the value.
Quantity operator*(const Quantity &q) const
Multiplies two quantities; the units are also multiplied.
Quantity()=default
The default constructor; expect value and unit to be uninitialized.
bool operator<(const Quantity &q) const
Compares two quantities of the same units.
constexpr Quantity(const double &v, const Unit &u)
Constructs a new Quantity with the given values.
Quantity & operator-=(const Quantity &q)
Subtracts a quantity from another; they must use the same units.
bool operator!=(const Quantity &q) const
Compares two quantities for inequality.
Quantity & operator+=(const Quantity &q)
Adds two quantities; they must use the same units.
Represents an SI unit, either base or derived.
boost::error_info< struct Info_unitname, std::string > BadUnit
The name of the bad unit.
Quantity operator+(const Quantity &q) const
Adds two quantities; they must use the same units.
A conversion between units was attempted that cannot be performed.
void toDuration(Duration &d) const
Sets a duration to the seconds stored in this quantity.
bool operator>(const Quantity &q) const
Compares two quantities of the same units.
Quantity(const Duration &d)
Constructs a new Quantity holding the number of seconds stored in the given duration.
Quantity operator-(const Quantity &q) const
Subtracts a quantity from another; they must use the same units.
friend class boost::serialization::access
bool operator<=(const Quantity &q) const
Compares two quantities of the same units.
void serialize(A &a, const unsigned int)
Quantity & operator/=(const Quantity &q)
Divides a quantity by another; the units are also divided.
Defines Unit objects for specific common base and derived SI units.
bool operator==(const Quantity &q) const
Compares two quantities for equality.
double value
Some value; probably something measured.
Quantity & operator*=(const Quantity &q)
Multiplies two quantities; the units are also multiplied.
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
constexpr Unit Second(DUDS_UNIT_VALUE(0, 0, 0, 0, 0, 0, 1, 0, 0))
Quantity operator/(const Quantity &q) const
Divides a quantity by another; the units are also divided.
bool operator>=(const Quantity &q) const
Compares two quantities of the same units.