Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | Friends | List of all members
CalibrationInstrumentFactory Class Reference

#include <ored/model/calibrationinstrumentfactory.hpp>

+ Inheritance diagram for CalibrationInstrumentFactory:
+ Collaboration diagram for CalibrationInstrumentFactory:

Public Types

typedef std::map< std::string, std::function< QuantLib::ext::shared_ptr< CalibrationInstrument >()> > map_type
 

Public Member Functions

QuantLib::ext::shared_ptr< CalibrationInstrumentbuild (const std::string &instrumentType)
 
void addBuilder (const std::string &instrumentType, std::function< QuantLib::ext::shared_ptr< CalibrationInstrument >()> builder, const bool allowOverwrite=false)
 

Private Attributes

boost::shared_mutex mutex_
 
map_type map_
 

Friends

class QuantLib::Singleton< CalibrationInstrumentFactory, std::integral_constant< bool, true > >
 

Detailed Description

Calibration instrument factory class

This class is a repository of functions that can build instances of CalibrationInstrument. The functions are keyed on the calibration instrument type that they can build. An instance of this factory class can be asked to build a particular instance of the CalibrationInstrument class via a call to build(const std::string& instrumentType) with the correct calibration instrument type, instrumentType. For example, a call to build("CpiCapFloor") should return a CpiCapFloor instance if the CpiCapFloor calibration instrument building function has been added to the factory.

It is up to each class derived from CalibrationInstrument to register itself with the CalibrationInstrumentFactory via the CalibrationInstrumentRegister class below. All registration does is add a function that can build an instance of that class to the factory and store it against its calibration instrument type key.

Definition at line 67 of file calibrationinstrumentfactory.hpp.

Member Typedef Documentation

◆ map_type

typedef std::map<std::string, std::function<QuantLib::ext::shared_ptr<CalibrationInstrument>()> > map_type

The container type used to store the calibration instrument type key and the function that will be used to build a default instance of that calibration instrument type.

Definition at line 76 of file calibrationinstrumentfactory.hpp.

Member Function Documentation

◆ build()

QuantLib::ext::shared_ptr< CalibrationInstrument > build ( const std::string &  instrumentType)

A call to build should return an instance of CalibrationInstrument corresponding to the required instrumentType. For example, a call to build("CpiCapFloor") should return a CpiCapFloor instance.

Warning:
If the instrumentType has not been added to the factory then a call to this method for that instrumentType will return a nullptr

Definition at line 27 of file calibrationinstrumentfactory.cpp.

27 {
28 boost::shared_lock<boost::shared_mutex> lock(mutex_);
29 auto it = map_.find(instrumentType);
30 if (it == map_.end())
31 return nullptr;
32 return it->second();
33}

◆ addBuilder()

void addBuilder ( const std::string &  instrumentType,
std::function< QuantLib::ext::shared_ptr< CalibrationInstrument >()>  builder,
const bool  allowOverwrite = false 
)

Add a builder function builder for a given instrumentType

Definition at line 35 of file calibrationinstrumentfactory.cpp.

37 {
38 boost::unique_lock<boost::shared_mutex> lock(mutex_);
39 QL_REQUIRE(map_.insert(std::make_pair(instrumentType, builder)).second,
40 "CalibrationInstrumentFactory::addBuilder(" << instrumentType << "): builder for key already exists.");
41}

Friends And Related Function Documentation

◆ QuantLib::Singleton< CalibrationInstrumentFactory, std::integral_constant< bool, true > >

friend class QuantLib::Singleton< CalibrationInstrumentFactory, std::integral_constant< bool, true > >
friend

Definition at line 49 of file calibrationinstrumentfactory.hpp.

Member Data Documentation

◆ mutex_

boost::shared_mutex mutex_
private

Definition at line 94 of file calibrationinstrumentfactory.hpp.

◆ map_

map_type map_
private

Definition at line 95 of file calibrationinstrumentfactory.hpp.