QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
unitofmeasureconversion.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 J. Erik Radmall
5 Copyright (C) 2009 StatPro Italia srl
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
25#ifndef quantlib_unit_of_measure_conversion_hpp
26#define quantlib_unit_of_measure_conversion_hpp
27
28#include <ql/experimental/commodities/quantity.hpp>
29#include <ql/experimental/commodities/unitofmeasure.hpp>
30#include <ql/utilities/null.hpp>
31#include <utility>
32
33namespace QuantLib {
34
36 public:
37 enum Type { Direct,
38 Derived
40 };
42
49 const UnitOfMeasure& source,
50 const UnitOfMeasure& target,
53
55
56
57 const UnitOfMeasure& source() const;
59 const UnitOfMeasure& target() const;
61 const CommodityType& commodityType() const;
63 Type type() const;
65 Real conversionFactor() const;
66
67 const std::string& code() const;
69
71
72
73 Quantity convert(const Quantity& quantity) const;
76 const UnitOfMeasureConversion& r2);
78 protected:
80 const UnitOfMeasureConversion& r2);
81
82 struct Data;
83 ext::shared_ptr<Data> data_;
84
85 struct Data {
90 std::string code;
91 std::pair<ext::shared_ptr<UnitOfMeasureConversion>,
92 ext::shared_ptr<UnitOfMeasureConversion> >
94
96 const UnitOfMeasure& source,
97 const UnitOfMeasure& target,
99 Type type);
100
102 const UnitOfMeasureConversion& r2);
103 };
104 };
105
106 // inline definitions
107
109 return data_->commodityType;
110 }
111
113 return data_->source;
114 }
115
117 return data_->target;
118 }
119
121 return data_->conversionFactor;
122 }
123
125 return data_->type;
126 }
127
128 inline const std::string& UnitOfMeasureConversion::code() const {
129 return data_->code;
130 }
131
132}
133
134#endif
Amount of a commodity.
Definition: quantity.hpp:34
const UnitOfMeasure & source() const
the source UOM.
Quantity convert(const Quantity &quantity) const
apply the conversion factor to a cash amount
const UnitOfMeasure & target() const
the target UOM.
Real conversionFactor() const
the conversion factor
const CommodityType & commodityType() const
the commodity type.
static UnitOfMeasureConversion chain(const UnitOfMeasureConversion &r1, const UnitOfMeasureConversion &r2)
chain two conversion factors
Unit of measure specification
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
std::pair< ext::shared_ptr< UnitOfMeasureConversion >, ext::shared_ptr< UnitOfMeasureConversion > > conversionFactorChain