13 #include <boost/serialization/nvp.hpp> 14 #include <boost/exception/exception.hpp> 15 #include <boost/exception/info.hpp> 20 namespace duds {
namespace data {
28 struct UnitError :
virtual std::exception,
virtual boost::exception { };
45 typedef boost::error_info<struct Info_unitname, std::string>
BadUnit;
186 friend class boost::serialization::access;
194 a & BOOST_SERIALIZATION_NVP(u);
220 constexpr
Unit(std::int32_t U) : u(U) { }
235 Unit(
int A,
int cd,
int K,
int kg,
int m,
int mol,
int s,
236 int rad = 0,
int sr = 0);
241 return SignExtend<4>(u & 0xF);
247 return SignExtend<4>((u & 0xF0) >> 4);
253 return SignExtend<4>((u & 0xF00) >> 8);
259 return SignExtend<4>((u & 0xF000) >> 12);
265 return SignExtend<4>((u & 0xF0000) >> 16);
271 return SignExtend<4>((u & 0xF00000) >> 20);
277 return SignExtend<4>((u & 0xF000000) >> 24);
283 return SignExtend<2>((u & 0x30000000) >> 28);
289 return SignExtend<2>((u & 0xC0000000) >> 30);
363 u = (u & 0xFFFFFFF0) | (e & 0xF);
371 u = (u & 0xFFFFFF0F) | ((e & 0xF) << 4);
379 u = (u & 0xFFFFF0FF) | ((e & 0xF) << 8);
387 u = (u & 0xFFFF0FFF) | ((e & 0xF) << 12);
395 u = (u & 0xFFF0FFFF) | ((e & 0xF) << 16);
403 u = (u & 0xFF0FFFFF) | ((e & 0xF) << 20);
411 u = (u & 0xF0FFFFFF) | ((e & 0xF) << 24);
418 u = (u & 0xCFFFFFFF) | ((e & 0x3) << 28);
425 u = (u & 0x3FFFFFFF) | ((e & 0x3) << 30);
518 void setAmpere(
int e);
524 void setCandela(
int e);
530 void setKelvin(
int e);
536 void setKilogram(
int e);
542 void setMeter(
int e);
554 void setSecond(
int e);
560 void setRadian(
int e);
566 void setSteradian(
int e);
625 bool operator < (
const Unit &U)
const {
631 bool operator > (
const Unit &U)
const {
637 bool operator <= (
const Unit &U)
const {
643 bool operator >= (
const Unit &U)
const {
678 #define DUDS_UNIT_VALUE(A, cd, K, kg, m, mol, s, rad, sr) \ 679 (((A) & 0xF) | (((cd) & 0xF) << 4) | (((K) & 0xF) << 8) | \ 680 (((kg) & 0xF) << 12) | (((m) & 0xF) << 16) | (((mol) & 0xF) << 20) | \ 681 (((s) & 0xF) << 24) | (((rad) & 3) << 28) | (((sr) & 3) << 30)) 683 #endif // #ifndef UNIT_HPP void clear()
Makes the Unit unitless.
void mol(int e)
Sets the exponent for the mole (amount of substance) dimension without range checking.
Indicates that a value is beyond the range allowed by the Unit or ExtendedUnit class.
int cd() const
Returns the exponent for the candela (luminous intensity) dimension.
int ampere() const
Returns the exponent for the ampere (current) dimension.
void candela(int e)
Sets the exponent for the candela (luminous intensity) dimension without range checking.
int m() const
Returns the exponent for the meter (distance) dimension.
void serialize(A &a, const unsigned int)
Serialize the unit data.
constexpr bool operator==(const DigitalPinCap &cap, const DigitalPinCap::Flags &flg)
int rad() const
Returns the exponent for radians (angle).
int second() const
Returns the exponent for the second (time) dimension.
int kilogram() const
Returns the exponent for the kilogram (mass) dimension.
int steradian() const
Returns the exponent for steradians (solid angle).
int sr() const
Returns the exponent for steradians (solid angle).
Indicates that two different Unit objects were used in an operation that requires identical Unit obje...
void amp(int e)
Sets the exponent for the ampere (current) dimension without range checking.
void setAmp(int e)
Sets the exponent for the ampere (current) dimension.
int radian() const
Returns the exponent for radians (angle).
std::int32_t value() const
Returns the internal exponent fields.
int meter() const
Returns the exponent for the meter (distance) dimension.
void s(int e)
Sets the exponent for the second (time) dimension without range checking.
void kelvin(int e)
Sets the exponent for the kelvin (thermodynamic temperature) dimension without range checking...
int mol() const
Returns the exponent for the mole (amount of substance) dimension.
int K() const
Returns the exponent for the kelvin (thermodynamic temperature) dimension.
void steradian(int e)
Sets the exponent for steradians (solid angle) without range checking.
constexpr bool operator!=(const DigitalPinCap &cap, const DigitalPinCap::Flags &flg)
void meter(int e)
Sets the exponent for the meter (distance) dimension without range checking.
int amp() const
Returns the exponent for the ampere (current) dimension.
int kg() const
Returns the exponent for the kilogram (mass) dimension.
Represents an SI unit, either base or derived.
void kg(int e)
Sets the exponent for the kilogram (mass) dimension without range checking.
boost::error_info< struct Info_unitname, std::string > BadUnit
The name of the bad unit.
A conversion between units was attempted that cannot be performed.
void metre(int e)
Sets the exponent for the meter (distance) dimension without range checking.
boost::error_info< struct Info_unitexp, int > BadUnitExponent
The out-of-range exponent.
void m(int e)
Sets the exponent for the meter (distance) dimension without range checking.
void second(int e)
Sets the exponent for the second (time) dimension without range checking.
Quantity operator*(double s, const Quantity &q)
Multiplies a Quantity by a scalar.
void K(int e)
Sets the exponent for the kelvin (thermodynamic temperature) dimension without range checking...
int kelvin() const
Returns the exponent for the kelvin (thermodynamic temperature) dimension.
void A(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.
void mole(int e)
Sets the exponent for the mole (amount of substance) dimension without range checking.
std::make_signed< T >::type SignExtend(const T x)
Performs a sign extention operation.
void sr(int e)
Sets the exponent for steradians (solid angle) without range checking.
int metre() const
Returns the exponent for the meter (distance) dimension.
int A() const
Returns the exponent for the ampere (current) dimension.
void cd(int e)
Sets the exponent for the candela (luminous intensity) dimension without range checking.
void ampere(int e)
Sets the exponent for the ampere (current) dimension without range checking.
int candela() const
Returns the exponent for the candela (luminous intensity) dimension.
void rad(int e)
Sets the exponent for radians (angle) without range checking.
bool unitless() const
Returns true if the Unit represents no units.
std::int32_t u
Stores the exponent fields.
void setMetre(int e)
Sets the exponent for the meter (distance) dimension.
void radian(int e)
Sets the exponent for radians (angle) without range checking.
int s() const
Returns the exponent for the second (time) dimension.
void kilogram(int e)
Sets the exponent for the ampere (current)kilogram (mass) dimension without range checking...
constexpr Unit(std::int32_t U)
Make a new Unit set to a specific unit value; intended for making common unit constants with DUDS_UNI...
Quantity operator/(double s, const Quantity &q)
Divides a Quantity by a scalar.
A general unit related error.