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
Classes | Namespaces | Macros | Functions
scalar_unit.hpp File Reference
#include "./dimension.hpp"
#include "./prefix.hpp"
#include "../util/is_number.hpp"
#include <cmath>
#include <map>
#include <string>
#include <iostream>
#include <sstream>
#include <string_view>
#include <vector>
Include dependency graph for scalar_unit.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  scifir::scalar_unit
 Class that allows to create scalar units, which are composed of a value (as a float) and dimensions. The dimensions can be of any number, and be simple dimensions, composite dimensions and/or special names of dimensions. All base and derived scalar unit classes inherit from scalar_unit. Initialization string example: "1 N". More...
 

Namespaces

namespace  scifir
 The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
 

Macros

#define SCALAR_UNIT_HPP_BEGIN(name)
 
#define SCALAR_UNIT_HPP_END()
 
#define SCALAR_UNIT_HPP(name)
 
#define SCALAR_UNIT_CPP(name, init_real_dimensions)
 

Functions

string scifir::to_string (const scalar_unit &x)
 Generates a string representation of the scalar_unit, it uses the display of the scalar_unit with 2 decimals, without brackets and without a close prefix.
 
bool scifir::is_scalar_unit (const string &init_scalar)
 Checks if an string is an initialization string of a scalar_unit.
 
float scifir::abs (const scalar_unit &x)
 Returns the absolute value of the scalar_unit, without dimensions.
 
scalar_unit scifir::pow (const scalar_unit &x, int exponent)
 Exponentiates a scalar_unit to some numeric type, the dimensions are also exponentiated.
 
scalar_unit scifir::sqrt (const scalar_unit &x)
 Square root of a scalar_unit, it squares the dimensions too.
 
scalar_unit scifir::sqrt_nth (const scalar_unit &x, int index)
 Nth root of a scalar_unit to any numeric value, it squares the dimensions too.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
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 dimensions of x.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
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 same dimensions of x.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
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 same dimensions of x.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
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 same dimensions of x.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
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, returns a float as the result of the calculation.
 
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. If their basic dimensions are different, it returns false.
 
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 are not equal, they are changed to be equal in order to do the comparison.
 
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 are not equal, they are changed to be equal in order to do the comparison.
 
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. If their dimensions are not equal, they are changed to be equal in order to do the comparison.
 
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. If their dimensions are not equal, they are changed to be equal in order to do the comparison.
 
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. The display() function is not used, and so the values are compared with all its decimal numbers.
 
bool operator!= (const scifir::scalar_unit &x, const string &init_scalar)
 Returns true if x is not equal to the scalar_unit initialized with the string being compared. The display() function is not used, and so the values are compared with all its decimal numbers.
 
bool operator< (const scifir::scalar_unit &x, const string &init_scalar)
 Returns true if x is lower than the scalar_unit initialized with the string being compared.
 
bool operator> (const scifir::scalar_unit &x, const string &init_scalar)
 Returns true if x is greather than the scalar_unit initialized with the string being compared.
 
bool operator<= (const scifir::scalar_unit &x, const string &init_scalar)
 Returns true if x is lower or equal to the scalar_unit initialized with the string being compared.
 
bool operator>= (const scifir::scalar_unit &x, const string &init_scalar)
 Returns true if x is greather or equal to the scalar_unit initialized with the string being compared.
 
bool operator== (const string &init_scalar, const scifir::scalar_unit &x)
 Returns true if x is equal to the scalar_unit initialized with the string being compared. The display() function is not used, and so the values are compared with all its decimal numbers.
 
bool operator!= (const string &init_scalar, const scifir::scalar_unit &x)
 Returns true if x is not equal to the scalar_unit initialized with the string being compared. The display() function is not used, and so the values are compared with all its decimal numbers.
 
bool operator< (const string &init_scalar, const scifir::scalar_unit &x)
 Returns true if x is greather than the scalar_unit initialized with the string being compared.
 
bool operator> (const string &init_scalar, const scifir::scalar_unit &x)
 Returns true if x is lower than the scalar_unit initialized with the string being compared.
 
bool operator<= (const string &init_scalar, const scifir::scalar_unit &x)
 Returns true if x is greather or equal to the scalar_unit initialized with the string being compared.
 
bool operator>= (const string &init_scalar, const scifir::scalar_unit &x)
 Returns true if x is lower or equal to the scalar_unit initialized with the string being compared.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator== (const T &x, const scifir::scalar_unit &y)
 Returns true if the value of the scalar_unit is equal to the numeric type, ignoring the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator!= (const T &x, const scifir::scalar_unit &y)
 Returns true if the value of the scalar_unit is not equal to the numeric type, ignoring the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator< (const T &x, const scifir::scalar_unit &y)
 Returns true if the value of y is greather than the numeric type, ignoring the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator> (const T &x, const scifir::scalar_unit &y)
 Returns true if the value of y is lower than the numeric type, ignoring the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator<= (const T &x, const scifir::scalar_unit &y)
 Returns true if the value of y is lower or equal than the numeric type, ignoring the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator>= (const T &x, const scifir::scalar_unit &y)
 Returns true if the value of y is equal or greather than the numeric type, ignoring the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator== (const scifir::scalar_unit &x, const T &y)
 Returns true if the value of the scalar_unit is equal to the numeric type, ignoring the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator!= (const scifir::scalar_unit &x, const T &y)
 Returns true if the value of the scalar_unit is not equal to the numeric type, ignoring the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator< (const scifir::scalar_unit &x, const T &y)
 Returns true if the value of x is lower than the numeric type, ignoring the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator> (const scifir::scalar_unit &x, const T &y)
 Returns true if the value of x is greather than the numeric type, ignoring the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator<= (const scifir::scalar_unit &x, const T &y)
 Returns true if the value of x is lower or equal than the numeric type, ignoring the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator>= (const scifir::scalar_unit &x, const T &y)
 Returns true if the value of x is equal or greather than the numeric type, ignoring the dimensions.
 
void operator+= (string &x, const scifir::scalar_unit &y)
 Concatenates the string representation of the scalar_unit y to the string x.
 
string operator+ (const string &x, const scifir::scalar_unit &y)
 Creates a new string as the concatenation of the string x with the representation string of the scalar_unit y.
 
string operator+ (const scifir::scalar_unit &y, const string &x)
 Creates a new string as the concatenation of the string x with the representation string of the scalar_unit y.
 
ostream & operator<< (ostream &os, const scifir::scalar_unit &x)
 Adds the string representation of the scalar_unit x to an output stream os.
 
istream & operator>> (istream &is, scifir::scalar_unit &x)
 Allows that an istream initializes by string a scalar_unit x.
 

Macro Definition Documentation

◆ SCALAR_UNIT_CPP

#define SCALAR_UNIT_CPP (   name,
  init_real_dimensions 
)

Definition at line 81 of file scalar_unit.hpp.

81 : scalar_unit() { \
82 scalar_unit::dimensions = name::real_dimensions; \
83} \
84\
85 name::name(const name& x) : scalar_unit() \
86 { \
87 value = x.get_value(); \
88 dimensions = x.get_dimensions(); \
89 } \
90\
91 name::name(name&& x) : scalar_unit() \
92 { \
93 value = std::move(x.get_value()); \
94 dimensions = std::move(x.get_dimensions()); \
95 } \
96\
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) \
98 { \
99 scalar_unit::check_dimensions(name::real_dimensions); \
100 } \
101\
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) \
103 { \
104 scalar_unit::check_dimensions(name::real_dimensions); \
105 } \
106\
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) \
108 { \
109 scalar_unit::check_dimensions(name::real_dimensions); \
110 } \
111\
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) \
113 { \
114 scalar_unit::check_dimensions(name::real_dimensions); \
115 } \
116\
117 name::name(float new_value, const string& init_dimensions) : scalar_unit(new_value,init_dimensions) \
118 { \
119 scalar_unit::check_dimensions(name::real_dimensions); \
120 } \
121\
122 name::name(double new_value, const string& init_dimensions) : scalar_unit(new_value,init_dimensions) \
123 { \
124 scalar_unit::check_dimensions(name::real_dimensions); \
125 } \
126\
127 name::name(long double new_value, const string& init_dimensions) : scalar_unit(new_value,init_dimensions) \
128 { \
129 scalar_unit::check_dimensions(name::real_dimensions); \
130 } \
131\
132 name::name(int new_value, const string& init_dimensions) : scalar_unit(new_value,init_dimensions) \
133 { \
134 scalar_unit::check_dimensions(name::real_dimensions); \
135 } \
136\
137 name::name(float new_value, const vector<dimension>& new_dimensions) : scalar_unit(new_value,new_dimensions) \
138 { \
139 scalar_unit::check_dimensions(name::real_dimensions); \
140 } \
141\
142 name::name(double new_value, const vector<dimension>& new_dimensions) : scalar_unit(new_value,new_dimensions) \
143 { \
144 scalar_unit::check_dimensions(name::real_dimensions); \
145 } \
146\
147 name::name(long double new_value, const vector<dimension>& new_dimensions) : scalar_unit(new_value,new_dimensions) \
148 { \
149 scalar_unit::check_dimensions(name::real_dimensions); \
150 } \
151\
152 name::name(int new_value, const vector<dimension>& new_dimensions) : scalar_unit(new_value,new_dimensions) \
153 { \
154 scalar_unit::check_dimensions(name::real_dimensions); \
155 } \
156\
157 name::name(const string& init_scalar) : scalar_unit() \
158 { \
159 initialize_from_string(init_scalar,name::real_dimensions); \
160 } \
161\
162 name::name(const scalar_unit& x) : scalar_unit() \
163 { \
164 if (x.has_dimensions(name::real_dimensions)) \
165 { \
166 value = x.get_value(); \
167 dimensions = x.get_dimensions(); \
168 } \
169 } \
170\
171 name::name(scalar_unit&& x) : scalar_unit() \
172 { \
173 if (x.has_dimensions(name::real_dimensions)) \
174 { \
175 value = std::move(x.get_value()); \
176 dimensions = std::move(x.get_dimensions()); \
177 } \
178 } \
179\
180 name& name::operator =(const name& x) \
181 { \
182 value = x.get_value(); \
183 dimensions = x.get_dimensions(); \
184 return *this; \
185 } \
186\
187 name& name::operator =(name&& x) \
188 { \
189 value = std::move(x.get_value()); \
190 dimensions = std::move(x.get_dimensions()); \
191 return *this; \
192 } \
193\
194const string name::dimensions_match = init_real_dimensions; \
195const vector<dimension> name::real_dimensions = create_base_dimensions(init_real_dimensions)
vector< dimension > create_base_dimensions(const string &init_dimensions)
Creates the base dimensions from an initialization string of dimensions.

◆ SCALAR_UNIT_HPP

#define SCALAR_UNIT_HPP (   name)
Value:
class name : public scalar_unit \
{ \
public: \
name(); \
name(const name&); \
name(name&&); \
explicit name(float new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
explicit name(double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
explicit name(long double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
explicit name(int new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
explicit name(float new_value, const string& init_dimensions); \
explicit name(double new_value, const string& init_dimensions); \
explicit name(long double new_value, const string& init_dimensions); \
explicit name(int new_value, const string& init_dimensions); \
explicit name(float new_value, const vector<dimension>& new_dimensions); \
explicit name(double new_value, const vector<dimension>& new_dimensions); \
explicit name(long double new_value, const vector<dimension>& new_dimensions); \
explicit name(int new_value, const vector<dimension>& new_dimensions); \
explicit name(const string& init_scalar); \
explicit name(const scalar_unit&); \
explicit name(scalar_unit&&); \
name& operator =(const name&); \
name& operator =(name&&); \
using scalar_unit::operator =; \
using scalar_unit::operator +=; \
using scalar_unit::operator -=; \
\
static const string dimensions_match; \
static const vector<dimension> real_dimensions; \
}

Definition at line 50 of file scalar_unit.hpp.

50 : public scalar_unit \
51 { \
52 public: \
53 name(); \
54 name(const name&); \
55 name(name&&); \
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 -=; \
76\
77 static const string dimensions_match; \
78 static const vector<dimension> real_dimensions; \
79 }

◆ SCALAR_UNIT_HPP_BEGIN

#define SCALAR_UNIT_HPP_BEGIN (   name)
Value:
class name : public scalar_unit \
{ \
public: \
name(); \
name(const name&); \
name(name&&); \
explicit name(float new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
explicit name(double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
explicit name(long double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
explicit name(int new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
explicit name(float new_value, const string& init_dimensions); \
explicit name(double new_value, const string& init_dimensions); \
explicit name(long double new_value, const string& init_dimensions); \
explicit name(int new_value, const string& init_dimensions); \
explicit name(float new_value, const vector<dimension>& new_dimensions); \
explicit name(double new_value, const vector<dimension>& new_dimensions); \
explicit name(long double new_value, const vector<dimension>& new_dimensions); \
explicit name(int new_value, const vector<dimension>& new_dimensions); \
explicit name(const string& init_scalar); \
explicit name(const scalar_unit&); \
explicit name(scalar_unit&&); \
name& operator =(const name&); \
name& operator =(name&&); \
using scalar_unit::operator =; \
using scalar_unit::operator +=; \
using scalar_unit::operator -=

Definition at line 16 of file scalar_unit.hpp.

16 : public scalar_unit \
17 { \
18 public: \
19 name(); \
20 name(const name&); \
21 name(name&&); \
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 -=

◆ SCALAR_UNIT_HPP_END

#define SCALAR_UNIT_HPP_END ( )
Value:
\
public: \
static const string dimensions_match; \
static const vector<dimension> real_dimensions; \
}

Definition at line 43 of file scalar_unit.hpp.

45 : \
46 static const string dimensions_match; \
47 static const vector<dimension> real_dimensions; \
48 }

Function Documentation

◆ operator!=() [1/5]

bool operator!= ( const scifir::scalar_unit x,
const string &  init_scalar 
)

Returns true if x is not equal to the scalar_unit initialized with the string being compared. The display() function is not used, and so the values are compared with all its decimal numbers.

Definition at line 1021 of file scalar_unit.cpp.

1022{
1023 return !(x == init_scalar);
1024}

◆ operator!=() [2/5]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator!= ( const scifir::scalar_unit x,
const T &  y 
)

Returns true if the value of the scalar_unit is not equal to the numeric type, ignoring the dimensions.

Definition at line 641 of file scalar_unit.hpp.

642{
643 return !(x == y);
644}

◆ operator!=() [3/5]

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. If their basic dimensions are different, it returns false.

Definition at line 964 of file scalar_unit.cpp.

965{
966 return !(x == y);
967}

◆ operator!=() [4/5]

bool operator!= ( const string &  init_scalar,
const scifir::scalar_unit x 
)

Returns true if x is not equal to the scalar_unit initialized with the string being compared. The display() function is not used, and so the values are compared with all its decimal numbers.

Definition at line 1053 of file scalar_unit.cpp.

1054{
1055 return (x != init_scalar);
1056}

◆ operator!=() [5/5]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator!= ( const T &  x,
const scifir::scalar_unit y 
)

Returns true if the value of the scalar_unit is not equal to the numeric type, ignoring the dimensions.

Definition at line 605 of file scalar_unit.hpp.

606{
607 return !(x == y);
608}

◆ operator*()

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
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 same dimensions of x.

Definition at line 551 of file scalar_unit.hpp.

552{
554 z *= y;
555 return z;
556}
Class that allows to create scalar units, which are composed of a value (as a float) and dimensions....

◆ operator+() [1/3]

string operator+ ( const scifir::scalar_unit y,
const string &  x 
)

Creates a new string as the concatenation of the string x with the representation string of the scalar_unit y.

Definition at line 1095 of file scalar_unit.cpp.

1096{
1097 ostringstream output;
1098 output << y;
1099 output << x;
1100 return output.str();
1101}

◆ operator+() [2/3]

string operator+ ( const string &  x,
const scifir::scalar_unit y 
)

Creates a new string as the concatenation of the string x with the representation string of the scalar_unit y.

Definition at line 1087 of file scalar_unit.cpp.

1088{
1089 ostringstream output;
1090 output << x;
1091 output << y;
1092 return output.str();
1093}

◆ operator+() [3/3]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
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 dimensions of x.

Definition at line 535 of file scalar_unit.hpp.

536{
538 z += y;
539 return z;
540}

◆ operator+=()

void operator+= ( string &  x,
const scifir::scalar_unit y 
)

Concatenates the string representation of the scalar_unit y to the string x.

Definition at line 1080 of file scalar_unit.cpp.

1081{
1082 ostringstream output;
1083 output << y;
1084 x += output.str();
1085}

◆ operator-()

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
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 same dimensions of x.

Definition at line 543 of file scalar_unit.hpp.

544{
546 z -= x;
547 return z;
548}
const vector< dimension > & get_dimensions() const
Read-only getter of the dimensions.

◆ operator/()

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
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 same dimensions of x.

Definition at line 559 of file scalar_unit.hpp.

560{
561 scifir::scalar_unit z = scifir::scalar_unit((long double)y,vector<scifir::dimension>());
562 return z / x;
563}

◆ operator<() [1/5]

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 are not equal, they are changed to be equal in order to do the comparison.

Definition at line 969 of file scalar_unit.cpp.

970{
971 if(!x.has_dimensions(y))
972 {
973 return false;
974 }
977 if(z.get_value() < y.get_value())
978 {
979 return true;
980 }
981 else
982 {
983 return false;
984 }
985}
bool has_dimensions(const string &init_dimensions) const
Checks if the basic dimensions are the same as the initialization string of dimensions.
void change_dimensions(const string &init_dimensions)
Changes the dimensions to the dimensions specified by the initialization string of dimensions.
const float & get_value() const
Read-only getter of the value.

◆ operator<() [2/5]

bool operator< ( const scifir::scalar_unit x,
const string &  init_scalar 
)

Returns true if x is lower than the scalar_unit initialized with the string being compared.

Definition at line 1026 of file scalar_unit.cpp.

1027{
1028 scifir::scalar_unit y(init_scalar);
1029 return (x < y);
1030}

◆ operator<() [3/5]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator< ( const scifir::scalar_unit x,
const T &  y 
)

Returns true if the value of x is lower than the numeric type, ignoring the dimensions.

Definition at line 647 of file scalar_unit.hpp.

648{
649 return (x.get_value() < y);
650}

◆ operator<() [4/5]

bool operator< ( const string &  init_scalar,
const scifir::scalar_unit x 
)

Returns true if x is greather than the scalar_unit initialized with the string being compared.

Definition at line 1058 of file scalar_unit.cpp.

1059{
1060 scifir::scalar_unit y(init_scalar);
1061 return (y < x);
1062}

◆ operator<() [5/5]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator< ( const T &  x,
const scifir::scalar_unit y 
)

Returns true if the value of y is greather than the numeric type, ignoring the dimensions.

Definition at line 611 of file scalar_unit.hpp.

612{
613 return (x < y.get_value());
614}

◆ operator<<()

ostream & operator<< ( ostream &  os,
const scifir::scalar_unit x 
)

Adds the string representation of the scalar_unit x to an output stream os.

Definition at line 1103 of file scalar_unit.cpp.

1104{
1105 return os << to_string(x);
1106}
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

◆ operator<=() [1/5]

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. If their dimensions are not equal, they are changed to be equal in order to do the comparison.

Definition at line 1005 of file scalar_unit.cpp.

1006{
1007 return !(x > y);
1008}

◆ operator<=() [2/5]

bool operator<= ( const scifir::scalar_unit x,
const string &  init_scalar 
)

Returns true if x is lower or equal to the scalar_unit initialized with the string being compared.

Definition at line 1038 of file scalar_unit.cpp.

1039{
1040 return !(x > init_scalar);
1041}

◆ operator<=() [3/5]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator<= ( const scifir::scalar_unit x,
const T &  y 
)

Returns true if the value of x is lower or equal than the numeric type, ignoring the dimensions.

Definition at line 659 of file scalar_unit.hpp.

660{
661 return (x.get_value() <= y);
662}

◆ operator<=() [4/5]

bool operator<= ( const string &  init_scalar,
const scifir::scalar_unit x 
)

Returns true if x is greather or equal to the scalar_unit initialized with the string being compared.

Definition at line 1070 of file scalar_unit.cpp.

1071{
1072 return !(init_scalar > x);
1073}

◆ operator<=() [5/5]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator<= ( const T &  x,
const scifir::scalar_unit y 
)

Returns true if the value of y is lower or equal than the numeric type, ignoring the dimensions.

Definition at line 623 of file scalar_unit.hpp.

624{
625 return (x <= y.get_value());
626}

◆ operator==() [1/4]

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. The display() function is not used, and so the values are compared with all its decimal numbers.

Definition at line 1015 of file scalar_unit.cpp.

1016{
1017 scifir::scalar_unit y(init_scalar);
1018 return (x == y);
1019}

◆ operator==() [2/4]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator== ( const scifir::scalar_unit x,
const T &  y 
)

Returns true if the value of the scalar_unit is equal to the numeric type, ignoring the dimensions.

Definition at line 635 of file scalar_unit.hpp.

636{
637 return (x.get_value() == y);
638}

◆ operator==() [3/4]

bool operator== ( const string &  init_scalar,
const scifir::scalar_unit x 
)

Returns true if x is equal to the scalar_unit initialized with the string being compared. The display() function is not used, and so the values are compared with all its decimal numbers.

Definition at line 1048 of file scalar_unit.cpp.

1049{
1050 return (x == init_scalar);
1051}

◆ operator==() [4/4]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator== ( const T &  x,
const scifir::scalar_unit y 
)

Returns true if the value of the scalar_unit is equal to the numeric type, ignoring the dimensions.

Definition at line 599 of file scalar_unit.hpp.

600{
601 return (x == y.get_value());
602}

◆ operator>() [1/5]

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 are not equal, they are changed to be equal in order to do the comparison.

Definition at line 987 of file scalar_unit.cpp.

988{
989 if(!x.has_dimensions(y))
990 {
991 return false;
992 }
995 if(z.get_value() > y.get_value())
996 {
997 return true;
998 }
999 else
1000 {
1001 return false;
1002 }
1003}

◆ operator>() [2/5]

bool operator> ( const scifir::scalar_unit x,
const string &  init_scalar 
)

Returns true if x is greather than the scalar_unit initialized with the string being compared.

Definition at line 1032 of file scalar_unit.cpp.

1033{
1034 scifir::scalar_unit y(init_scalar);
1035 return (x > y);
1036}

◆ operator>() [3/5]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator> ( const scifir::scalar_unit x,
const T &  y 
)

Returns true if the value of x is greather than the numeric type, ignoring the dimensions.

Definition at line 653 of file scalar_unit.hpp.

654{
655 return (x.get_value() > y);
656}

◆ operator>() [4/5]

bool operator> ( const string &  init_scalar,
const scifir::scalar_unit x 
)

Returns true if x is lower than the scalar_unit initialized with the string being compared.

Definition at line 1064 of file scalar_unit.cpp.

1065{
1066 scifir::scalar_unit y(init_scalar);
1067 return (y > x);
1068}

◆ operator>() [5/5]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator> ( const T &  x,
const scifir::scalar_unit y 
)

Returns true if the value of y is lower than the numeric type, ignoring the dimensions.

Definition at line 617 of file scalar_unit.hpp.

618{
619 return (x > y.get_value());
620}

◆ operator>=() [1/5]

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. If their dimensions are not equal, they are changed to be equal in order to do the comparison.

Definition at line 1010 of file scalar_unit.cpp.

1011{
1012 return !(x < y);
1013}

◆ operator>=() [2/5]

bool operator>= ( const scifir::scalar_unit x,
const string &  init_scalar 
)

Returns true if x is greather or equal to the scalar_unit initialized with the string being compared.

Definition at line 1043 of file scalar_unit.cpp.

1044{
1045 return !(x < init_scalar);
1046}

◆ operator>=() [3/5]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator>= ( const scifir::scalar_unit x,
const T &  y 
)

Returns true if the value of x is equal or greather than the numeric type, ignoring the dimensions.

Definition at line 665 of file scalar_unit.hpp.

666{
667 return (x.get_value() >= y);
668}

◆ operator>=() [4/5]

bool operator>= ( const string &  init_scalar,
const scifir::scalar_unit x 
)

Returns true if x is lower or equal to the scalar_unit initialized with the string being compared.

Definition at line 1075 of file scalar_unit.cpp.

1076{
1077 return !(init_scalar < x);
1078}

◆ operator>=() [5/5]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
bool operator>= ( const T &  x,
const scifir::scalar_unit y 
)

Returns true if the value of y is equal or greather than the numeric type, ignoring the dimensions.

Definition at line 629 of file scalar_unit.hpp.

630{
631 return (x >= y.get_value());
632}

◆ operator>>()

istream & operator>> ( istream &  is,
scifir::scalar_unit x 
)

Allows that an istream initializes by string a scalar_unit x.

Definition at line 1108 of file scalar_unit.cpp.

1109{
1110 char a[256];
1111 is.getline(a, 256);
1112 string b(a);
1113 boost::trim(b);
1114 x = scifir::scalar_unit(b);
1115 return is;
1116}

◆ operator^()

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
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, returns a float as the result of the calculation.

Definition at line 566 of file scalar_unit.hpp.

567{
569 {
570 return std::pow(x, y.get_value());
571 }
572 else
573 {
574 return 0;
575 }
576}
bool has_empty_dimensions() const
Checks if there aren't base dimensions.