Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
sf::UnitConverter Class Reference

unit conversion class to easy the pain of conversions in dialogs. More...

#include <UnitConversion.h>

Public Member Functions

 UnitConverter ()=default
 Default constructor.
 
 UnitConverter (const std::string &unit, int sig_digits)
 Initializing constructor.
 
bool set (const std::string &unit, int sig_digits)
 Retrieves the unit conversion using the passed values.
 
bool set ()
 Retrieves the unit conversion using the current set values
and passes them to the global function getUnitConversion.
 
double getValue (double value) const
 Gets the converted value from an original one.
 
std::string getString (double value) const
 Returns the converted value as a string using the digits.
 
std::string getUnit () const
 Returns the unit after conversion.
 
int getSigDigits () const
 Gets the significant digits after conversion.
 
bool isValid () const
 Returns if there is a valid conversion present.
 
double getOrgValue (double value) const
 Gets original value from the past converted value.
 
double getOrgValue (const std::string &value, double def=0.0) const
 Gets the original value from the past string which may contain a calculation.
 
void clear ()
 Clear the conversion and make it invalid.
 

Detailed Description

unit conversion class to easy the pain of conversions in dialogs.

Used dialogs to convert SI-unit's to be displayed as required and to store them as SI-units.
When performing scientific formula calculations in applications there is no need for obscure conversions since all values are in SI-units.

Constructor & Destructor Documentation

◆ UnitConverter() [1/2]

sf::UnitConverter::UnitConverter ( )
default

Default constructor.

◆ UnitConverter() [2/2]

sf::UnitConverter::UnitConverter ( const std::string &  unit,
int  sig_digits 
)
inline

Initializing constructor.

Parameters
unitOriginal unit.
sig_digitsOriginal significant digits.

Member Function Documentation

◆ clear()

void sf::UnitConverter::clear ( )
inline

Clear the conversion and make it invalid.

Clearing makes this class pass through values unconverted.

◆ getOrgValue() [1/2]

double sf::UnitConverter::getOrgValue ( const std::string &  value,
double  def = 0.0 
) const

Gets the original value from the past string which may contain a calculation.

Calculations like:

  • "2*20+3"
  • "PI and sin(PI/2)"

This method parses the string and calls the other getOrgValue().

Parameters
valueString value to parse and to convert.
defDefault value when parsing the string fails.
Returns
Original non converted value.

◆ getOrgValue() [2/2]

double sf::UnitConverter::getOrgValue ( double  value) const

Gets original value from the past converted value.

Turns converted value into original one.

Parameters
valueConverted value.
Returns
Original non converted value.

◆ getSigDigits()

int sf::UnitConverter::getSigDigits ( ) const
inline

Gets the significant digits after conversion.

Returns
If no valid conversion the original unit is returned.

◆ getString()

std::string sf::UnitConverter::getString ( double  value) const

Returns the converted value as a string using the digits.

Used to display this value appropriately.

Parameters
valueValue to turn into string.
Returns
Value formatted into string using the digits.

◆ getUnit()

std::string sf::UnitConverter::getUnit ( ) const
inline

Returns the unit after conversion.

Returns
If no valid conversion the original unit is returned.

◆ getValue()

double sf::UnitConverter::getValue ( double  value) const

Gets the converted value from an original one.

If not valid the passed value is returned in changed.

Parameters
valueOriginal value.
Returns
Converted value of the passed value.

◆ isValid()

bool sf::UnitConverter::isValid ( ) const
inline

Returns if there is a valid conversion present.

Returns
True when valid.

◆ set() [1/2]

bool sf::UnitConverter::set ( )

Retrieves the unit conversion using the current set values
and passes them to the global function getUnitConversion.

Returns
True when successful.

◆ set() [2/2]

bool sf::UnitConverter::set ( const std::string &  unit,
int  sig_digits 
)

Retrieves the unit conversion using the passed values.

Parameters
unitOriginal unit.
sig_digitsOriginal significant digits.
Returns
True when successful.

The documentation for this class was generated from the following file: