Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
tradefactory.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016-2022 Quaternion Risk Management Ltd
3 Copyright (C) 2021 Skandinaviska Enskilda Banken AB (publ)
4 All rights reserved.
5
6 This file is part of ORE, a free-software/open-source library
7 for transparent pricing and risk analysis - http://opensourcerisk.org
8
9 ORE is free software: you can redistribute it and/or modify it
10 under the terms of the Modified BSD License. You should have received a
11 copy of the license along with this program.
12 The license is also available online at <http://opensourcerisk.org>
13
14 This program is distributed on the basis that it will form a useful
15 contribution to risk analytics and model standardisation, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
21
22#include <ql/errors.hpp>
23
24using namespace std;
25
26namespace ore {
27namespace data {
28
29std::map<std::string, QuantLib::ext::shared_ptr<AbstractTradeBuilder>> TradeFactory::getBuilders() const {
30 boost::shared_lock<boost::shared_mutex> lock(mutex_);
31 return builders_;
32}
33
34QuantLib::ext::shared_ptr<AbstractTradeBuilder> TradeFactory::getBuilder(const std::string& className) const {
35 boost::shared_lock<boost::shared_mutex> lock(mutex_);
36 auto b = builders_.find(className);
37 QL_REQUIRE(b != builders_.end(), "TradeFactory::getBuilder(" << className << "): no builder found");
38 return b->second;
39}
40
41void TradeFactory::addBuilder(const std::string& className, const QuantLib::ext::shared_ptr<AbstractTradeBuilder>& builder,
42 const bool allowOverwrite) {
43 boost::unique_lock<boost::shared_mutex> lock(mutex_);
44 QL_REQUIRE(builders_.insert(std::make_pair(className, builder)).second || allowOverwrite,
45 "TradeFactory: duplicate builder for className '" << className << "'.");
46}
47
48QuantLib::ext::shared_ptr<Trade> TradeFactory::build(const string& className) const { return getBuilder(className)->build(); }
49
50} // namespace data
51} // namespace ore
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
Trade Factory.