3#include "../util/types.hpp"
5#include "boost/algorithm/string.hpp"
226 cerr <<
"A percentage cannot be initialized with dimensions" <<
endl;
239 value = std::move(x.get_value());
281 cerr <<
"A percentage cannot be initialized with dimensions" <<
endl;
365 return value / 100.0f;
370 return value * 10000.0f;
607 return !(x == init_percentage);
618 return !(init_percentage == x);
623 ostringstream output;
630 ostringstream output;
638 ostringstream output;
646 return os << to_string(x);
Class that allows to handle percentages and do calculations with it easy. It supports normal percenta...
percentage operator*(const percentage &x) const
Creates a new percentage as the multiplication of two percentages.
percentage operator/(const percentage &x) const
Creates a new percentage as the division of two percentages.
void initialize_from_string(const string &init_percentage)
Internal function. Initializes the member-variables with an initialization string of percentage.
percentage operator+(const percentage &x) const
Creates a new percentage as the addition of two percentages.
float get_factor() const
Returns the factor of the percentage, not his value. It equals is value divided by 100.
percentage()
Default constructor. The value is 0.
percentage & operator=(const percentage &x)
Copy assignment. The value is copied from the percentage x.
percentage & operator--()
Decrements the value by one.
@ PARTS_PER_MILLION
Percentage, with the ppm symbol. Commonly used in chemistry, it represents 1 in 10^6.
@ RATIO
The normal percentage obtained by a direct ratio of some proportion, you don't need to multiply by 10...
@ PERCENTAGE
Normal percentage, with the % symbol.
void operator+=(const percentage &x)
Sums the value with the value of the percentage x.
string display_ppm() const
Displays the percentage as ppm, with the ppm symbol.
float get_ppm() const
Returns the factor of the percentage in ppm, not his value. It equals is value multiplied by 10,...
string display_percentage(int number_of_decimals=2) const
Displays the percentage as normal percentage, with the % symbol.
void operator*=(const percentage &x)
Multiplies the value with the value of the percentage x.
const float & get_value() const
It returns the value.
percentage operator-(const percentage &x) const
Creates a new percentage as the difference of two percentages.
float value
The value of the percentage, in numbers related to a 100%. A percentage of 30% has a value of 30,...
void operator/=(const percentage &x)
Divides the value with the value of the percentage x.
void operator-=(const percentage &x)
Substracts the value with the value of the percentage x.
percentage & operator++()
Increments the value by one.
Class that allows to create scalar units, which are composed of a value (as a float) and dimensions....
bool has_empty_dimensions() const
Checks if there aren't base dimensions.
const float & get_value() const
Read-only getter of the value.
The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
string to_string(const aid &x)
Creates a string representation of aid, it's for aid equivalent to the display() function of aid.
string display_float(const float &value, int number_of_decimals)
bool is_percentage(const string &init_percentage)
Checks if a string is an initialization string of percentage.
bool operator==(const scifir::percentage &x, const scifir::percentage &y)
Returns true if the value of percentage x is equal to the value of percentage y.
string operator+(const string &x, const scifir::percentage &y)
Concatenates x with the string representation of percentage y.
bool operator<(const scifir::percentage &x, const scifir::percentage &y)
Returns true if the value of percentage x is lower than the value of percentage y.
bool operator!=(const scifir::percentage &x, const scifir::percentage &y)
Returns true if the value of percentage x is not equal to the value of percentage y.
ostream & operator<<(ostream &os, const scifir::percentage &x)
Adds the string representation of the percentage x to an output stream os.
scifir::scalar_unit operator/(const scifir::scalar_unit &x, const scifir::percentage &y)
Multiplies the scalar_unit x by the percentage equal to the inverse of percentage y.
bool operator<=(const scifir::percentage &x, const scifir::percentage &y)
Returns true if the value of percentage x is lower or equal than the value of percentage y.
void operator+=(string &x, const scifir::percentage &y)
Concatenates the string representation of percentage y to the string x.
istream & operator>>(istream &is, scifir::percentage &x)
Allows that an istream initializes by string a percentage x.
bool operator>(const scifir::percentage &x, const scifir::percentage &y)
Returns true if the value of percentage x is greather than the value of percentage y.
scifir::scalar_unit operator*(const scifir::scalar_unit &x, const scifir::percentage &y)
Multiplies the percentage with the scalar_unit x to create a percentage of that scalar_unit.
bool operator>=(const scifir::percentage &x, const scifir::percentage &y)
Returns true if the value of percentage x is equal or greather than the value of percentage y.