Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
referencedatafactory.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file portfolio/referencedatafactory.hpp
20 \brief Reference data model and serialization
21 \ingroup tradedata
22*/
23
24#pragma once
25
26#include <map>
27#include <functional>
28#include <ql/patterns/singleton.hpp>
29#include <string>
30#include <boost/thread/shared_mutex.hpp>
31#include <boost/thread/lock_types.hpp>
32
33namespace ore {
34namespace data {
35
36class ReferenceDatum;
37
39public:
41 virtual QuantLib::ext::shared_ptr<ReferenceDatum> build() const = 0;
42};
43
44//! Template TradeBuilder class
45/*!
46 \ingroup tradedata
47*/
48template <class T> class ReferenceDatumBuilder : public AbstractReferenceDatumBuilder {
49public:
50 virtual QuantLib::ext::shared_ptr<ReferenceDatum> build() const override { return QuantLib::ext::make_shared<T>(); }
51};
52
53class ReferenceDatumFactory : public QuantLib::Singleton<ReferenceDatumFactory, std::integral_constant<bool, true>> {
54
55 friend class QuantLib::Singleton<ReferenceDatumFactory, std::integral_constant<bool, true>>;
56
57public:
58 typedef std::map<std::string, std::function<QuantLib::ext::shared_ptr<AbstractReferenceDatumBuilder>()>> map_type;
59
60 QuantLib::ext::shared_ptr<ReferenceDatum> build(const std::string& refDatumType);
61
62 void addBuilder(const std::string& refDatumType,
63 std::function<QuantLib::ext::shared_ptr<AbstractReferenceDatumBuilder>()> builder,
64 const bool allowOverwrite = false);
65
66private:
67 boost::shared_mutex mutex_;
69};
70
71template <class T> QuantLib::ext::shared_ptr<AbstractReferenceDatumBuilder> createReferenceDatumBuilder() {
72 return QuantLib::ext::make_shared<T>();
73}
74
75} // namespace data
76} // namespace ore
virtual QuantLib::ext::shared_ptr< ReferenceDatum > build() const =0
Template TradeBuilder class.
virtual QuantLib::ext::shared_ptr< ReferenceDatum > build() const override
QuantLib::ext::shared_ptr< ReferenceDatum > build(const std::string &refDatumType)
void addBuilder(const std::string &refDatumType, std::function< QuantLib::ext::shared_ptr< AbstractReferenceDatumBuilder >()> builder, const bool allowOverwrite=false)
std::map< std::string, std::function< QuantLib::ext::shared_ptr< AbstractReferenceDatumBuilder >()> > map_type
@ data
Definition: log.hpp:77
QuantLib::ext::shared_ptr< AbstractReferenceDatumBuilder > createReferenceDatumBuilder()
Serializable Credit Default Swap.
Definition: namespaces.docs:23