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
Namespaces | Functions
scalar_unit.cpp File Reference
#include "./scalar_unit.hpp"
#include "./conversion.hpp"
#include "./base_units.hpp"
#include "./prefix.hpp"
#include "../util/types.hpp"
#include "boost/algorithm/string/erase.hpp"
#include "boost/algorithm/string.hpp"
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
Include dependency graph for scalar_unit.cpp:

Go to the source code of this file.

Namespaces

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

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.
 
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.
 
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.
 

Function Documentation

◆ operator!=() [1/3]

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/3]

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!=() [3/3]

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+() [1/2]

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/2]

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+=()

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<() [1/3]

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}
Class that allows to create scalar units, which are composed of a value (as a float) and dimensions....
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/3]

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/3]

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<<()

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/3]

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/3]

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/3]

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==() [1/2]

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/2]

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>() [1/3]

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/3]

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/3]

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>=() [1/3]

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/3]

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/3]

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>>()

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}