|
DUDS
|
Distributed Update of Data from Something
|
A container for a value and a unit to better describe the value. More...
#include <Quantity.hpp>
Public Member Functions | |
| Quantity ()=default | |
| The default constructor; expect value and unit to be uninitialized. More... | |
| Quantity (const Quantity &)=default | |
| A default copy constrcutor. More... | |
| constexpr | Quantity (const double &v, const Unit &u) |
| Constructs a new Quantity with the given values. More... | |
| template<class Duration > | |
| Quantity (const Duration &d) | |
| Constructs a new Quantity holding the number of seconds stored in the given duration. More... | |
| bool | operator!= (const Quantity &q) const |
| Compares two quantities for inequality. More... | |
| Quantity | operator* (const Quantity &q) const |
| Multiplies two quantities; the units are also multiplied. More... | |
| Quantity | operator* (double s) const |
| Multiplies a Quantity by a scalar. More... | |
| Quantity & | operator*= (const Quantity &q) |
| Multiplies two quantities; the units are also multiplied. More... | |
| Quantity & | operator*= (double s) |
| Multiplies a Quantity by a scalar. More... | |
| Quantity | operator+ (const Quantity &q) const |
| Adds two quantities; they must use the same units. More... | |
| Quantity & | operator+= (const Quantity &q) |
| Adds two quantities; they must use the same units. More... | |
| Quantity | operator- (const Quantity &q) const |
| Subtracts a quantity from another; they must use the same units. More... | |
| Quantity & | operator-= (const Quantity &q) |
| Subtracts a quantity from another; they must use the same units. More... | |
| Quantity | operator/ (const Quantity &q) const |
| Divides a quantity by another; the units are also divided. More... | |
| Quantity | operator/ (double s) const |
| Divides a Quantity by a scalar. More... | |
| Quantity & | operator/= (const Quantity &q) |
| Divides a quantity by another; the units are also divided. More... | |
| Quantity & | operator/= (double s) |
| Divides a Quantity by a scalar. More... | |
| bool | operator< (const Quantity &q) const |
| Compares two quantities of the same units. More... | |
| bool | operator<= (const Quantity &q) const |
| Compares two quantities of the same units. More... | |
| bool | operator== (const Quantity &q) const |
| Compares two quantities for equality. More... | |
| bool | operator> (const Quantity &q) const |
| Compares two quantities of the same units. More... | |
| bool | operator>= (const Quantity &q) const |
| Compares two quantities of the same units. More... | |
| template<class Duration > | |
| void | toDuration (Duration &d) const |
| Sets a duration to the seconds stored in this quantity. More... | |
| template<class Duration > | |
| Duration | toDuration () const |
| Returns a duration with the seconds stored in this quantity. More... | |
Public Attributes | |
| Unit | unit |
| The units describing the value. More... | |
| double | value |
| Some value; probably something measured. More... | |
Private Member Functions | |
| template<class A > | |
| void | serialize (A &a, const unsigned int) |
Friends | |
| class | boost::serialization::access |
A container for a value and a unit to better describe the value.
This struct has a full set of arithmetic operators with Quantity objects as both operands. These operators enforce proper use of units by throwing exceptions when the operation is invalid. For multiplication and division, the new unit is also computed for the result.
The unit member is a Unit, which is simpiler to work with than an ExtendedUnit. Because of the limitations of Unit, the value member must be floating point. Bewteen this and the decision to use doubles unless integers are a better representation, I decided not to make this class a template and force the use of a double.
Definition at line 37 of file Quantity.hpp.
|
default |
The default constructor; expect value and unit to be uninitialized.
Referenced by operator*(), operator+(), operator-(), operator/(), and duds::data::operator/().
|
default |
A default copy constrcutor.
|
inline |
Constructs a new Quantity with the given values.
| v | The initial value. |
| u | The initlal unit. |
Definition at line 59 of file Quantity.hpp.
|
inline |
Constructs a new Quantity holding the number of seconds stored in the given duration.
| Duration | A time duration class related to std::chrono::duration. |
| d | The duration. |
Definition at line 67 of file Quantity.hpp.
|
inline |
Compares two quantities for inequality.
Definition at line 171 of file Quantity.hpp.
Multiplies two quantities; the units are also multiplied.
| BadUnitExponent | The resulting units cannot be represented. |
Definition at line 86 of file Quantity.hpp.
|
inline |
Multiplies a Quantity by a scalar.
Definition at line 92 of file Quantity.hpp.
Multiplies two quantities; the units are also multiplied.
| BadUnitExponent | The resulting units cannot be represented. |
Definition at line 44 of file Quantity.cpp.
Referenced by operator/().
|
inline |
Multiplies a Quantity by a scalar.
Definition at line 126 of file Quantity.hpp.
Adds two quantities; they must use the same units.
| UnitMismatch | The quantities are for different units. |
Definition at line 14 of file Quantity.cpp.
Referenced by Quantity().
Adds two quantities; they must use the same units.
| UnitMismatch | The quantities are for different units. |
Definition at line 28 of file Quantity.cpp.
Referenced by operator/().
Subtracts a quantity from another; they must use the same units.
| UnitMismatch | The quantities are for different units. |
Definition at line 21 of file Quantity.cpp.
Referenced by Quantity().
Subtracts a quantity from another; they must use the same units.
| UnitMismatch | The quantities are for different units. |
Definition at line 36 of file Quantity.cpp.
Referenced by operator/().
Divides a quantity by another; the units are also divided.
| BadUnitExponent | The resulting units cannot be represented. |
Definition at line 99 of file Quantity.hpp.
|
inline |
Divides a Quantity by a scalar.
Definition at line 105 of file Quantity.hpp.
Divides a quantity by another; the units are also divided.
| BadUnitExponent | The resulting units cannot be represented. |
Definition at line 50 of file Quantity.cpp.
Referenced by operator*=().
|
inline |
Divides a Quantity by a scalar.
Definition at line 138 of file Quantity.hpp.
| bool duds::data::Quantity::operator< | ( | const Quantity & | q | ) | const |
Compares two quantities of the same units.
| UnitMismatch | The quantities are for different units. |
Definition at line 56 of file Quantity.cpp.
Referenced by operator/=().
| bool duds::data::Quantity::operator<= | ( | const Quantity & | q | ) | const |
Compares two quantities of the same units.
| UnitMismatch | The quantities are for different units. |
Definition at line 70 of file Quantity.cpp.
Referenced by operator/=().
|
inline |
Compares two quantities for equality.
Definition at line 165 of file Quantity.hpp.
| bool duds::data::Quantity::operator> | ( | const Quantity & | q | ) | const |
Compares two quantities of the same units.
| UnitMismatch | The quantities are for different units. |
Definition at line 63 of file Quantity.cpp.
Referenced by operator/=().
| bool duds::data::Quantity::operator>= | ( | const Quantity & | q | ) | const |
Compares two quantities of the same units.
| UnitMismatch | The quantities are for different units. |
Definition at line 77 of file Quantity.cpp.
Referenced by operator/=().
|
inlineprivate |
Definition at line 216 of file Quantity.hpp.
|
inline |
Sets a duration to the seconds stored in this quantity.
| Duration | The duration type. It must be usable in the same manner as std::chrono::duration. |
| d | The duration object to set. The value will be converted to the units used by the duration type. |
| UnitBadConversion | The quantity value is not in seconds. |
Definition at line 184 of file Quantity.hpp.
Referenced by duds::data::GenericValueDurationVisitor< IST >::operator()().
|
inline |
Returns a duration with the seconds stored in this quantity.
| Duration | The duration type. It must be usable in the same manner as std::chrono::duration. |
| UnitBadConversion | The quantity value is not in seconds. |
Definition at line 203 of file Quantity.hpp.
|
friend |
Definition at line 214 of file Quantity.hpp.
| Unit duds::data::Quantity::unit |
The units describing the value.
Definition at line 45 of file Quantity.hpp.
Referenced by duds::hardware::devices::instruments::LSM9DS1AccelGyro::accelerometerQuantity(), operator!=(), duds::data::GenericValueDurationVisitor< IST >::operator()(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), duds::data::operator/(), operator/=(), operator<(), operator<=(), operator==(), operator>(), and operator>=().
| double duds::data::Quantity::value |
Some value; probably something measured.
Definition at line 41 of file Quantity.hpp.
Referenced by operator!=(), duds::data::GenericValueNumericVisitor< N >::operator()(), duds::data::GenericValueStringVisitor::operator()(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), duds::data::operator/(), operator/=(), operator<(), operator<=(), operator==(), operator>(), and operator>=().