scifir-units 2.0.0
scifir-units is a library of units of measurement, angles, coordinates, fields, and related data, all lightweight, that help in the development of scientific software and scientific machines
|
Class that represents dimensions of the SI system of units. Each dimension sizes 6 bytes, 1 byte for the dimension type, 1 byte for the prefix, 1 byte for the position (which can be the NUMERATOR or the DENOMINATOR), and 3 bytes for the custom dimension (in case it's used one). A base dimension is a dimension that doesn't has more base dimensions, a derived dimension has always base dimensions from which it's defined. More...
#include <dimension.hpp>
Public Types | |
enum | type : int8_t { NONE , METRE , DEGREE , RADIAN , STERADIAN , SECOND , GRAM , COULOMB , KELVIN , CELSIUS , MOLE , CANDELA , BYTE , BIT , HERTZ , NEWTON , PASCAL , JOULE , WATT , AMPERE , VOLT , FARAD , OHM , SIEMENS , WEBER , TESLA , HENRY , LUMEN , LUX , BECQUEREL , GRAY , SIEVERT , KATAL , ANGSTROM , LITRE , MINUTE , HOUR , DAY , LIGHT_YEAR , ASTRONOMICAL_UNIT , PARSEC , ELECTRON_VOLT , DALTON , ATOMIC_MASS_UNIT , BARN , MOLARITY , PARTICLES , CUSTOM , CUSTOM_BASIC , CUSTOM_FULL_SYMBOL , MONEY , PIXEL , MEMO , INTERNATIONAL_UNIT , MILLIEQUIVALENT , DECIBEL } |
Represents a dimension of the SI system of units. All the dimensions of the SI system of units are supported. There are also dimensions supported that aren't considered yet part of the SI system of units, but that are widely used. More... | |
enum | position : int8_t { NO_POSITION , NUMERATOR , DENOMINATOR } |
Represents the position of the dimension, which can be at the numerator or at the denominator. The value NO_POSITION is used when there's no position specified. More... | |
Public Member Functions | |
dimension () | |
Default constructor. The dimension_type is NONE, the dimension_position is NO_POSITION, and the prefix is NONE, the symbol is empty. | |
dimension (const dimension &x) | |
Copy constructor. The dimension is initialized to be a copy of the dimension x. | |
dimension (dimension &&x) | |
Move constructor. The dimension is initialized with a move of the dimension x. | |
dimension (dimension::type new_dimension_type, scifir::prefix::type new_prefix, dimension::position new_position) | |
Constructor. The dimension is initialized to the dimension_type, the prefix type and the position given. | |
dimension (dimension::type new_dimension_type, const scifir::prefix &new_prefix, dimension::position new_position) | |
Constructor. The dimension is initialized to the dimension_type, the prefix and the position given. | |
dimension (const string &init_dimension, dimension::position new_position) | |
Constructor. The dimension is initialized with an initialization string of dimension and the position given. | |
dimension & | operator= (const dimension &x) |
Copy assignment. The dimension copies the dimension x. | |
dimension & | operator= (dimension &&x) |
Move assignment. The dimension values are all moved from the dimension x. | |
string | get_name () const |
Returns the name of the dimension. | |
string | get_fullname () const |
Returns the name of the dimension with the name of the prefix first. | |
string | get_plural () const |
Returns the plural of the dimension. | |
string | get_fullplural () const |
Returns the plural of the dimension with the name of the prefix first. | |
string | get_symbol () const |
Returns the symbol of the dimension. In the case of a custom dimension, it returns the custom dimension defined. | |
long double | get_conversion_factor () const |
Returns the conversion factor of the dimension. | |
long double | prefix_math () const |
Returns the math between the prefix and the dimension, which varies if the dimension is a B or another. In the case of bytes the math with the prefix is different, it's done with 1024 instead of multiples of 10. It doesn't includes the conversion factor of dimensions. | |
long double | prefix_math (const prefix &x_prefix) const |
Returns the math between some prefix and the dimension. The difference with the other prefix_math() function is that the prefix is given as parameter. | |
bool | is_simple_dimension () const |
If the dimension doesn't has more base dimensions, it's a simple dimension. | |
bool | is_composite_dimension () const |
If the dimension has more simple dimensions, it's a composite dimension. | |
bool | is_base_dimension () const |
Returns true if the dimension is a base dimension, which includes all base dimensions of the SI system of units, excepting AMPERE, which has been changed for COULOMB. Additional to the base dimensions of the SI system of units, they are considered base dimensions too RADIAN, STERADIAN, BYTE, MONEY, MEMO, and all CUSTOM_BASIC dimensions. | |
bool | is_derived_dimension () const |
If the dimension is not a base dimension, it's considered a derived dimension. | |
bool | is_SI_base_dimension () const |
Returns true if the dimension is a SI base dimension. Following the SI system of units, only are base dimensions the METRE, the GRAM, the SECOND, the AMPERE, the KELVIN, the MOLE and the CANDELA. | |
bool | is_SI_derived_dimension () const |
If the dimension is not a SI base dimension, it's considered a SI derived dimension. | |
bool | is_dimensionless () const |
If the dimension_type is DEGREE, RADIAN or STERADIAN, it's considered dimensionless, following the SI system of units. | |
vector< dimension > | get_base_dimensions () const |
Returns the base dimensions of the dimensions, which can be the same dimension or all the base dimension this dimension has, if it's a derived dimension. | |
void | invert () |
Changes the position of the dimension to the reverse, from the NUMERATOR to the DENOMINATOR, or from the DENOMINATOR to the NUMERATOR. | |
Static Public Member Functions | |
static void | create_custom_dimension (const string &new_symbol, const string &init_dimensions) |
Creates a new custom dimension, that's stored with its symbol, which is given as an string, and the base dimensions it has, if this custom dimension is not a new base dimension. | |
static char * | create_full_symbol (const string &full_symbol) |
Creates a new dimension that's stored in the private static map dimension::full_symbols. | |
static string | get_full_symbol (const char *x_symbol) |
Returns the symbol of a custom_full_symbol dimension stored in the private static map dimension::full_symbols. | |
Public Attributes | |
scifir::prefix | prefix |
The prefix of the dimension. It's used along with the symbol of the dimension when printing it. | |
dimension::type | dimension_type |
The type of the dimension. | |
dimension::position | dimension_position |
The position of the dimension, which can be the NUMERATOR, the DENOMINATOR or NO_POSITION. NO_POSITION means that the dimension is not ready to be used, and must be changed if the dimension is intended to be used. | |
char | symbol [3] |
The value of the position of the character of a custom dimension in the map of full_symbols. | |
Static Private Attributes | |
static map< string, vector< dimension > > | base_dimensions = map<string,vector<dimension>>() |
static map< int, string > | full_symbols = map<int,string>() |
static int | total_full_symbols = 0 |
static set< string > | prefixes_options {"Q", "R", "Y", "Z", "E", "P", "T", "G", "M", "k", "h", "d", "c", "m", "\u00B5", "u", "n", "p", "f", "a", "z", "y", "r", "q"} |
Class that represents dimensions of the SI system of units. Each dimension sizes 6 bytes, 1 byte for the dimension type, 1 byte for the prefix, 1 byte for the position (which can be the NUMERATOR or the DENOMINATOR), and 3 bytes for the custom dimension (in case it's used one). A base dimension is a dimension that doesn't has more base dimensions, a derived dimension has always base dimensions from which it's defined.
Definition at line 30 of file dimension.hpp.
Represents the position of the dimension, which can be at the numerator or at the denominator. The value NO_POSITION is used when there's no position specified.
Enumerator | |
---|---|
NO_POSITION | The dimension is not ready and yet being used. |
NUMERATOR | The dimension is at the numerator. |
DENOMINATOR | The dimension is at the denominator. |
Definition at line 38 of file dimension.hpp.
Represents a dimension of the SI system of units. All the dimensions of the SI system of units are supported. There are also dimensions supported that aren't considered yet part of the SI system of units, but that are widely used.
Definition at line 33 of file dimension.hpp.
dimension::dimension | ( | ) |
Default constructor. The dimension_type is NONE, the dimension_position is NO_POSITION, and the prefix is NONE, the symbol is empty.
Definition at line 27 of file dimension.cpp.
Copy constructor. The dimension is initialized to be a copy of the dimension x.
dimension::dimension | ( | dimension && | x | ) |
Move constructor. The dimension is initialized with a move of the dimension x.
|
explicit |
Constructor. The dimension is initialized to the dimension_type, the prefix type and the position given.
Definition at line 52 of file dimension.cpp.
|
explicit |
Constructor. The dimension is initialized to the dimension_type, the prefix and the position given.
Definition at line 55 of file dimension.cpp.
|
explicit |
Constructor. The dimension is initialized with an initialization string of dimension and the position given.
Definition at line 58 of file dimension.cpp.
|
inlinestatic |
Creates a new custom dimension, that's stored with its symbol, which is given as an string, and the base dimensions it has, if this custom dimension is not a new base dimension.
Definition at line 79 of file dimension.hpp.
Creates a new dimension that's stored in the private static map dimension::full_symbols.
Definition at line 87 of file dimension.hpp.
Returns the base dimensions of the dimensions, which can be the same dimension or all the base dimension this dimension has, if it's a derived dimension.
Definition at line 1396 of file dimension.cpp.
Returns the conversion factor of the dimension.
Definition at line 743 of file dimension.cpp.
Returns the symbol of a custom_full_symbol dimension stored in the private static map dimension::full_symbols.
Definition at line 145 of file dimension.hpp.
string dimension::get_fullname | ( | ) | const |
Returns the name of the dimension with the name of the prefix first.
Definition at line 478 of file dimension.cpp.
string dimension::get_fullplural | ( | ) | const |
Returns the plural of the dimension with the name of the prefix first.
Definition at line 603 of file dimension.cpp.
string dimension::get_name | ( | ) | const |
Returns the name of the dimension.
Definition at line 358 of file dimension.cpp.
string dimension::get_plural | ( | ) | const |
Returns the plural of the dimension.
Definition at line 483 of file dimension.cpp.
string dimension::get_symbol | ( | ) | const |
Returns the symbol of the dimension. In the case of a custom dimension, it returns the custom dimension defined.
Definition at line 608 of file dimension.cpp.
void dimension::invert | ( | ) |
Changes the position of the dimension to the reverse, from the NUMERATOR to the DENOMINATOR, or from the DENOMINATOR to the NUMERATOR.
Definition at line 1647 of file dimension.cpp.
bool dimension::is_base_dimension | ( | ) | const |
Returns true if the dimension is a base dimension, which includes all base dimensions of the SI system of units, excepting AMPERE, which has been changed for COULOMB. Additional to the base dimensions of the SI system of units, they are considered base dimensions too RADIAN, STERADIAN, BYTE, MONEY, MEMO, and all CUSTOM_BASIC dimensions.
Definition at line 1012 of file dimension.cpp.
bool dimension::is_composite_dimension | ( | ) | const |
If the dimension has more simple dimensions, it's a composite dimension.
Definition at line 1000 of file dimension.cpp.
bool dimension::is_derived_dimension | ( | ) | const |
If the dimension is not a base dimension, it's considered a derived dimension.
Definition at line 1132 of file dimension.cpp.
bool dimension::is_dimensionless | ( | ) | const |
If the dimension_type is DEGREE, RADIAN or STERADIAN, it's considered dimensionless, following the SI system of units.
Definition at line 1384 of file dimension.cpp.
bool dimension::is_SI_base_dimension | ( | ) | const |
Returns true if the dimension is a SI base dimension. Following the SI system of units, only are base dimensions the METRE, the GRAM, the SECOND, the AMPERE, the KELVIN, the MOLE and the CANDELA.
Definition at line 1144 of file dimension.cpp.
bool dimension::is_SI_derived_dimension | ( | ) | const |
If the dimension is not a SI base dimension, it's considered a SI derived dimension.
Definition at line 1264 of file dimension.cpp.
bool dimension::is_simple_dimension | ( | ) | const |
If the dimension doesn't has more base dimensions, it's a simple dimension.
Definition at line 880 of file dimension.cpp.
Copy assignment. The dimension copies the dimension x.
Move assignment. The dimension values are all moved from the dimension x.
Returns the math between the prefix and the dimension, which varies if the dimension is a B or another. In the case of bytes the math with the prefix is different, it's done with 1024 instead of multiples of 10. It doesn't includes the conversion factor of dimensions.
Definition at line 863 of file dimension.cpp.
Returns the math between some prefix and the dimension. The difference with the other prefix_math() function is that the prefix is given as parameter.
Definition at line 868 of file dimension.cpp.
|
staticprivate |
Definition at line 167 of file dimension.hpp.
dimension::position dimension::dimension_position |
The position of the dimension, which can be the NUMERATOR, the DENOMINATOR or NO_POSITION. NO_POSITION means that the dimension is not ready to be used, and must be changed if the dimension is intended to be used.
Definition at line 76 of file dimension.hpp.
dimension::type dimension::dimension_type |
The type of the dimension.
Definition at line 75 of file dimension.hpp.
Definition at line 168 of file dimension.hpp.
scifir::prefix dimension::prefix |
The prefix of the dimension. It's used along with the symbol of the dimension when printing it.
Definition at line 74 of file dimension.hpp.
|
staticprivate |
Definition at line 170 of file dimension.hpp.
char dimension::symbol[3] |
The value of the position of the character of a custom dimension in the map of full_symbols.
Definition at line 77 of file dimension.hpp.
|
staticprivate |
Definition at line 169 of file dimension.hpp.