#include <Quantity.hpp>
Public Member Functions | |
Constructors | |
Quantity (const UnitSystem &system=UnitSystem::Mixed) | |
Quantity (double value, const UnitSystem &system=UnitSystem::Mixed) | |
Quantity (double value, const Unit &units) | |
Quantity (const Quantity &q) | |
Quantity & | operator= (const Quantity &q) |
virtual | ~Quantity ()=default |
Value | |
double | value () const |
void | setValue (double newValue) |
Value setter. More... | |
Units | |
Unit | units () const |
Returns deep copy (clone) of this Quantity's units. More... | |
UnitSystem | system () const |
bool | isTemperature () const |
Returns true if units().optionalCast<TemperatureUnit>(). More... | |
std::vector< std::string > | baseUnits () const |
Vector of base units available to the Quantity. More... | |
int | baseUnitExponent (const std::string &baseUnit) const |
Base unit exponent getter. More... | |
void | setBaseUnitExponent (const std::string &baseUnit, int exponent) |
Sets the exponent of a base unit in this Quantity's m_units. More... | |
std::string | standardUnitsString (bool withScale=true) const |
Units in string form. More... | |
std::string | prettyUnitsString (bool withScale=true) const |
Pretty string for this quantity's units. More... | |
void | setPrettyUnitsString (const std::string &str) |
Sets the prettystring for this Quantity's m_units. More... | |
Scale | scale () const |
Scale getter. More... | |
bool | setScale (int scaleExponent) |
Sets the scale to the one registered in ScaleFactory for 10^scaleExponent. More... | |
bool | setScale (const std::string &scaleAbbreviation) |
Sets the scale to the one registered in ScaleFactory under scaleAbbreviation. More... | |
Temperature Methods | |
Quantities that have units of temperature need several extra functions to distinguish between absolute and relative measures. | |
bool | isAbsolute () const |
Throws if !units().optionalCast<TemperatureUnit>(). More... | |
bool | isRelative () const |
Throws if !units().optionalCast<TemperatureUnit>(). More... | |
void | setAsAbsolute () |
Set temperature as absolute. More... | |
void | setAsRelative () |
Set temperature as relative. More... | |
IP Methods | |
void | lbmToLbf () |
Conversions for pounds mass to pounds force. More... | |
void | lbfToLbm () |
Conversions for pounds mass to pounds force. More... | |
Mathematical Operators | |
Quantity & | operator+= (const Quantity &rQuantity) |
Add and assign operator. More... | |
Quantity & | operator-= (const Quantity &rQuantity) |
Subtract and assign operator. More... | |
Quantity & | operator*= (const Quantity &rQuantity) |
Multiply and assign operator. More... | |
Quantity & | operator/= (const Quantity &rQuantity) |
Divide and assign operator. More... | |
Quantity & | operator*= (double d) |
Multiply by double. More... | |
Quantity & | operator/= (double d) |
Divide by double. More... | |
Quantity & | pow (int expNum, int expDenom=1) |
Raise Quantity to a rational power. More... | |
Protected Attributes | |
Unit | m_units |
double | m_value |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Quantity &q) |
Related Functions | |
(Note that these are not member functions.) | |
std::ostream & | operator<< (std::ostream &os, const Quantity &q) |
using | OptionalQuantity = boost::optional< Quantity > |
using | QuantityVector = std::vector< Quantity > |
Quantity class defines value, unit pairs.
Units are set at construction and are modified by arithmetic operations. The constructors and assignment operator ensure that this class behaves as "plain old data" (POD) by cloning any units information (to avoid multiple objects pointing to the exact same unit data).
|
explicit |
|
explicit |
openstudio::Quantity::Quantity | ( | double | value, |
const Unit & | units | ||
) |
openstudio::Quantity::Quantity | ( | const Quantity & | q | ) |
|
virtualdefault |
int openstudio::Quantity::baseUnitExponent | ( | const std::string & | baseUnit | ) | const |
Base unit exponent getter.
Returns 0 if baseUnit not present.
std::vector<std::string> openstudio::Quantity::baseUnits | ( | ) | const |
Vector of base units available to the Quantity.
bool openstudio::Quantity::isAbsolute | ( | ) | const |
Throws if !units().optionalCast<TemperatureUnit>().
bool openstudio::Quantity::isRelative | ( | ) | const |
Throws if !units().optionalCast<TemperatureUnit>().
bool openstudio::Quantity::isTemperature | ( | ) | const |
Returns true if units().optionalCast<TemperatureUnit>().
void openstudio::Quantity::lbfToLbm | ( | ) |
Conversions for pounds mass to pounds force.
These functions will throw if !units().optionalCast<IPUnit>().
void openstudio::Quantity::lbmToLbf | ( | ) |
Conversions for pounds mass to pounds force.
These functions will throw if !units().optionalCast<IPUnit>().
Multiply and assign operator.
Throws if Quantity is a particular system and rQuantity is not the same system.
Quantity& openstudio::Quantity::operator*= | ( | double | d | ) |
Multiply by double.
No impact to units or scale. Does not throw.
Add and assign operator.
Throws if units are not equal.
Subtract and assign operator.
Throws if units are not equal.
Divide and assign operator.
Throws if Quantity is a particular system and rQuantity is not the same system.
Quantity& openstudio::Quantity::operator/= | ( | double | d | ) |
Divide by double.
No impact to units or scale. Does not throw.
Raise Quantity to a rational power.
Throws openstudio::Exception if expDenom is not a common divisor for all baseUnit and scale exponents. Returned scale exponent may differ from expectation based on initialization of openstudio::ScaleFactory, see Scale operators declared in ScaleFactory.hpp.
std::string openstudio::Quantity::prettyUnitsString | ( | bool | withScale = true | ) | const |
Pretty string for this quantity's units.
For instance N = kg*m/s^2.
void openstudio::Quantity::setAsAbsolute | ( | ) |
Set temperature as absolute.
Throws if !units().optionalCast<TemperatureUnit>().
void openstudio::Quantity::setAsRelative | ( | ) |
Set temperature as relative.
Throws if !units().optionalCast<TemperatureUnit>().
void openstudio::Quantity::setBaseUnitExponent | ( | const std::string & | baseUnit, |
int | exponent | ||
) |
void openstudio::Quantity::setPrettyUnitsString | ( | const std::string & | str | ) |
Sets the prettystring for this Quantity's m_units.
openstudio::Unit attempts to keep up with prettyStrings, but makes no promises. Precondition: isCompoundUnit(str). Otherwise throws.
bool openstudio::Quantity::setScale | ( | int | scaleExponent | ) |
Sets the scale to the one registered in ScaleFactory for 10^scaleExponent.
bool openstudio::Quantity::setScale | ( | const std::string & | scaleAbbreviation | ) |
Sets the scale to the one registered in ScaleFactory under scaleAbbreviation.
void openstudio::Quantity::setValue | ( | double | newValue | ) |
Value setter.
std::string openstudio::Quantity::standardUnitsString | ( | bool | withScale = true | ) | const |
Units in string form.
LaTeX mathematical formatting–_ for subscripting, ^ for superscripting. Curly braces {} are used for grouping.
UnitSystem openstudio::Quantity::system | ( | ) | const |
double openstudio::Quantity::value | ( | ) | const |
|
friend |
|
related |
|
related |
|
related |
|
protected |
|
protected |