10 #ifndef EXTENDEDUNIT_HPP 11 #define EXTENDEDUNIT_HPP 15 #include <boost/serialization/split_member.hpp> 17 namespace duds {
namespace data {
64 void save(
A &a,
const unsigned int)
const {
65 a & BOOST_SERIALIZATION_NVP(unit);
70 a & BOOST_SERIALIZATION_NVP(packed);
73 void load(
A &a,
const unsigned int) {
74 a & BOOST_SERIALIZATION_NVP(unit);
76 a & BOOST_SERIALIZATION_NVP(packed);
80 mant = packed & 0xFFFFF;
81 exp = (packed >> 20) & 0x7F;
82 sign = (packed >> 27) & 1;
119 template <
typename O>
121 if ((s > 7) || (s < -8)) {
601 template <
class Q =
double>
607 friend class boost::serialization::access;
610 a & BOOST_SERIALIZATION_NVP(value);
611 a & BOOST_SERIALIZATION_NVP(unit);
617 #endif // #ifndef EXTENDEDUNIT_HPP
Indicates that a value is beyond the range allowed by the Unit or ExtendedUnit class.
void setSteradian(int e)
Sets the exponent for steradians (solid angle).
int ampere() const
Returns the exponent for the ampere (current) dimension.
int m() const
Returns the exponent for the meter (distance) dimension.
void setKilogram(int e)
Sets the exponent for the kilogram (mass) dimension.
ExtendedUnit()=default
Makes an uninitialized ExtendedUnit.
ExtendedUnit & operator*=(const Unit &U)
Combines two units into a new unit.
int cd() const
Returns the exponent for the candela (luminous intensity) dimension.
void setKelvin(int e)
Sets the exponent for the kelvin (thermodynamic temperature) dimension.
void kelvin(int e)
Sets the exponent for the kelvin (thermodynamic temperature) dimension without range checking...
bool operator>=(const ExtendedUnit &U) const
Unit objects are compared using the u member.
void s(int e)
Sets the exponent for the second (time) dimension without range checking.
int second() const
Returns the exponent for the second (time) dimension.
void setSteradian(int e)
Sets the exponent for steradians (solid angle).
int kilogram() const
Returns the exponent for the kilogram (mass) dimension.
int steradian() const
Returns the exponent for steradians (solid angle).
void setMole(int e)
Sets the exponent for the mole (amount of substance) dimension.
void m(int e)
Sets the exponent for the meter (distance) dimension without range checking.
void setKilogram(int e)
Sets the exponent for the kilogram (mass) dimension.
ExtendedUnit & operator=(const Unit &U)
Makes this extended unit equivalent to the given Unit object.
bool canConvertToUnit() const
True if the unit represented by this object can also be represented by a Unit object.
const ExtendedUnit operator*(const Unit &U) const
Combines two units into a new unit.
void setSecond(int e)
Sets the exponent for the second (time) dimension.
bool operator<=(const ExtendedUnit &U) const
Unit objects are compared using the u member.
int scale
A value used to represnt most SI prefixes.
constexpr ExtendedUnit(Unit u, std::uint32_t s)
An simple internal constructor that takes the values of it members.
int kilogram() const
Returns the exponent for the kilogram (mass) dimension.
int kg() const
Returns the exponent for the kilogram (mass) dimension.
int radian() const
Returns the exponent for radians (angle).
int kelvin() const
Returns the exponent for the kelvin (thermodynamic temperature) dimension.
void setMetre(int e)
Sets the exponent for the meter (distance) dimension.
unsigned int mant
The mantissa, save for the impled leading bit.
void setAmp(int e)
Sets the exponent for the ampere (current) dimension.
int meter() const
Returns the exponent for the meter (distance) dimension.
int radian() const
Returns the exponent for radians (angle).
constexpr ExtendedUnit(Unit u)
Makes an ExtendedUnit that is equivalent to the given base Unit.
void setCandela(int e)
Sets the exponent for the candela (luminous intensity) dimension.
void setAmpere(int e)
Sets the exponent for the ampere (current) dimension.
int second() const
Returns the exponent for the second (time) dimension.
void cd(int e)
Sets the exponent for the candela (luminous intensity) dimension without range checking.
int mol() const
Returns the exponent for the mole (amount of substance) dimension.
const ExtendedUnit operator/(const Unit &U) const
Combines two units into a new unit.
int ampere() const
Returns the exponent for the ampere (current) dimension.
void setKelvin(int e)
Sets the exponent for the kelvin (thermodynamic temperature) dimension.
bool operator>(const ExtendedUnit &U) const
Unit objects are compared using the u member.
Represents an SI unit, either base or derived.
void setAmpere(int e)
Sets the exponent for the ampere (current) dimension.
int steradian() const
Returns the exponent for steradians (solid angle).
void K(int e)
Sets the exponent for the kelvin (thermodynamic temperature) dimension without range checking...
bool unitless() const
Returns true if the object represents no units.
void setMeter(int e)
Sets the exponent for the meter (distance) dimension.
const Unit & base() const
Returns the base unit as a Unit object.
ExtendedUnit(Unit u, O o, int s)
Constructs an ExtendedUnit with the given values.
void radian(int e)
Sets the exponent for radians (angle) without range checking.
ExtendedUnit & operator/=(const Unit &U)
Combines two units into a new unit.
int mole() const
Returns the exponent for the mole (amount of substance) dimension.
int A() const
Returns the exponent for the ampere (current) dimension.
int sr() const
Returns the exponent for steradians (solid angle).
void candela(int e)
Sets the exponent for the candela (luminous intensity) dimension without range checking.
void save(A &a, const unsigned int) const
int meter() const
Returns the exponent for the meter (distance) dimension.
friend class boost::serialization::access
int kelvin() const
Returns the exponent for the kelvin (thermodynamic temperature) dimension.
void mol(int e)
Sets the exponent for the mole (amount of substance) dimension without range checking.
redo: Use floats for scale and offset.
int K() const
Returns the exponent for the kelvin (thermodynamic temperature) dimension.
int amp() const
Returns the exponent for the ampere (current) dimension.
An idea that is not yet implemented; DO NOT USE.
void ampere(int e)
Sets the exponent for the ampere (current) dimension without range checking.
int mole() const
Returns the exponent for the mole (amount of substance) dimension.
bool operator==(const ExtendedUnit &U) const
Unit objects are compared using the u member.
float offsetf() const
Query the offset as a float.
void sr(int e)
Sets the exponent for steradians (solid angle) without range checking.
int s() const
Returns the exponent for the second (time) dimension.
void setMeter(int e)
Sets the exponent for the meter (distance) dimension.
void setRadian(int e)
Sets the exponent for radians (angle).
void kg(int e)
Sets the exponent for the kilogram (mass) dimension without range checking.
bool operator<(const ExtendedUnit &U) const
Unit objects are compared using the u member.
int candela() const
Returns the exponent for the candela (luminous intensity) dimension.
void setSecond(int e)
Sets the exponent for the second (time) dimension.
void setMole(int e)
Sets the exponent for the mole (amount of substance) dimension.
void rad(int e)
Sets the exponent for radians (angle) without range checking.
void mole(int e)
Sets the exponent for the mole (amount of substance) dimension without range checking.
void serialize(A &a, const unsigned int)
int rad() const
Returns the exponent for radians (angle).
bool operator!=(const ExtendedUnit &U) const
Unit objects are compared using the u member.
void A(int e)
Sets the exponent for the ampere (current) dimension without range checking.
bool unitless() const
Returns true if the Unit represents no units.
void steradian(int e)
Sets the exponent for steradians (solid angle) without range checking.
int metre() const
Returns the exponent for the meter (distance) dimension.
int exp
The exponent as a signed integer rather than unsigned with bias.
BOOST_SERIALIZATION_SPLIT_MEMBER()
double offset() const
Query the offset as a double.
void setRadian(int e)
Sets the exponent for radians (angle).
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
void amp(int e)
Sets the exponent for the ampere (current) dimension without range checking.
void meter(int e)
Sets the exponent for the meter (distance) dimension without range checking.
int candela() const
Returns the exponent for the candela (luminous intensity) dimension.
void metre(int e)
Sets the exponent for the meter (distance) dimension without range checking.
std::uint32_t scaloff
A scaling and offset value packed into four bytes.
void setCandela(int e)
Sets the exponent for the candela (luminous intensity) dimension.
void kilogram(int e)
Sets the exponent for the ampere (current)kilogram (mass) dimension without range checking...
void second(int e)
Sets the exponent for the second (time) dimension without range checking.
void load(A &a, const unsigned int)