swift
Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
swift::misc::physical_quantities::CMeasurementUnit Class Reference

Base class for all units, such as meter, hertz. More...

Inheritance diagram for swift::misc::physical_quantities::CMeasurementUnit:
[legend]

Classes

struct  AffineConverter
 Concrete strategy pattern for converting unit with offset linear conversion. More...
 
struct  Centi
 Metapolicy that can be used to modify template parameters of converters. More...
 
struct  Data
 Pimpl class. More...
 
struct  Giga
 Metapolicy that can be used to modify template parameters of converters. More...
 
struct  Hecto
 Metapolicy that can be used to modify template parameters of converters. More...
 
struct  IdentityConverter
 Concrete strategy pattern for converting unit that does nothing. More...
 
struct  InEachHundred
 Metapolicy that can be used to modify template parameters of converters. More...
 
struct  Kilo
 Metapolicy that can be used to modify template parameters of converters. More...
 
struct  LinearConverter
 Concrete strategy pattern for converting unit with linear conversion. More...
 
struct  Mega
 Metapolicy that can be used to modify template parameters of converters. More...
 
struct  Milli
 Metapolicy that can be used to modify template parameters of converters. More...
 
struct  NilConverter
 Converter for default values, such as None, used with public constructor. More...
 
struct  One
 Metapolicy that can be used to modify template parameters of converters. More...
 
struct  SubdivisionConverter
 Concrete strategy pattern for converting unit with one subdivision conversion. More...
 
struct  SubdivisionConverter2
 Concrete strategy pattern for converting unit with two subdivision conversions. More...
 
struct  Two
 Metapolicy that can be used to modify template parameters of converters. More...
 

Public Member Functions

QString convertToQString (bool i18n=false) const
 Cast as QString. More...
 
void marshallToDbus (QDBusArgument &argument) const
 Marshall without begin/endStructure, for when composed within another object. More...
 
void unmarshallFromDbus (const QDBusArgument &)
 Unmarshall without begin/endStructure, for when composed within another object. More...
 
void marshalToDataStream (QDataStream &stream) const
 Marshal a value to a QDataStream. More...
 
void unmarshalFromDataStream (QDataStream &)
 Unmarshal a value from a QDataStream. More...
 
QString getName (bool i18n=false) const
 Name such as "meter".
 
QString getSymbol (bool i18n=false) const
 Unit name such as "m".
 
bool endsStringWithNameOrSymbol (const QString &candidate, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 Does a string end with name or symbol? E.g. 3meter, 3m, 3deg.
 
double roundValue (double value, int digits=-1) const
 Rounded value. More...
 
double roundToEpsilon (double value) const
 Rounded to the nearest CMeasurementUnit::getEpsilon. More...
 
virtual QString makeRoundedQString (double value, int digits=-1, bool withGroupSeparator=false, bool i18n=false) const
 Rounded string utility method, virtual so units can have specialized formatting. More...
 
virtual QString makeRoundedQStringWithUnit (double value, int digits=-1, bool withGroupSeparator=false, bool i18n=false) const
 Value rounded with unit, e.g. "5.00m", "30kHz". More...
 
double getEpsilon () const
 Threshold for comparions.
 
int getDisplayDigits () const
 Display digits.
 
double convertFrom (double value, const CMeasurementUnit &unit) const
 Convert from other unit to this unit.
 
bool isEpsilon (double value) const
 Is given value <= epsilon?
 
bool isNull () const
 Is unit null?
 
- Public Member Functions inherited from swift::misc::mixin::String< CMeasurementUnit >
QString toQString (bool i18n=false) const
 Cast as QString.
 
std::string toStdString (bool i18n=false) const
 To std string.
 
QString stringForStreaming () const
 String for streaming operators.
 
- Public Member Functions inherited from swift::misc::mixin::Icon< CMeasurementUnit >
CIcons::IconIndex toIcon () const
 As icon, not implemented by all classes.
 

Static Public Member Functions

template<class U >
static U unitFromSymbol (const QString &symbol, bool strict=true)
 Unit from symbol. More...
 
template<class U >
static const QStringList & allSymbols ()
 All symbols.
 
template<class U >
static const QStringList & allSymbolsLowerCase ()
 All symbols case insensitive.
 
template<class U >
static bool hasCaseSensitiveSymbols ()
 Are symbols case sensitive?
 
template<class U >
static bool isValidUnitSymbol (const QString &symbol)
 Valid unit symbol? More...
 
template<class U >
static bool isValidUnitSymbol (const QString &symbol, Qt::CaseSensitivity caseSensitivity)
 Valid unit symbol? More...
 
template<class U >
static bool containsValidUnitSymbol (const QString &candidate, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive)
 Contains valid unit symbol? More...
 
template<class U >
static bool endWithValidUnitSymbol (const QString &candidate, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive)
 Ends with valid unit symbol? More...
 
static CMeasurementUnit None ()
 Dimensionless unit.
 

Protected Types

using ConverterFunction = double(*)(double)
 Pointer to function for converting between units.
 

Protected Member Functions

 CMeasurementUnit (const Data &data)
 Constructor.
 
 CMeasurementUnit (const Data &&)=delete
 Constructor saves the address of its argument, so forbid rvalues.
 
 ~CMeasurementUnit ()=default
 Destructor.
 
 CMeasurementUnit (const CMeasurementUnit &)=default
 Copy constructor.
 
CMeasurementUnitoperator= (const CMeasurementUnit &)=default
 Copy assignment operator.
 

Static Protected Member Functions

template<int N>
static constexpr QLatin1String constQLatin1 (const char(&str)[N])
 Constant-initialize QLatin1String without using strlen.
 

Friends

bool operator== (const CMeasurementUnit &a, const CMeasurementUnit &b)
 Equal operator ==.
 
bool operator!= (const CMeasurementUnit &a, const CMeasurementUnit &b)
 Unequal operator !=.
 
size_t qHash (const CMeasurementUnit &unit)
 qHash overload, needed for storing value in a QSet. More...
 

Detailed Description

Base class for all units, such as meter, hertz.

Definition at line 36 of file measurementunit.h.

Member Function Documentation

◆ containsValidUnitSymbol()

template<class U >
static bool swift::misc::physical_quantities::CMeasurementUnit::containsValidUnitSymbol ( const QString &  candidate,
Qt::CaseSensitivity  caseSensitivity = Qt::CaseSensitive 
)
inlinestatic

Contains valid unit symbol?

Parameters
candidateto be tested
caseSensitivitycheck case sensitiv?

Definition at line 459 of file measurementunit.h.

◆ convertToQString()

QString swift::misc::physical_quantities::CMeasurementUnit::convertToQString ( bool  i18n = false) const
inline

Cast as QString.

Definition at line 262 of file measurementunit.h.

◆ endWithValidUnitSymbol()

template<class U >
static bool swift::misc::physical_quantities::CMeasurementUnit::endWithValidUnitSymbol ( const QString &  candidate,
Qt::CaseSensitivity  caseSensitivity = Qt::CaseSensitive 
)
inlinestatic

Ends with valid unit symbol?

Parameters
candidateto be tested
caseSensitivitycheck case sensitiv?

Definition at line 476 of file measurementunit.h.

◆ isValidUnitSymbol() [1/2]

template<class U >
static bool swift::misc::physical_quantities::CMeasurementUnit::isValidUnitSymbol ( const QString &  symbol)
inlinestatic

Valid unit symbol?

Parameters
symbolto be tested

Definition at line 430 of file measurementunit.h.

◆ isValidUnitSymbol() [2/2]

template<class U >
static bool swift::misc::physical_quantities::CMeasurementUnit::isValidUnitSymbol ( const QString &  symbol,
Qt::CaseSensitivity  caseSensitivity 
)
inlinestatic

Valid unit symbol?

Parameters
symbolto be tested
caseSensitivitycheck case sensitiv?

Definition at line 443 of file measurementunit.h.

◆ makeRoundedQString()

QString swift::misc::physical_quantities::CMeasurementUnit::makeRoundedQString ( double  value,
int  digits = -1,
bool  withGroupSeparator = false,
bool  i18n = false 
) const
virtual

Rounded string utility method, virtual so units can have specialized formatting.

Note
default digits is CMeasurementUnit::getDisplayDigits

Definition at line 40 of file measurementunit.cpp.

◆ makeRoundedQStringWithUnit()

QString swift::misc::physical_quantities::CMeasurementUnit::makeRoundedQStringWithUnit ( double  value,
int  digits = -1,
bool  withGroupSeparator = false,
bool  i18n = false 
) const
virtual

Value rounded with unit, e.g. "5.00m", "30kHz".

Note
default digits is CMeasurementUnit::getDisplayDigits

Reimplemented in swift::misc::physical_quantities::CTimeUnit, and swift::misc::physical_quantities::CAngleUnit.

Definition at line 22 of file measurementunit.cpp.

◆ marshallToDbus()

void swift::misc::physical_quantities::CMeasurementUnit::marshallToDbus ( QDBusArgument &  argument) const
inline

Marshall without begin/endStructure, for when composed within another object.

Definition at line 265 of file measurementunit.h.

◆ marshalToDataStream()

void swift::misc::physical_quantities::CMeasurementUnit::marshalToDataStream ( QDataStream &  stream) const
inline

Marshal a value to a QDataStream.

Definition at line 276 of file measurementunit.h.

◆ roundToEpsilon()

double swift::misc::physical_quantities::CMeasurementUnit::roundToEpsilon ( double  value) const

Rounded to the nearest CMeasurementUnit::getEpsilon.

Remarks
uses CMathUtils::roundEpsilon

Definition at line 34 of file measurementunit.cpp.

◆ roundValue()

double swift::misc::physical_quantities::CMeasurementUnit::roundValue ( double  value,
int  digits = -1 
) const

Rounded value.

Note
default digits is CMeasurementUnit::getDisplayDigits

Definition at line 28 of file measurementunit.cpp.

◆ unitFromSymbol()

template<class U >
static U swift::misc::physical_quantities::CMeasurementUnit::unitFromSymbol ( const QString &  symbol,
bool  strict = true 
)
inlinestatic

Unit from symbol.

Parameters
symbolmust be a valid unit symbol (without i18n) or empty string (empty means default unit)
strictstrict check means if unit is not found, program terminates

Definition at line 367 of file measurementunit.h.

◆ unmarshalFromDataStream()

void swift::misc::physical_quantities::CMeasurementUnit::unmarshalFromDataStream ( QDataStream &  )
inline

Unmarshal a value from a QDataStream.

Definition at line 279 of file measurementunit.h.

◆ unmarshallFromDbus()

void swift::misc::physical_quantities::CMeasurementUnit::unmarshallFromDbus ( const QDBusArgument &  )
inline

Unmarshall without begin/endStructure, for when composed within another object.

Definition at line 268 of file measurementunit.h.

Friends And Related Function Documentation

◆ qHash

size_t qHash ( const CMeasurementUnit unit)
friend

qHash overload, needed for storing value in a QSet.

Definition at line 297 of file measurementunit.h.


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