33 void convertTo(Quantity& m,
const UnitOfMeasure& target) {
34 if (m.unitOfMeasure() != target) {
35 UnitOfMeasureConversion
rate =
37 m.commodityType(), m.unitOfMeasure(), target);
38 m =
rate.convert(m).rounded();
42 void convertToBase(Quantity& m) {
44 "no base unitOfMeasure set");
63 QL_FAIL(
"unitOfMeasure mismatch and no conversion specified");
81 QL_FAIL(
"unitOfMeasure mismatch and no conversion specified");
101 QL_FAIL(
"unitOfMeasure mismatch and no conversion specified");
121 QL_FAIL(
"unitOfMeasure mismatch and no conversion specified");
140 QL_FAIL(
"unitOfMeasure mismatch and no conversion specified");
159 QL_FAIL(
"unitOfMeasure mismatch and no conversion specified");
172 return close(tmp1,tmp2,
n);
178 QL_FAIL(
"unitOfMeasure mismatch and no conversion specified");
197 QL_FAIL(
"unitOfMeasure mismatch and no conversion specified");
const std::string & code() const
commodity code, e.g, "HO"
static ConversionType conversionType
UnitOfMeasure unitOfMeasure_
static UnitOfMeasure baseUnitOfMeasure
Quantity & operator-=(const Quantity &)
CommodityType commodityType_
@ BaseUnitOfMeasureConversion
Quantity & operator+=(const Quantity &)
const UnitOfMeasure & unitOfMeasure() const
static UnitOfMeasureConversionManager & instance()
access to the unique instance
UnitOfMeasureConversion lookup(const CommodityType &commodityType, const UnitOfMeasure &, const UnitOfMeasure &, UnitOfMeasureConversion::Type type=UnitOfMeasureConversion::Derived) const
const std::string & code() const
code, e.g, "BBL", "MT"
floating-point comparisons
Classes and functions for error handling.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
detail::percent_holder rate(Rate)
output rates and spreads as percentages
std::size_t Size
size of a container
bool operator==(const Currency &c1, const Currency &c2)
bool operator<(const Quantity &m1, const Quantity &m2)
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
bool close(const Quantity &m1, const Quantity &m2, Size n)
bool operator<=(const Quantity &m1, const Quantity &m2)
bool close_enough(const Quantity &m1, const Quantity &m2, Size n)
Real operator/(const Quantity &m1, const Quantity &m2)
Unit-of-measure conversion manager.