![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
|
Unit conversion class. More...
#include <FXUnits.h>
Public Types | |
| enum | { GRAM, METER, AMPERE, CANDELA, MOLE, RADIAN, STERADIAN, SECOND, KELVIN, CELSIUS, FAHRENHEIT, RANKINE } |
| enum | { NumUnits =133 } |
Public Member Functions | |
| FXUnits () | |
| Initialize to identity. | |
| FXUnits (FXdouble mm, FXdouble aa=0.0) | |
| Initialize only with scale. | |
| FXUnits (const FXUnits &org) | |
| Copy from other units. | |
| operator FXbool () const | |
| Check if non-empty. | |
| FXUnits & | operator= (const FXUnits &org) |
| Assign from other units. | |
| FXdouble | operator() (FXdouble x) const |
| Convert number x according to transformation. | |
| FXUnits | invert () const |
| Return the transformation. | |
Static Public Member Functions | |
| static FXint | lookup (const FXchar *unit) |
| Look up unit; return -1 if not found. | |
| static FXint | lookup (const FXString &unit) |
| static FXint | span (const FXchar *unit) |
| Return number of characters consumed from unit-string. | |
| static FXint | span (const FXString &unit) |
| static FXulong | dimensions (const FXchar *unit) |
| Return dimension-description from a unit-string. | |
| static FXulong | dimensions (const FXString &unit) |
| static FXString | canonical (FXulong dims) |
| Return canonical (S.I.) unit-string from dimension-description. | |
| static FXUnits | convertFromTo (const FXchar *srcUnit, const FXchar *dstUnit=nullptr) |
| Convert from source unit to destination unit; default is convert to S.I. | |
| static FXUnits | convertFromTo (const FXString &srcUnit, const FXchar *dstUnit=nullptr) |
| static FXUnits | convertFromTo (const FXchar *srcUnit, const FXString &dstUnit) |
| static FXUnits | convertFromTo (const FXString &srcUnit, const FXString &dstUnit) |
| static FXUnits | convertToFrom (const FXchar *dstUnit, const FXchar *srcUnit=nullptr) |
| Convert to destination unit from source unit; default is convert from S.I. | |
| static FXUnits | convertToFrom (const FXString &dstUnit, const FXchar *srcUnit=nullptr) |
| static FXUnits | convertToFrom (const FXchar *dstUnit, const FXString &srcUnit) |
| static FXUnits | convertToFrom (const FXString &dstUnit, const FXString &srcUnit) |
| static FXUnits | convertFromToDims (const FXchar *srcUnit, FXulong dims) |
| Convert from source units to S.I., checking dimension-description. | |
| static FXUnits | convertFromToDims (const FXString &srcUnit, FXulong dims) |
| static FXUnits | convertToFromDims (const FXchar *dstUnit, FXulong dims) |
| Convert to destimation units from S.I., checking dimension-description. | |
| static FXUnits | convertToFromDims (const FXString &dstUnit, FXulong dims) |
Static Public Attributes | |
| static const FXchar | symbol [NumUnits][8] |
| List of unit names. | |
| static const FXdouble | factor [NumUnits] |
| List of conversion factors. | |
| static const FXchar | expression [NumUnits][16] |
| Unit sub-expression for non-basic units; for basic units, this would be empty string. More... | |
Unit conversion class.
Convert from any unit to any other unit, via intermediate S.I. unit representation. There are 9 basic units in the S.I. system (kg,m,A,cd,mol,rad,sr,s,K). We have a lot of derived units, which can be expressed in either other derived units or, eventually, into a collection of the base units. The derived units are described in terms of unit sub-expressions. To ensure unit-dimensions are correct when setting up a conversion, this class supports a so-called dimension-vector; currently, implemented as a single 64-bit integer number which encodes a combination of the base units. This dimension-vector is calculated for both source-unit and destination-unit, and then compared; if there is no match, then an error is detected (the FXUnits object returned is empty).
In order to bulk-transform numbers from one unit to another, the operator needs to perform only a single multiply and add (hopefully, your compiler will turn this into a FMA (Fused-Multiply-Add), making it a single instruction only).
Temperature scale is the only one that needs an offset; this offset only applies for temperature units that are "pure temperature", i.e. no other units in the mix, and no other powers than 1.
Scaling prefixes (y,z,a,f,p,n,μ,u,m,c,d,h,k,M,G,T,P,E,Z,Y), these are incorporated into the conversion automatically, like "1.21GW".
|
static |
Unit sub-expression for non-basic units; for basic units, this would be empty string.
|
|