Skip to content

Commit efb4270

Browse files
pcaspersjenkins
authored andcommitted
QPR-11568 align bond factory behaviour
1 parent b02996f commit efb4270

2 files changed

Lines changed: 6 additions & 12 deletions

File tree

OREData/ored/portfolio/bond.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,13 @@ BondBuilder::Result BondFactory::build(const boost::shared_ptr<EngineFactory>& e
325325
"data and that there is a builder for the reference data type.");
326326
}
327327

328-
void BondFactory::addBuilder(const std::string& referenceDataType, const boost::shared_ptr<BondBuilder>& builder) {
328+
void BondFactory::addBuilder(const std::string& referenceDataType, const boost::shared_ptr<BondBuilder>& builder,
329+
const bool allowOverwrite) {
329330
boost::unique_lock<boost::shared_mutex> lock(mutex_);
330-
builders_[referenceDataType] = builder;
331+
QL_REQUIRE(builders_.insert(std::make_pair(referenceDataType, builder)).second || allowOverwrite,
332+
"BondFactory::addBuilder(" << referenceDataType << "): builder for key already exists.");
331333
}
332334

333-
BondBuilderRegister<VanillaBondBuilder> VanillaBondBuilder::reg_("Bond");
334-
335335
BondBuilder::Result VanillaBondBuilder::build(const boost::shared_ptr<EngineFactory>& engineFactory,
336336
const boost::shared_ptr<ReferenceDataManager>& referenceData,
337337
const std::string& securityId) const {

OREData/ored/portfolio/bond.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,11 @@ class BondFactory : public QuantLib::Singleton<BondFactory, std::integral_consta
207207
BondBuilder::Result build(const boost::shared_ptr<EngineFactory>& engineFactory,
208208
const boost::shared_ptr<ReferenceDataManager>& referenceData,
209209
const std::string& securityId) const;
210-
void addBuilder(const std::string& referenceDataType, const boost::shared_ptr<BondBuilder>& builder);
211-
};
212-
213-
template <typename T> struct BondBuilderRegister {
214-
BondBuilderRegister<T>(const std::string& referenceDataType) {
215-
BondFactory::instance().addBuilder(referenceDataType, boost::make_shared<T>());
216-
}
210+
void addBuilder(const std::string& referenceDataType, const boost::shared_ptr<BondBuilder>& builder,
211+
const bool allowOverwrite = false);
217212
};
218213

219214
struct VanillaBondBuilder : public BondBuilder {
220-
static BondBuilderRegister<VanillaBondBuilder> reg_;
221215
virtual Result build(const boost::shared_ptr<EngineFactory>& engineFactory,
222216
const boost::shared_ptr<ReferenceDataManager>& referenceData,
223217
const std::string& securityId) const override;

0 commit comments

Comments
 (0)