/src/quantlib/ql/experimental/commodities/unitofmeasure.cpp
Line | Count | Source |
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 | | <https://www.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 | | |
20 | | #include <ql/experimental/commodities/unitofmeasure.hpp> |
21 | | #include <ostream> |
22 | | #include <utility> |
23 | | |
24 | | namespace QuantLib { |
25 | | |
26 | 0 | std::ostream& operator<<(std::ostream& out, const UnitOfMeasure& c) { |
27 | 0 | if (!c.empty()) |
28 | 0 | return out << c.code(); |
29 | 0 | else |
30 | 0 | return out << "null unit of measure"; |
31 | 0 | } |
32 | | |
33 | | std::map<std::string, |
34 | | ext::shared_ptr<UnitOfMeasure::Data> > |
35 | | UnitOfMeasure::unitsOfMeasure_; |
36 | | |
37 | | UnitOfMeasure::UnitOfMeasure(const std::string& name, |
38 | | const std::string& code, |
39 | 0 | UnitOfMeasure::Type unitType) { |
40 | 0 | auto i = |
41 | 0 | unitsOfMeasure_.find(name); |
42 | 0 | if (i != unitsOfMeasure_.end()) { |
43 | 0 | data_ = i->second; |
44 | 0 | } else { |
45 | 0 | data_ = ext::make_shared<UnitOfMeasure::Data>( |
46 | 0 | name, code, unitType); |
47 | 0 | unitsOfMeasure_[name] = data_; |
48 | 0 | } |
49 | 0 | } |
50 | | |
51 | | UnitOfMeasure::Data::Data(std::string name, |
52 | | std::string code, |
53 | | UnitOfMeasure::Type unitType, |
54 | | UnitOfMeasure triangulationUnitOfMeasure, |
55 | | const Rounding& rounding) |
56 | 0 | : name(std::move(name)), code(std::move(code)), unitType(unitType), |
57 | 0 | triangulationUnitOfMeasure(std::move(triangulationUnitOfMeasure)), rounding(rounding) {} |
58 | | } |
59 | | |