1#ifndef SCIFIR_UNITS_UNITS_SCALAR_UNIT_HPP_INCLUDED
2#define SCIFIR_UNITS_UNITS_SCALAR_UNIT_HPP_INCLUDED
6#include "../util/is_number.hpp"
16#define SCALAR_UNIT_HPP_BEGIN(name) class name : public scalar_unit \
22 explicit name(float new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
23 explicit name(double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
24 explicit name(long double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
25 explicit name(int new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
26 explicit name(float new_value, const string& init_dimensions); \
27 explicit name(double new_value, const string& init_dimensions); \
28 explicit name(long double new_value, const string& init_dimensions); \
29 explicit name(int new_value, const string& init_dimensions); \
30 explicit name(float new_value, const vector<dimension>& new_dimensions); \
31 explicit name(double new_value, const vector<dimension>& new_dimensions); \
32 explicit name(long double new_value, const vector<dimension>& new_dimensions); \
33 explicit name(int new_value, const vector<dimension>& new_dimensions); \
34 explicit name(const string& init_scalar); \
35 explicit name(const scalar_unit&); \
36 explicit name(scalar_unit&&); \
37 name& operator =(const name&); \
38 name& operator =(name&&); \
39 using scalar_unit::operator =; \
40 using scalar_unit::operator +=; \
41 using scalar_unit::operator -=
43#define SCALAR_UNIT_HPP_END() \
46 static const string dimensions_match; \
47 static const vector<dimension> real_dimensions; \
50#define SCALAR_UNIT_HPP(name) class name : public scalar_unit \
56 explicit name(float new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
57 explicit name(double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
58 explicit name(long double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
59 explicit name(int new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
60 explicit name(float new_value, const string& init_dimensions); \
61 explicit name(double new_value, const string& init_dimensions); \
62 explicit name(long double new_value, const string& init_dimensions); \
63 explicit name(int new_value, const string& init_dimensions); \
64 explicit name(float new_value, const vector<dimension>& new_dimensions); \
65 explicit name(double new_value, const vector<dimension>& new_dimensions); \
66 explicit name(long double new_value, const vector<dimension>& new_dimensions); \
67 explicit name(int new_value, const vector<dimension>& new_dimensions); \
68 explicit name(const string& init_scalar); \
69 explicit name(const scalar_unit&); \
70 explicit name(scalar_unit&&); \
71 name& operator =(const name&); \
72 name& operator =(name&&); \
73 using scalar_unit::operator =; \
74 using scalar_unit::operator +=; \
75 using scalar_unit::operator -=; \
77 static const string dimensions_match; \
78 static const vector<dimension> real_dimensions; \
81#define SCALAR_UNIT_CPP(name,init_real_dimensions) name::name() : scalar_unit() { \
82 scalar_unit::dimensions = name::real_dimensions; \
85 name::name(const name& x) : scalar_unit() \
87 value = x.get_value(); \
88 dimensions = x.get_dimensions(); \
91 name::name(name&& x) : scalar_unit() \
93 value = std::move(x.get_value()); \
94 dimensions = std::move(x.get_dimensions()); \
97 name::name(float new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position) : scalar_unit(new_value,new_dimension,new_prefix,new_position) \
99 scalar_unit::check_dimensions(name::real_dimensions); \
102 name::name(double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position) : scalar_unit(new_value,new_dimension,new_prefix,new_position) \
104 scalar_unit::check_dimensions(name::real_dimensions); \
107 name::name(long double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position) : scalar_unit(new_value,new_dimension,new_prefix,new_position) \
109 scalar_unit::check_dimensions(name::real_dimensions); \
112 name::name(int new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position) : scalar_unit(new_value,new_dimension,new_prefix,new_position) \
114 scalar_unit::check_dimensions(name::real_dimensions); \
117 name::name(float new_value, const string& init_dimensions) : scalar_unit(new_value,init_dimensions) \
119 scalar_unit::check_dimensions(name::real_dimensions); \
122 name::name(double new_value, const string& init_dimensions) : scalar_unit(new_value,init_dimensions) \
124 scalar_unit::check_dimensions(name::real_dimensions); \
127 name::name(long double new_value, const string& init_dimensions) : scalar_unit(new_value,init_dimensions) \
129 scalar_unit::check_dimensions(name::real_dimensions); \
132 name::name(int new_value, const string& init_dimensions) : scalar_unit(new_value,init_dimensions) \
134 scalar_unit::check_dimensions(name::real_dimensions); \
137 name::name(float new_value, const vector<dimension>& new_dimensions) : scalar_unit(new_value,new_dimensions) \
139 scalar_unit::check_dimensions(name::real_dimensions); \
142 name::name(double new_value, const vector<dimension>& new_dimensions) : scalar_unit(new_value,new_dimensions) \
144 scalar_unit::check_dimensions(name::real_dimensions); \
147 name::name(long double new_value, const vector<dimension>& new_dimensions) : scalar_unit(new_value,new_dimensions) \
149 scalar_unit::check_dimensions(name::real_dimensions); \
152 name::name(int new_value, const vector<dimension>& new_dimensions) : scalar_unit(new_value,new_dimensions) \
154 scalar_unit::check_dimensions(name::real_dimensions); \
157 name::name(const string& init_scalar) : scalar_unit() \
159 initialize_from_string(init_scalar,name::real_dimensions); \
162 name::name(const scalar_unit& x) : scalar_unit() \
164 if (x.has_dimensions(name::real_dimensions)) \
166 value = x.get_value(); \
167 dimensions = x.get_dimensions(); \
171 name::name(scalar_unit&& x) : scalar_unit() \
173 if (x.has_dimensions(name::real_dimensions)) \
175 value = std::move(x.get_value()); \
176 dimensions = std::move(x.get_dimensions()); \
180 name& name::operator =(const name& x) \
182 value = x.get_value(); \
183 dimensions = x.get_dimensions(); \
187 name& name::operator =(name&& x) \
189 value = std::move(x.get_value()); \
190 dimensions = std::move(x.get_dimensions()); \
194const string name::dimensions_match = init_real_dimensions; \
195const vector<dimension> name::real_dimensions = create_base_dimensions(init_real_dimensions)
225 explicit operator float()
const;
534template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
542template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
550template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
558template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
565template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
598template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
604template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
610template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
616template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
622template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
628template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
634template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
640template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
646template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
652template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
658template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
664template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
Class that represents dimensions of the SI system of units. Each dimension sizes 6 bytes,...
position
Represents the position of the dimension, which can be at the numerator or at the denominator....
@ NUMERATOR
The dimension is at the numerator.
type
Represents a dimension of the SI system of units. All the dimensions of the SI system of units are su...
type
Represents a prefix of the SI system of units. All the prefixes of the SI system of units are support...
Class that allows to create scalar units, which are composed of a value (as a float) and dimensions....
string to_latex(const string &init_dimensions, int number_of_decimals=2, bool with_brackets=false) const
bool has_single_dimensions() const
Returns true if there's only one dimension, which can be simple or composite.
bool has_empty_dimensions() const
Checks if there aren't base dimensions.
void operator*=(T y)
Multiplication operator, it multiplies the numeric type to the value, independent of the dimensions.
string display_dimensions() const
Generates an string of the dimensions of the scalar_unit, with the same format as the initialization ...
scalar_unit & operator--()
Decrement operator, it decreases the value by one.
bool has_composite_dimensions() const
Returns true is there's more than one simple dimension.
void add_dimension(const dimension &new_dimension)
Internal function. It adds a dimension, changing the value according to the conversion factor of the ...
vector< dimension > dimensions
Dimensions of the scalar_unit. They can be simple dimensions, composite dimensions or special names.
scalar_unit & operator=(const scalar_unit &x)
Copy assignment, it assigns a copy of the scalar_unit.
scalar_unit operator*(scalar_unit x) const
Multiplication operator, it multiplies two scalar_unit classes, their dimensions are also multiplied.
const vector< dimension > & get_dimensions() const
Read-only getter of the dimensions.
bool operator==(scalar_unit x) const
Comparison operator, two scalar_unit classes are considered equivalent if they have the same value gi...
scalar_unit operator/(scalar_unit x) const
Division operator, it divides one scalar_unit class with the other, their dimensions are also divided...
bool has_dimensions(const string &init_dimensions) const
Checks if the basic dimensions are the same as the initialization string of dimensions.
void check_dimensions(const vector< dimension > &real_dimensions)
dimension::type get_single_dimension_type() const
Returns the dimension::type if there's only one dimension, returns dimension::NONE if there's more th...
string display(int number_of_decimals=2, bool with_brackets=false, bool use_close_prefix=false) const
Generates a string representation of the scalar_unit, with the value and the dimensions....
vector< dimension > get_base_dimensions() const
Generates a set of the base dimensions of the dimensions of the scalar_unit.
float value
Value of the scalar_unit. It changes automatically when the dimensions change.
bool is_dimensionless() const
Returns true if there aren't dimensions or if all dimensions are dimensionless.
scalar_unit operator+(scalar_unit x) const
Addition operator, it sums two scalar_unit classes, their dimensions are changed to be equal first....
scalar_unit & operator++()
Increment operator, it increases the value by one.
bool has_simple_dimensions() const
Returns true if there's only a simple dimension.
scalar_unit operator-(scalar_unit x) const
Substraction operator, it substracts one scalar_unit from the other, their dimensions are changed to ...
void change_dimensions(const string &init_dimensions)
Changes the dimensions to the dimensions specified by the initialization string of dimensions.
scalar_unit()
Default constructor, the value is 0 and the dimensions are empty.
void operator/=(T y)
Division operator, it divides the numeric type to the value, independent of the dimensions.
void operator+=(scalar_unit x)
Addition operator, it adds a scalar_unit class to another, by converting their dimensions to be equal...
void initialize_from_string(string init_scalar, const vector< dimension > &real_dimensions)
Internal function. It sets the value and the dimensions of the scalar_unit to the value and dimension...
string custom_display(const string &init_dimensions, int number_of_decimals=2, bool with_brackets=false) const
Generates a string representation of the scalar_unit, with the dimensions changed to any set of dimen...
void operator-=(scalar_unit x)
Substraction operator, it substracts a scalar_unit class to another, by converting their dimensions t...
string base_display(int number_of_decimals=2, bool with_brackets=false, bool use_close_prefix=false) const
Generates a string representation of the scalar_unit, with its dimensions converted to their base cou...
void remove_dimension(const dimension &old_dimension)
Internal function. It removes a dimension, changing the value according to the conversion factor of t...
const float & get_value() const
Read-only getter of the value.
scalar_unit operator^(const scalar_unit &x) const
Power operator, it powers a scalar_unit class with another, if that second scalar_unit class,...
The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
angle sqrt_nth(const angle &x, int index)
Calculates the nth root of the angle x and returns that new angle.
T abs(const complex_number< T > &x)
bool is_scalar_unit(const string &init_scalar)
Checks if an string is an initialization string of a scalar_unit.
scalar_unit pow(const scalar_unit &x, int exponent)
Exponentiates a scalar_unit to some numeric type, the dimensions are also exponentiated.
string to_string(const aid &x)
Creates a string representation of aid, it's for aid equivalent to the display() function of aid.
angle sqrt(const angle &x)
Calculates the square root of the angle x and returns that new angle.
vector< dimension > power_dimensions(const vector< dimension > &x, int exponent)
Powers the dimensions by an exponent.
bool operator<=(const scifir::scalar_unit &x, const scifir::scalar_unit &y)
Returns true if x has a lower or equal value than y, compared with the same dimensions....
scifir::scalar_unit operator/(const T &y, const scifir::scalar_unit &x)
Divides a numeric type y with an scalar_unit x, returns that result as a new scalar_unit with the sam...
scifir::scalar_unit operator+(const T &y, const scifir::scalar_unit &x)
Sums a numeric type y with an scalar_unit x, returns that result as a new scalar_unit with the same d...
scifir::scalar_unit operator-(const T &y, const scifir::scalar_unit &x)
Substracts a scalar_unit x to a numeric type y, returns that result as a new scalar_unit with the sam...
scifir::scalar_unit operator*(const T &y, const scifir::scalar_unit &x)
Multiplies a numeric type y with an scalar_unit x, returns that result as a new scalar_unit with the ...
float operator^(const T &x, const scifir::scalar_unit &y)
Exponentiates a numeric type x with a scalar_unit y, only if that scalar_unit as empty dimensions,...
istream & operator>>(istream &is, scifir::scalar_unit &x)
Allows that an istream initializes by string a scalar_unit x.
bool operator>(const scifir::scalar_unit &x, const scifir::scalar_unit &y)
Returns true if x has a greather value than y, compared with the same dimensions. If their dimensions...
bool operator!=(const scifir::scalar_unit &x, scifir::scalar_unit y)
Returns true if two scalar_unit classes doesn't have the same value when changed to same dimensions....
ostream & operator<<(ostream &os, const scifir::scalar_unit &x)
Adds the string representation of the scalar_unit x to an output stream os.
void operator+=(string &x, const scifir::scalar_unit &y)
Concatenates the string representation of the scalar_unit y to the string x.
bool operator==(const scifir::scalar_unit &x, const string &init_scalar)
Returns true if x is equal to the scalar_unit initialized with the string being compared....
bool operator<(const scifir::scalar_unit &x, const scifir::scalar_unit &y)
Returns true if x has a lower value than y, compared with the same dimensions. If their dimensions ar...
bool operator>=(const scifir::scalar_unit &x, const scifir::scalar_unit &y)
Returns true if x has a greather or equal value than y, compared with the same dimensions....