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
Loading...
Searching...
No Matches
dimension.hpp
Go to the documentation of this file.
1#ifndef SCIFIR_UNITS_UNITS_DIMENSION_HPP_INCLUDED
2#define SCIFIR_UNITS_UNITS_DIMENSION_HPP_INCLUDED
3
4#include "./prefix.hpp"
5
6#include "boost/algorithm/string.hpp"
7
8#include "unicode/uchar.h"
9
10#include <algorithm>
11#include <cstring>
12#include <cstddef>
13#include <cmath>
14#include <iostream>
15#include <map>
16#include <set>
17#include <sstream>
18#include <string>
19#include <vector>
20
21using namespace std;
22
23namespace scifir
24{
25 class dimension;
26
27 vector<dimension> create_dimensions(string init_dimensions);
28 vector<dimension> create_base_dimensions(const string& init_dimensions);
29
31 {
32 public:
37
39
40 dimension();
46
49
50 string get_name() const;
51 string get_fullname() const;
52 string get_plural() const;
53 string get_fullplural() const;
54 string get_symbol() const;
55 long double get_conversion_factor() const;
56 long double prefix_math() const;
57 long double prefix_math(const prefix& x_prefix) const;
58
59 bool is_simple_dimension() const;
60 bool is_composite_dimension() const;
61
62 bool is_base_dimension() const;
63 bool is_derived_dimension() const;
64
65 bool is_SI_base_dimension() const;
66 bool is_SI_derived_dimension() const;
67
68 bool is_dimensionless() const;
69
71
72 void invert();
73
77 char symbol[3];
78
86
87 static char* create_full_symbol(const string& full_symbol)
88 {
89 char symbol_abbreviation[3] = "";
91 if (total_full_symbols <= 255)
92 {
93 if (total_full_symbols <= 32)
94 {
96 }
98 symbol_abbreviation[1] = '\n';
99 symbol_abbreviation[2] = '\n';
100 }
101 else if (total_full_symbols <= 65535)
102 {
103 int char_code1 = (total_full_symbols / 256);
104 if (char_code1 <= 32)
105 {
106 char_code1 = 33;
107 }
109 int closest_number = int(floor(total_full_symbols / 256.0)) * 256;
111 if (char_code2 <= 32)
112 {
113 char_code2 = 33;
114 }
116 symbol_abbreviation[2] = '\n';
117 }
118 else
119 {
120 int char_code1 = (total_full_symbols / 65536);
121 if (char_code1 <= 32)
122 {
123 char_code1 = 33;
124 }
126 int closest_number = int(floor(total_full_symbols / 65536.0)) * 65536;
128 if (char_code2 <= 32)
129 {
130 char_code2 = 33;
131 }
133 int closest_number2 = int(floor(total_full_symbols / 256.0)) * 256;
135 if (char_code3 <= 32)
136 {
137 char_code3 = 33;
138 }
140 }
143 }
144
145 static string get_full_symbol(const char* x_symbol)
146 {
147 int symbol_code;
148 if (x_symbol[1] == '\n')
149 {
151 }
152 else if (x_symbol[2] == '\n')
153 {
154 symbol_code = int(x_symbol[0]) * 256;
155 symbol_code += int(x_symbol[1]);
156 }
157 else
158 {
159 symbol_code = int(x_symbol[0]) * 65536;
160 symbol_code += int(x_symbol[1]) * 256;
161 symbol_code += int(x_symbol[2]);
162 }
164 }
165
166 private:
171 };
172
173 string to_string(const dimension& x);
174 string to_string(const vector<dimension>& x_dimensions,bool with_brackets = false);
175
176 string to_latex(const vector<dimension>& x_dimensions,bool with_brackets = false);
177
180
184 vector<dimension> square_dimensions(vector<dimension> x,int index,long double& value);
186
188 vector<dimension> normalize_dimensions(const vector<dimension>& x,long double& value);
189
190 bool is_dimension_char(const UChar32& x);
191
192 bool common_dimension(const dimension& x,const dimension& y);
193 bool equal_dimensions(const string& init_dimensions_x,const string& init_dimensions_y);
196
197 /*constexpr bool is_dimensions(const char* x)
198 {
199 return true;
200 }*/
201}
202
203bool operator ==(const scifir::dimension& x,const scifir::dimension& y);
204bool operator !=(const scifir::dimension& x,const scifir::dimension& y);
205
206ostream& operator <<(ostream& os, const scifir::dimension& x);
207
208#endif // SCIFIR_UNITS_UNITS_DIMENSION_HPP_INCLUDED
Class that represents dimensions of the SI system of units. Each dimension sizes 6 bytes,...
Definition dimension.hpp:31
bool is_dimensionless() const
If the dimension_type is DEGREE, RADIAN or STERADIAN, it's considered dimensionless,...
position
Represents the position of the dimension, which can be at the numerator or at the denominator....
Definition dimension.hpp:38
@ DENOMINATOR
The dimension is at the denominator.
Definition dimension.hpp:38
@ NO_POSITION
The dimension is not ready and yet being used.
Definition dimension.hpp:38
@ NUMERATOR
The dimension is at the numerator.
Definition dimension.hpp:38
dimension & operator=(const dimension &x)
Copy assignment. The dimension copies the dimension x.
string get_fullplural() const
Returns the plural of the dimension with the name of the prefix first.
bool is_composite_dimension() const
If the dimension has more simple dimensions, it's a composite dimension.
string get_name() const
Returns the name of the dimension.
scifir::prefix prefix
The prefix of the dimension. It's used along with the symbol of the dimension when printing it.
Definition dimension.hpp:74
dimension::position dimension_position
The position of the dimension, which can be the NUMERATOR, the DENOMINATOR or NO_POSITION....
Definition dimension.hpp:76
bool is_base_dimension() const
Returns true if the dimension is a base dimension, which includes all base dimensions of the SI syste...
char symbol[3]
The value of the position of the character of a custom dimension in the map of full_symbols.
Definition dimension.hpp:77
string get_fullname() const
Returns the name of the dimension with the name of the prefix first.
bool is_SI_derived_dimension() const
If the dimension is not a SI base dimension, it's considered a SI derived dimension.
static int total_full_symbols
dimension::type dimension_type
The type of the dimension.
Definition dimension.hpp:75
static map< string, vector< dimension > > base_dimensions
dimension(dimension &&x)
Move constructor. The dimension is initialized with a move of the dimension x.
bool is_SI_base_dimension() const
Returns true if the dimension is a SI base dimension. Following the SI system of units,...
bool is_simple_dimension() const
If the dimension doesn't has more base dimensions, it's a simple dimension.
type
Represents a dimension of the SI system of units. All the dimensions of the SI system of units are su...
Definition dimension.hpp:34
@ MOLARITY
Molarity, plural molarities. The derived dimensions are mol / L. Dimension of concentration of a chem...
Definition dimension.hpp:35
@ NONE
No dimension. Default value for the default constructor.
Definition dimension.hpp:35
@ BECQUEREL
Becquerel, plural becquerels. The derived dimensions are 1 / s. Dimension of radioactivity....
Definition dimension.hpp:35
@ KATAL
Katal, plural katals. The derived dimensions are mol / s. Dimension of catalytic activity....
Definition dimension.hpp:35
@ LITRE
Litre, plural litres. The derived dimensions are dm3. Dimension of volume. Symbol L.
Definition dimension.hpp:35
@ LUMEN
Lumen, plural lumens. The derived dimensions are cd * sr Dimension of luminous flux....
Definition dimension.hpp:35
@ MEMO
Memo, plural memos. Invented unit inside Scifir, it's not part of the SI system of units....
Definition dimension.hpp:35
@ STERADIAN
Steradian, plural steradians. Dimension of solid angle. A solid angle is an angle in volume....
Definition dimension.hpp:35
@ TESLA
Tesla, plural teslas. The derived dimensions are V * s / m2. Dimension of magnetic strength....
Definition dimension.hpp:35
@ INTERNATIONAL_UNIT
International unit, plural international units. It measures the amount of effect or biological activi...
Definition dimension.hpp:35
@ BARN
Barn, plural barns. Dimension of area. The derived dimensions are 10^-28 m2. It's used inside nuclear...
Definition dimension.hpp:35
@ LIGHT_YEAR
Light year, plural light years. Dimension of length. The derived dimensions are 9,...
Definition dimension.hpp:35
@ HENRY
Henry, plural henries. The derived dimensions are V * s / A. Dimension of electric inductance....
Definition dimension.hpp:35
@ AMPERE
Ampere, plural amperes. The derived dimensions are C / s. Dimension of electric current....
Definition dimension.hpp:35
@ MOLE
Mole, plural moles. SI dimension of quantity. Symbol mol.
Definition dimension.hpp:35
@ CUSTOM_FULL_SYMBOL
Custom dimension. It's identical to a CUSTOM dimension in his use, but its symbol is stored in the st...
Definition dimension.hpp:35
@ VOLT
Volt, plural volts. The derived dimensions are J / C, W / A. Dimension of voltage....
Definition dimension.hpp:35
@ OHM
Ohm, plural ohms. The derived dimensions are V / A. Dimension of electric resistance....
Definition dimension.hpp:35
@ COULOMB
Coulomb, plural coulombs. SI dimension of charge. Special name. Symbol C.
Definition dimension.hpp:35
@ LUX
Lux, plural luxes. The derived dimensions are cd * sr / m2. Dimension of illuminance....
Definition dimension.hpp:35
@ GRAY
Gray, plural grays. The derived dimensions are m2 / s2. Dimension of ionising radiation (absorbed dos...
Definition dimension.hpp:35
@ ANGSTROM
Ángstrom, plural angstroms. The derived dimensions are 10^-10 m. Dimension of length,...
Definition dimension.hpp:35
@ ELECTRON_VOLT
Electron volt, plural electron volts. The derived dimensions are 1.602176634 * 10^−19 J....
Definition dimension.hpp:35
@ GRAM
Gram, plural grams. SI dimension of mass. Symbol g.
Definition dimension.hpp:35
@ SIEVERT
Sievert, plural sieverts. The derived dimensions are J / kg. Dimension of ionising radiation (equival...
Definition dimension.hpp:35
@ DALTON
Dalton, plural daltons. The derived dimensions are 1,66053886 * 10^-24. Dimension of mass....
Definition dimension.hpp:35
@ MILLIEQUIVALENT
Milliequivalent, plural Milliequivalents. Amount of moles in a given chemical reaction needed to reac...
Definition dimension.hpp:35
@ CELSIUS
Celsius, plural celsius. SI dimension of temperature, derived from kelvin. Symbol °C....
Definition dimension.hpp:35
@ DEGREE
Degree, plural degrees. Dimension of angle. Symbol θ.
Definition dimension.hpp:35
@ PASCAL
Pascal, plural pascals. The derived dimensions are kg / s2 * m. Dimension of pressure....
Definition dimension.hpp:35
@ PIXEL
Pixel, plural pixels. it represents the amount of pixels, it can be used as a replacemet of the metre...
Definition dimension.hpp:35
@ ATOMIC_MASS_UNIT
Atomic mass unit, plural atomic mass units. The derived dimensions are Da. Equivalent to the Dalton....
Definition dimension.hpp:35
@ ASTRONOMICAL_UNIT
Astronomical unit, plural astronomical units. Dimension of length. The derived dimensions are 149,...
Definition dimension.hpp:35
@ HERTZ
Hertz, plural hertz. The derived dimensions are 1 / s. Dimension of frequency. Special name....
Definition dimension.hpp:35
@ DAY
Day, plural days. The derived dimensions are 86,400 s. Dimension of time. Symbol day,...
Definition dimension.hpp:35
@ WATT
Watt, plural watts. The derived dimensions are kg * m2 / s3. Dimension of power. Special name....
Definition dimension.hpp:35
@ NEWTON
Newton, plural newtons. The derived dimensions are kg * m / s2. Dimension of force....
Definition dimension.hpp:35
@ HOUR
Hour, plural hours. The derived dimensions are 3,600 s. Dimension of time. Symbol hour,...
Definition dimension.hpp:35
@ PARTICLES
Total of particles, the total amount that the mole represents. It's not exactly a dimension,...
Definition dimension.hpp:35
@ MONEY
Money, plural money. The money is not specified in a specific currency, you must use the ISO 4217 of ...
Definition dimension.hpp:35
@ BIT
Bit, plural bits. Dimension of amount of information, of each binary digit. Symbol bit.
Definition dimension.hpp:35
@ SECOND
Second, plural seconds. SI dimension of time. Symbol s.
Definition dimension.hpp:35
@ MINUTE
Minute, plural minutes. The derived dimensions are 60 s. Dimension of time. Symbol min.
Definition dimension.hpp:35
@ CANDELA
Candela, plural candelas. SI dimension of luminous intensity. Symbol cd.
Definition dimension.hpp:35
@ RADIAN
Radian, plural radians. Dimension of angle. Special name. Symbol rad.
Definition dimension.hpp:35
@ BYTE
Byte, plural bytes. Dimension of amount of information. Symbol B.
Definition dimension.hpp:35
@ SIEMENS
Siemens, plural siemens. The derived dimensions are 1 / Ω. Dimension of electric conductance....
Definition dimension.hpp:35
@ JOULE
Joule, plural joules. The derived dimensions are kg * m2 / s2. Dimension of energy....
Definition dimension.hpp:35
@ FARAD
Farad, plural farads. The derived dimensions are A * s / V. Dimension of electric capacitance....
Definition dimension.hpp:35
@ WEBER
Weber, plural webers. The derived dimensions are T * m2. Dimension of magnetic flux....
Definition dimension.hpp:35
@ KELVIN
Kelvin, plural kelvins. SI dimension of temperature. Symbol K.
Definition dimension.hpp:35
@ METRE
Meter, plural meters. SI dimension of length. Symbol m.
Definition dimension.hpp:35
@ PARSEC
Parsec, plural parsecs. Dimension of length. The derived dimensions are 3.2616 ly....
Definition dimension.hpp:35
@ CUSTOM
Custom dimension. It means the dimension is a custom dimension, which can have any value and meaning,...
Definition dimension.hpp:35
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,...
Definition dimension.hpp:79
string get_symbol() const
Returns the symbol of the dimension. In the case of a custom dimension, it returns the custom dimensi...
string get_plural() const
Returns the plural of the dimension.
static set< string > prefixes_options
dimension(const dimension &x)
Copy constructor. The dimension is initialized to be a copy of the dimension x.
vector< dimension > get_base_dimensions() const
Returns the base dimensions of the dimensions, which can be the same dimension or all the base dimens...
long double get_conversion_factor() const
Returns the conversion factor of the dimension.
static map< int, string > full_symbols
bool is_derived_dimension() const
If the dimension is not a base dimension, it's considered a derived dimension.
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...
dimension()
Default constructor. The dimension_type is NONE, the dimension_position is NO_POSITION,...
Definition dimension.cpp:27
long double prefix_math() const
Returns the math between the prefix and the dimension, which varies if the dimension is a B or anothe...
void invert()
Changes the position of the dimension to the reverse, from the NUMERATOR to the DENOMINATOR,...
static char * create_full_symbol(const string &full_symbol)
Creates a new dimension that's stored in the private static map dimension::full_symbols.
Definition dimension.hpp:87
Class that represents prefixes of the SI system of units. Each prefix sizes 1 byte....
Definition prefix.hpp:14
type
Represents a prefix of the SI system of units. All the prefixes of the SI system of units are support...
Definition prefix.hpp:16
bool operator!=(const scifir::dimension &x, const scifir::dimension &y)
Checks if the dimension type and the position of two dimensions are any of them different....
ostream & operator<<(ostream &os, const scifir::dimension &x)
Adds the string representation of a dimension to an output stream.
bool operator==(const scifir::dimension &x, const scifir::dimension &y)
Checks if the dimension type, the position and the prefix of two dimensions are the same.
The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
Definition address.cpp:6
bool equal_dimensions(const string &init_dimensions_x, const string &init_dimensions_y)
Checks if two initialization strings of dimensions initialize the same basic dimensions.
vector< dimension > divide_dimensions(vector< dimension > x, const vector< dimension > &y, long double &value)
Divides the first vector of dimensions with the other. The result is normalized after,...
bool equal_dimensions_and_prefixes(const vector< dimension > &x, const vector< dimension > &y)
Checks if the base dimensions of two vectors of dimensions are equal, and if they have also the same ...
bool common_dimension(const dimension &x, const dimension &y)
Checks if there's an equal basic dimension between the basic dimensions of those two dimensions.
vector< dimension > normalize_dimensions(const vector< dimension > &x)
Normalizes the dimensions, which means that repited dimensions at the numerator and at the denominato...
string to_string(const aid &x)
Creates a string representation of aid, it's for aid equivalent to the display() function of aid.
Definition aid.cpp:582
vector< dimension > create_base_dimensions(const string &init_dimensions)
Creates the base dimensions from an initialization string of dimensions.
bool is_dimension_char(const UChar32 &x)
string to_latex(const vector< dimension > &x_dimensions, bool with_brackets)
vector< dimension > multiply_dimensions(const vector< dimension > &x, const vector< dimension > &y)
Multiplies two vectors of dimensions. The result is normalized after, which means that equal dimensio...
vector< dimension > square_dimensions(vector< dimension > x, int index, long double &value)
Squares a vector of dimensions by an index. The value is updated too related to the prefix math and t...
vector< dimension > create_dimensions(string init_dimensions)
Creates the dimensions from an initialization string of dimensions.
vector< dimension > power_dimensions(const vector< dimension > &x, int exponent)
Powers the dimensions by an exponent.