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
percentage.cpp File Reference
#include "./percentage.hpp"
#include "../util/types.hpp"
#include "boost/algorithm/string.hpp"
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
Include dependency graph for percentage.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 percentage &x)
 Returns a string representation of percentage x.
 
bool scifir::is_percentage (const string &init_percentage)
 Checks if a string is an initialization string of percentage.
 
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.
 
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 equal to 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.
 
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 greather 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 lower or equal 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 equal or greather than the value of percentage y.
 
bool operator== (const scifir::percentage &x, const string &init_percentage)
 Returns true if x and the percentage constructed with init_percentage are equal.
 
bool operator!= (const scifir::percentage &x, const string &init_percentage)
 Returns true if x and the percentage constructed with init_percentage are different.
 
bool operator== (const string &init_percentage, const scifir::percentage &x)
 Returns true if x and the percentage constructed with init_percentage are equal.
 
bool operator!= (const string &init_percentage, const scifir::percentage &x)
 Returns true if x and the percentage constructed with init_percentage are different.
 
void operator+= (string &x, const scifir::percentage &y)
 Concatenates the string representation of percentage y to the string x.
 
string operator+ (const string &x, const scifir::percentage &y)
 Concatenates x with the string representation of percentage y.
 
string operator+ (const scifir::percentage &y, const string &x)
 Concatenates x with the string representation of percentage y.
 
ostream & operator<< (ostream &os, const scifir::percentage &x)
 Adds the string representation of the percentage x to an output stream os.
 
istream & operator>> (istream &is, scifir::percentage &x)
 Allows that an istream initializes by string a percentage x.
 

Function Documentation

◆ operator!=() [1/3]

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.

Definition at line 560 of file percentage.cpp.

561{
562 return !(x == y);
563}

◆ operator!=() [2/3]

bool operator!= ( const scifir::percentage x,
const string &  init_percentage 
)

Returns true if x and the percentage constructed with init_percentage are different.

Definition at line 605 of file percentage.cpp.

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

◆ operator!=() [3/3]

bool operator!= ( const string &  init_percentage,
const scifir::percentage x 
)

Returns true if x and the percentage constructed with init_percentage are different.

Definition at line 616 of file percentage.cpp.

617{
618 return !(init_percentage == x);
619}

◆ operator*()

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.

Definition at line 538 of file percentage.cpp.

539{
540 return x * y.get_factor();
541}
float get_factor() const
Returns the factor of the percentage, not his value. It equals is value divided by 100.

◆ operator+() [1/2]

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

Concatenates x with the string representation of percentage y.

Definition at line 636 of file percentage.cpp.

637{
638 ostringstream output;
639 output << y;
640 output << x;
641 return output.str();
642}

◆ operator+() [2/2]

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

Concatenates x with the string representation of percentage y.

Definition at line 628 of file percentage.cpp.

629{
630 ostringstream output;
631 output << x;
632 output << y;
633 return output.str();
634}

◆ operator+=()

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

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

Definition at line 621 of file percentage.cpp.

622{
623 ostringstream output;
624 output << y;
625 x += output.str();
626}

◆ operator/()

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.

Definition at line 543 of file percentage.cpp.

544{
545 return x / y.get_factor();
546}

◆ operator<()

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.

Definition at line 565 of file percentage.cpp.

566{
567 if(x.get_value() < y.get_value())
568 {
569 return true;
570 }
571 else
572 {
573 return false;
574 }
575}
const float & get_value() const
It returns the value.

◆ operator<<()

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

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

Definition at line 644 of file percentage.cpp.

645{
646 return os << to_string(x);
647}
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<=()

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.

Definition at line 589 of file percentage.cpp.

590{
591 return !(x > y);
592}

◆ operator==() [1/3]

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.

Definition at line 548 of file percentage.cpp.

549{
550 if(x.get_value() == y.get_value())
551 {
552 return true;
553 }
554 else
555 {
556 return false;
557 }
558}

◆ operator==() [2/3]

bool operator== ( const scifir::percentage x,
const string &  init_percentage 
)

Returns true if x and the percentage constructed with init_percentage are equal.

Definition at line 599 of file percentage.cpp.

600{
601 scifir::percentage y = scifir::percentage(init_percentage);
602 return (x == y);
603}
Class that allows to handle percentages and do calculations with it easy. It supports normal percenta...

◆ operator==() [3/3]

bool operator== ( const string &  init_percentage,
const scifir::percentage x 
)

Returns true if x and the percentage constructed with init_percentage are equal.

Definition at line 610 of file percentage.cpp.

611{
612 scifir::percentage y = scifir::percentage(init_percentage);
613 return (x == y);
614}

◆ operator>()

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.

Definition at line 577 of file percentage.cpp.

578{
579 if(x.get_value() > y.get_value())
580 {
581 return true;
582 }
583 else
584 {
585 return false;
586 }
587}

◆ operator>=()

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.

Definition at line 594 of file percentage.cpp.

595{
596 return !(x < y);
597}

◆ operator>>()

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

Allows that an istream initializes by string a percentage x.

Definition at line 649 of file percentage.cpp.

650{
651 char a[256];
652 is.getline(a, 256);
653 string b(a);
654 boost::trim(b);
655 x = scifir::percentage(b);
656 return is;
657}