QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
commoditytype.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_commodity_type_hpp
25#define quantlib_commodity_type_hpp
26
27#include <ql/qldefines.hpp>
28#include <ql/shared_ptr.hpp>
29#include <iosfwd>
30#include <map>
31#include <string>
32#include <utility>
33
34namespace QuantLib {
35
38 public:
40
45 CommodityType() = default;
46 CommodityType(const std::string& code, const std::string& name);
48
49
50 const std::string& code() const;
52 const std::string& name() const;
53 // commodity code
55
57
58 bool empty() const;
60
61 protected:
62 struct Data;
63 ext::shared_ptr<Data> data_;
64
65 struct Data {
66 std::string name, code;
67
68 Data(std::string name, std::string code)
69 : name(std::move(name)), code(std::move(code)) {}
70 };
71
72 static std::map<std::string, ext::shared_ptr<Data> > commodityTypes_;
73 };
74
76 bool operator==(const CommodityType&,
77 const CommodityType&);
78
80 bool operator!=(const CommodityType&,
81 const CommodityType&);
82
84 std::ostream& operator<<(std::ostream&,
85 const CommodityType&);
86
87
89 public:
91 CommodityType("<NULL>", "<NULL>") {}
92 };
93
94
95 inline const std::string& CommodityType::code() const {
96 return data_->code;
97 }
98
99 inline const std::string& CommodityType::name() const {
100 return data_->name;
101 }
102
103 inline bool CommodityType::empty() const {
104 return !data_;
105 }
106
107 inline bool operator==(const CommodityType& c1, const CommodityType& c2) {
108 return c1.code() == c2.code();
109 }
110
111 inline bool operator!=(const CommodityType& c1, const CommodityType& c2) {
112 return !(c1 == c2);
113 }
114
115}
116
117
118#endif
const std::string & code() const
commodity code, e.g, "HO"
const std::string & name() const
name, e.g, "Heating Oil"
bool empty() const
is this a usable instance?
static std::map< std::string, ext::shared_ptr< Data > > commodityTypes_
CommodityType()=default
default constructor
ext::shared_ptr< Data > data_
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
STL namespace.
Data(std::string name, std::string code)