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... | |
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.
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
_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 |
Definition at line 68 of file unit_converter.cpp.
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.
double cUnitConverter::GetFactor | ( | void | ) | const |
Return the conversion factor from internal to external units.
Definition at line 175 of file unit_converter.cpp.
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.
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.
double cUnitConverter::GetOffset | ( | void | ) | const |
Return the conversion offset from internal to external units.
Definition at line 183 of file unit_converter.cpp.
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.
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.
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.
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.
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.
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.
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.
|
protected |
A usefull number of decimal places for printing values in the external unit system.
Definition at line 198 of file unit_converter.h.
|
protected |
the conversion factor from internal to external units
Definition at line 192 of file unit_converter.h.
|
protected |
the kind of unit to be converted (something like "angle" or "time")
Definition at line 183 of file unit_converter.h.
|
protected |
the name of the external unit (something like "degrees" or "milliseconds")
Definition at line 186 of file unit_converter.h.
|
protected |
the conversion offset from internal to external units
Definition at line 195 of file unit_converter.h.
|
protected |
the symbol of the external unit (something like "deg" or "ms")
Definition at line 189 of file unit_converter.h.