Public Member Functions | Protected Attributes | List of all members
cUnitConverter Class Reference

Unit conversion class to convert values between physical unit systems. More...

#include <unit_converter.h>

Public Member Functions

 cUnitConverter (char const *_kind, char const *_name, char const *_symbol, double _factor=1.0, double _offset=0.0, int _decimal_places=1)
 
int GetDecimalPlaces (void) const
 Return the number of decimal places for printing values in the external unit system. More...
 
double GetFactor (void) const
 Return the conversion factor from internal to external units. More...
 
char const * GetKind (void) const
 Return the kind of unit converted (something like "angle" or "time") More...
 
char const * GetName (void) const
 Return the name of the external unit (something like "degrees" or "milliseconds") More...
 
double GetOffset (void) const
 Return the conversion offset from internal to external units. More...
 
char const * GetSymbol (void) const
 Return the symbol of the external unit (something like "deg" or "ms") More...
 
cSimpleVector ToExternal (cSimpleVector &internal) const
 
double ToExternal (double internal) const
 
std::vector< double > ToExternal (std::vector< double > const &internal) const
 
cSimpleVector ToInternal (cSimpleVector &external) const
 
double ToInternal (double external) const
 
std::vector< double > ToInternal (std::vector< double > const &external) const
 

Protected Attributes

int decimal_places
 A usefull number of decimal places for printing values in the external unit system. More...
 
double factor
 the conversion factor from internal to external units More...
 
char const * kind
 the kind of unit to be converted (something like "angle" or "time") More...
 
char const * name
 the name of the external unit (something like "degrees" or "milliseconds") More...
 
double offset
 the conversion offset from internal to external units More...
 
char const * symbol
 the symbol of the external unit (something like "deg" or "ms") More...
 

Detailed Description

Unit conversion class to convert values between physical unit systems.

An object of this class can be configured to convert values of a physical unit between 2 physical unit systems. An angle value given in degrees can e.g. be converted from/to radians or vice versa by an object of this class.


Definition at line 75 of file unit_converter.h.

Constructor & Destructor Documentation

◆ cUnitConverter()

USING_NAMESPACE_SDH cUnitConverter::cUnitConverter ( char const *  _kind,
char const *  _name,
char const *  _symbol,
double  _factor = 1.0,
double  _offset = 0.0,
int  _decimal_places = 1 
)

Constructor of cUnitConverter class.

At construction time the conversion parameters - a factor and an offset - must be provided along with elements that describe the unit of a value

Parameters
_kind- a string describing the kind of unit to be converted (something like "angle" or "time")
_name- the name of the external unit (something like "degrees" or "milliseconds")
_symbol- the symbol of the external unit (something like "deg" or "ms")
_factor- the conversion factor from internal to external units
_offset- the conversion offset from internal to external units
_decimal_places- A usefull number of decimal places for printing values in the external unit system
Attention
The strings given _kind, _name and _symbol are NOT copied, just their address is stored

Definition at line 68 of file unit_converter.cpp.

Member Function Documentation

◆ GetDecimalPlaces()

int cUnitConverter::GetDecimalPlaces ( void  ) const

Return the number of decimal places for printing values in the external unit system.

Definition at line 191 of file unit_converter.cpp.

◆ GetFactor()

double cUnitConverter::GetFactor ( void  ) const

Return the conversion factor from internal to external units.

Definition at line 175 of file unit_converter.cpp.

◆ GetKind()

char const * cUnitConverter::GetKind ( void  ) const

Return the kind of unit converted (something like "angle" or "time")

Definition at line 154 of file unit_converter.cpp.

◆ GetName()

char const * cUnitConverter::GetName ( void  ) const

Return the name of the external unit (something like "degrees" or "milliseconds")

Definition at line 161 of file unit_converter.cpp.

◆ GetOffset()

double cUnitConverter::GetOffset ( void  ) const

Return the conversion offset from internal to external units.

Definition at line 183 of file unit_converter.cpp.

◆ GetSymbol()

char const * cUnitConverter::GetSymbol ( void  ) const

Return the symbol of the external unit (something like "deg" or "ms")

Definition at line 168 of file unit_converter.cpp.

◆ ToExternal() [1/3]

cSimpleVector cUnitConverter::ToExternal ( cSimpleVector internal) const

Convert values in simple array internal, each given in internal units into external units. Returns a simple array with each valid element converted with internal[i] * factor + offset

Only valid entries of the internal vector are converted.

Definition at line 89 of file unit_converter.cpp.

◆ ToExternal() [2/3]

double cUnitConverter::ToExternal ( double  internal) const

Convert single value internal given in internal units into external units. Returns internal * factor + offset

Definition at line 82 of file unit_converter.cpp.

◆ ToExternal() [3/3]

std::vector< double > cUnitConverter::ToExternal ( std::vector< double > const &  internal) const

Convert values in vector internal, each given in internal units into external units. Returns a vector with each element converted with internal[i] * factor + offset

Definition at line 103 of file unit_converter.cpp.

◆ ToInternal() [1/3]

cSimpleVector cUnitConverter::ToInternal ( cSimpleVector external) const

Convert values in simple array external, each given in external units into internal units. Returns a simple array with each valid element converted with external[i] * factor + offset

Only valid entries of the external vector are converted.

Definition at line 125 of file unit_converter.cpp.

◆ ToInternal() [2/3]

double cUnitConverter::ToInternal ( double  external) const

Convert value external given in external units into internal units. Returns (external - offset) / factor

Definition at line 118 of file unit_converter.cpp.

◆ ToInternal() [3/3]

std::vector< double > cUnitConverter::ToInternal ( std::vector< double > const &  external) const

Convert values in vector external, each given in external units into internal units. Returns a vector with each valid element converted with external[i] * factor + offset

Definition at line 139 of file unit_converter.cpp.

Member Data Documentation

◆ decimal_places

int cUnitConverter::decimal_places
protected

A usefull number of decimal places for printing values in the external unit system.

Definition at line 198 of file unit_converter.h.

◆ factor

double cUnitConverter::factor
protected

the conversion factor from internal to external units

Definition at line 192 of file unit_converter.h.

◆ kind

char const* cUnitConverter::kind
protected

the kind of unit to be converted (something like "angle" or "time")

Definition at line 183 of file unit_converter.h.

◆ name

char const* cUnitConverter::name
protected

the name of the external unit (something like "degrees" or "milliseconds")

Definition at line 186 of file unit_converter.h.

◆ offset

double cUnitConverter::offset
protected

the conversion offset from internal to external units

Definition at line 195 of file unit_converter.h.

◆ symbol

char const* cUnitConverter::symbol
protected

the symbol of the external unit (something like "deg" or "ms")

Definition at line 189 of file unit_converter.h.


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


sdhlibrary_cpp
Author(s): Dirk Osswald
autogenerated on Wed Mar 2 2022 01:00:59