QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
unitofmeasure.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
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
24#ifndef quantlib_unit_of_measure_hpp
25#define quantlib_unit_of_measure_hpp
26
27#include <ql/types.hpp>
28#include <ql/math/rounding.hpp>
29#include <ql/shared_ptr.hpp>
30#include <string>
31#include <map>
32#include <iosfwd>
33
34namespace QuantLib {
35
38 public:
41
46 UnitOfMeasure() = default;
47 UnitOfMeasure(const std::string& name,
48 const std::string& code,
51
52
53 const std::string& name() const;
55 const std::string& code() const;
57 Type unitType() const;
59
61
62 bool empty() const;
63 // rounding
64 const Rounding& rounding() const;
68 protected:
69 struct Data;
70 ext::shared_ptr<Data> data_;
71 private:
72 static std::map<std::string, ext::shared_ptr<UnitOfMeasure::Data> >
74 };
75
77 std::string name, code;
81
82 Data(std::string name,
83 std::string code,
86 const Rounding& rounding = Rounding(0));
87 };
88
89
91 bool operator==(const UnitOfMeasure&,
92 const UnitOfMeasure&);
93
95 bool operator!=(const UnitOfMeasure&,
96 const UnitOfMeasure&);
97
99 std::ostream& operator<<(std::ostream&,
100 const UnitOfMeasure&);
101
102
103 // inline definitions
104
105 inline const std::string& UnitOfMeasure::name() const {
106 return data_->name;
107 }
108
109 inline const std::string& UnitOfMeasure::code() const {
110 return data_->code;
111 }
112
114 return data_->unitType;
115 }
116
117 inline const Rounding& UnitOfMeasure::rounding() const {
118 return data_->rounding;
119 }
120
121 inline bool UnitOfMeasure::empty() const {
122 return !data_;
123 }
124
125 inline const UnitOfMeasure&
127 return data_->triangulationUnitOfMeasure;
128 }
129
130 inline bool operator==(const UnitOfMeasure& c1, const UnitOfMeasure& c2) {
131 return c1.code() == c2.code();
132 }
133
134 inline bool operator!=(const UnitOfMeasure& c1, const UnitOfMeasure& c2) {
135 return !(c1 == c2);
136 }
137
139 public:
141 static ext::shared_ptr<Data> data(
142 new Data("Lot", "Lot", UnitOfMeasure::Quantity));
143 data_ = data;
144 }
145 };
146
147}
148
149
150#endif
Amount of a commodity.
Definition: quantity.hpp:34
basic rounding class
Definition: rounding.hpp:35
Unit of measure specification
const UnitOfMeasure & triangulationUnitOfMeasure() const
unit used for triangulation when required
const Rounding & rounding() const
const std::string & code() const
code, e.g, "BBL", "MT"
const std::string & name() const
name, e.g, "Barrels"
bool empty() const
is this a usable instance?
static std::map< std::string, ext::shared_ptr< UnitOfMeasure::Data > > unitsOfMeasure_
Type unitType() const
unit type (mass, volume...)
ext::shared_ptr< Data > data_
UnitOfMeasure()=default
default constructor
Definition: any.hpp:35
bool operator==(const Currency &c1, const Currency &c2)
Definition: currency.hpp:191
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
bool operator!=(const Currency &c1, const Currency &c2)
Definition: currency.hpp:196
UnitOfMeasure::Type unitType
UnitOfMeasure triangulationUnitOfMeasure