A unit of measurement, plus conversion to pretty-printed output.
More...
#include <Unit.h>
|
enum | UnitType {
UNIT_FS
, UNIT_HZ
, UNIT_VOLTS
, UNIT_AMPS
,
UNIT_OHMS
, UNIT_BITRATE
, UNIT_PERCENT
, UNIT_DB
,
UNIT_DBM
, UNIT_COUNTS
, UNIT_COUNTS_SCI
, UNIT_LOG_BER
,
UNIT_RATIO_SCI
, UNIT_SAMPLERATE
, UNIT_SAMPLEDEPTH
, UNIT_WATTS
,
UNIT_UI
, UNIT_DEGREES
, UNIT_RPM
, UNIT_CELSIUS
,
UNIT_RHO
, UNIT_HEXNUM
, UNIT_PM
, UNIT_MILLIVOLTS
,
UNIT_MICROVOLTS
, UNIT_VOLT_SEC
, UNIT_BYTES
, UNIT_W_M2_NM
,
UNIT_W_M2
, UNIT_MICROAMPS
, UNIT_FARADS
} |
|
|
| Unit (Unit::UnitType t=UNIT_COUNTS) |
|
| Unit (const std::string &rhs) |
|
std::string | ToString () const |
| Converts this unit to a string.
|
|
std::string | PrettyPrint (double value, int sigfigs=-1, bool useDisplayLocale=true) const |
| Prints a value with SI scaling factors. More...
|
|
std::string | PrettyPrintInt64 (int64_t value, int sigfigs=-1, bool useDisplayLocale=true) const |
| Prints a value with SI scaling factors. More...
|
|
std::string | PrettyPrintRange (double pixelMin, double pixelMax, double rangeMin, double rangeMax) const |
| Prints a value with SI scaling factors and unnecessarily significant sub-pixel digits removed. More...
|
|
double | ParseString (const std::string &str, bool useDisplayLocale=true) |
| Parses a string based on the supplied unit. More...
|
|
int64_t | ParseStringInt64 (const std::string &str, bool useDisplayLocale=true) |
| Parses a string based on the supplied unit. More...
|
|
UnitType | GetType () |
|
bool | operator== (const Unit &rhs) |
|
bool | operator!= (const Unit &rhs) |
|
bool | operator!= (UnitType rhs) |
|
Unit | operator* (const Unit &rhs) |
| Multiplies two units and calculates the resulting unit.
|
|
Unit | operator/ (const Unit &rhs) |
| Divides two units and calculates the resulting unit.
|
|
|
static void | SetLocale (const char *locale) |
|
|
void | GetSIScalingFactor (double num, double &scaleFactor, std::string &prefix) const |
| Gets the appropriate SI scaling factor for a number.
|
|
void | GetUnitSuffix (UnitType type, double num, double &scaleFactor, std::string &prefix, std::string &numprefix, std::string &suffix) const |
| Gets the suffix for a unit. More...
|
|
|
static void | SetPrintingLocale () |
| Sets the current locale to the user's selected LC_NUMERIC for printing numbers for display.
|
|
static void | SetDefaultLocale () |
| Sets the current locale to "C" for interchange.
|
|
|
static locale_t | m_locale |
| The user's requested locale for display.
|
|
static locale_t | m_defaultLocale |
| Handle to the "C" locale, used for interchange.
|
|
A unit of measurement, plus conversion to pretty-printed output.
TODO: add scale factors too?
◆ GetUnitSuffix()
void Unit::GetUnitSuffix |
( |
UnitType |
type, |
|
|
double |
num, |
|
|
double & |
scaleFactor, |
|
|
std::string & |
prefix, |
|
|
std::string & |
numprefix, |
|
|
std::string & |
suffix |
|
) |
| const |
|
protected |
Gets the suffix for a unit.
Note that this function may modify the SI scale factor and prefix
◆ ParseString()
double Unit::ParseString |
( |
const std::string & |
str, |
|
|
bool |
useDisplayLocale = true |
|
) |
| |
Parses a string based on the supplied unit.
- Parameters
-
str | The string to parse |
useDisplayLocale | True if the string is formatted for display (user's locale) False if the string is formatted for serialization ("C" locale regardless of user pref) |
◆ ParseStringInt64()
int64_t Unit::ParseStringInt64 |
( |
const std::string & |
str, |
|
|
bool |
useDisplayLocale = true |
|
) |
| |
Parses a string based on the supplied unit.
- Parameters
-
str | The string to parse |
useDisplayLocale | True if the string is formatted for display (user's locale) False if the string is formatted for serialization ("C" locale regardless of user pref) |
◆ PrettyPrint()
string Unit::PrettyPrint |
( |
double |
value, |
|
|
int |
sigfigs = -1 , |
|
|
bool |
useDisplayLocale = true |
|
) |
| const |
Prints a value with SI scaling factors.
- Parameters
-
value | The value |
digits | Number of significant digits to display |
useDisplayLocale | True if the string is formatted for display (user's locale) False if the string is formatted for serialization ("C" locale regardless of user pref) |
◆ PrettyPrintInt64()
string Unit::PrettyPrintInt64 |
( |
int64_t |
value, |
|
|
int |
sigfigs = -1 , |
|
|
bool |
useDisplayLocale = true |
|
) |
| const |
Prints a value with SI scaling factors.
- Parameters
-
value | The value |
digits | Number of significant digits to display |
useDisplayLocale | True if the string is formatted for display (user's locale) False if the string is formatted for serialization ("C" locale regardless of user pref) |
◆ PrettyPrintRange()
string Unit::PrettyPrintRange |
( |
double |
pixelMin, |
|
|
double |
pixelMax, |
|
|
double |
rangeMin, |
|
|
double |
rangeMax |
|
) |
| const |
Prints a value with SI scaling factors and unnecessarily significant sub-pixel digits removed.
The rangeMin/rangeMax values are typically used to ensure all axis labels on a graph use consistent units, for example 0.5V / 1.0V / 1.5V rather than 500 mV / 1.0V / 1.5V.
The pixelMin and pixelMax values are used to determine how many digits are actually significant. Rounding is in the upward direction.
For example, if the pixel covers values 1.3979 to 1.4152, this function will return "1.4".
- Parameters
-
pixelMin | Value at the lowest end of the pixel being labeled |
pixelMax | Value at the highest end of the pixel being labeled |
rangeMin | Value at the lowest end of the channel range |
rangeMax | Value at the highest end of the channel range |
The documentation for this class was generated from the following files: