QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
unitofmeasure.cpp
Go to the documentation of this file.
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
21#include <ostream>
22#include <utility>
23
24namespace QuantLib {
25
26 std::ostream& operator<<(std::ostream& out, const UnitOfMeasure& c) {
27 if (!c.empty())
28 return out << c.code();
29 else
30 return out << "null unit of measure";
31 }
32
33 std::map<std::string,
34 ext::shared_ptr<UnitOfMeasure::Data> >
36
37 UnitOfMeasure::UnitOfMeasure(const std::string& name,
38 const std::string& code,
39 UnitOfMeasure::Type unitType) {
40 std::map<std::string,
41 ext::shared_ptr<UnitOfMeasure::Data> >::const_iterator i =
43 if (i != unitsOfMeasure_.end()) {
44 data_ = i->second;
45 } else {
46 data_ = ext::make_shared<UnitOfMeasure::Data>(
49 }
50 }
51
52 UnitOfMeasure::Data::Data(std::string name,
53 std::string code,
54 UnitOfMeasure::Type unitType,
55 UnitOfMeasure triangulationUnitOfMeasure,
56 const Rounding& rounding)
57 : name(std::move(name)), code(std::move(code)), unitType(unitType),
58 triangulationUnitOfMeasure(std::move(triangulationUnitOfMeasure)), rounding(rounding) {}
59}
60
basic rounding class
Definition: rounding.hpp:35
Unit of measure specification
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
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
STL namespace.
Data(std::string name, std::string code, UnitOfMeasure::Type unitType, UnitOfMeasure triangulationUnitOfMeasure=UnitOfMeasure(), const Rounding &rounding=Rounding(0))
Unit of measure.