Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
tradefactory.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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 ored/portfolio/tradefactory.hpp
20 \brief Trade Factory
21 \ingroup portfolio
22*/
23
24#pragma once
25
26#include <map>
27#include <ql/patterns/singleton.hpp>
28
29#include <boost/make_shared.hpp>
30#include <boost/thread/lock_types.hpp>
31#include <boost/thread/shared_mutex.hpp>
32
33namespace ore {
34namespace data {
35
36class Trade;
37
38//! TradeBuilder base class
39/*! All derived classes have to be stateless. It should not be necessary to derive classes
40 other than TradeBuilder from this class anyway.
41
42 \ingroup portfolio
43*/
45public:
47 virtual QuantLib::ext::shared_ptr<Trade> build() const = 0;
48};
49
50//! Template TradeBuilder class
51/*!
52 \ingroup tradedata
53*/
54template <class T> class TradeBuilder : public AbstractTradeBuilder {
55public:
56 virtual QuantLib::ext::shared_ptr<Trade> build() const override { return QuantLib::ext::make_shared<T>(); }
57};
58
59//! TradeFactory
60/*!
61 \ingroup tradedata
62*/
63class TradeFactory : public QuantLib::Singleton<TradeFactory, std::integral_constant<bool, true>> {
64 std::map<std::string, QuantLib::ext::shared_ptr<AbstractTradeBuilder>> builders_;
65 mutable boost::shared_mutex mutex_;
66
67public:
68 std::map<std::string, QuantLib::ext::shared_ptr<AbstractTradeBuilder>> getBuilders() const;
69 QuantLib::ext::shared_ptr<AbstractTradeBuilder> getBuilder(const std::string& tradeType) const;
70 void addBuilder(const std::string& tradeType, const QuantLib::ext::shared_ptr<AbstractTradeBuilder>& builder,
71 const bool allowOverwrite = false);
72
73 //! Build, throws for unknown className
74 QuantLib::ext::shared_ptr<Trade> build(const std::string& className) const;
75};
76
77} // namespace data
78} // namespace ore
TradeBuilder base class.
virtual QuantLib::ext::shared_ptr< Trade > build() const =0
Template TradeBuilder class.
virtual QuantLib::ext::shared_ptr< Trade > build() const override
void addBuilder(const std::string &tradeType, const QuantLib::ext::shared_ptr< AbstractTradeBuilder > &builder, const bool allowOverwrite=false)
std::map< std::string, QuantLib::ext::shared_ptr< AbstractTradeBuilder > > builders_
boost::shared_mutex mutex_
QuantLib::ext::shared_ptr< AbstractTradeBuilder > getBuilder(const std::string &tradeType) const
QuantLib::ext::shared_ptr< Trade > build(const std::string &className) const
Build, throws for unknown className.
std::map< std::string, QuantLib::ext::shared_ptr< AbstractTradeBuilder > > getBuilders() const
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23