32 bool matches(
const UnitOfMeasureConversion& c1,
33 const UnitOfMeasureConversion& c2) {
34 return c1.commodityType() == c2.commodityType() &&
35 ((c1.source() == c2.source() && c1.target() == c2.target())
36 || (c1.source() == c2.target() && c1.target() == c2.source()));
39 bool matches(
const UnitOfMeasureConversion& c,
40 const CommodityType& commodityType,
41 const UnitOfMeasure& source,
42 const UnitOfMeasure& target) {
43 return c.commodityType() == commodityType &&
44 ((c.source() == source && c.target() == target)
45 || (c.source() == target && c.target() == source));
48 bool matches(
const UnitOfMeasureConversion& c,
49 const CommodityType& commodityType,
50 const UnitOfMeasure& source) {
51 return c.commodityType() == commodityType &&
52 (c.source() == source || c.target() == source);
63 for (
auto i =
data_.begin(); i !=
data_.end(); ++i) {
87 lookup(commodityType,link,target));
94 lookup(commodityType,source,link),
142 for (
const auto& i :
data_) {
143 if (matches(i, commodityType, source, target)) {
160 QL_FAIL(
"no direct conversion available from "
161 << commodityType.
code() <<
" " << source.
code()
162 <<
" to " << target.
code());
169 list<string> forbidden)
const {
179 forbidden.push_back(source.
code());
181 for (
const auto& i :
data_) {
183 if (matches(i, commodityType, source)) {
184 const UnitOfMeasure& other = source == i.source() ? i.target() : i.source();
185 if (find(forbidden.begin(),forbidden.end(),
186 other.
code()) == forbidden.end()) {
203 QL_FAIL(
"no conversion available for "
204 << commodityType.
code() <<
" from "
205 << source.
code() <<
" to " << target.
code());
const std::string & code() const
commodity code, e.g, "HO"
static UnitOfMeasureConversion chain(const UnitOfMeasureConversion &r1, const UnitOfMeasureConversion &r2)
chain two conversion factors
void add(const UnitOfMeasureConversion &)
UnitOfMeasureConversion lookup(const CommodityType &commodityType, const UnitOfMeasure &, const UnitOfMeasure &, UnitOfMeasureConversion::Type type=UnitOfMeasureConversion::Derived) const
std::list< UnitOfMeasureConversion > data_
void addKnownConversionFactors()
UnitOfMeasureConversionManager()
UnitOfMeasureConversion smartLookup(const CommodityType &commodityType, const UnitOfMeasure &source, const UnitOfMeasure &target, std::list< std::string > forbidden=std::list< std::string >()) const
UnitOfMeasureConversion directLookup(const CommodityType &commodityType, const UnitOfMeasure &source, const UnitOfMeasure &target) const
Unit of measure specification
const UnitOfMeasure & triangulationUnitOfMeasure() const
unit used for triangulation when required
const std::string & code() const
code, e.g, "BBL", "MT"
bool empty() const
is this a usable instance?
Classes and functions for error handling.
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Petroleum units of measure.
Unit-of-measure conversion manager.