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
LegDataFactory Class Reference

#include <ored/portfolio/legdatafactory.hpp>

+ Inheritance diagram for LegDataFactory:
+ Collaboration diagram for LegDataFactory:

Public Types

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

Public Member Functions

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

Private Attributes

boost::shared_mutex mutex_
 
map_type map_
 

Friends

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

Detailed Description

Leg data factory class

This class is a repository of functions that can build instances of LegAdditionalData. The functions are keyed on the leg data type that they can build. An instance of this factory class can be asked to build a particular instance of the LegAdditionalData class via a call to build(const std::string& legType) with the correct legType name. For example, a call to build("Fixed") should return a FixedLegData instance if the fixed leg data building function has been added to the factory.

It is up to each class derived from LegAdditionalData to register itself with the LegDataFactory via the LegDataRegister 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 leg type key.

Definition at line 65 of file legdatafactory.hpp.

Member Typedef Documentation

◆ map_type

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

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

Definition at line 73 of file legdatafactory.hpp.

Member Function Documentation

◆ build()

QuantLib::ext::shared_ptr< LegAdditionalData > build ( const std::string &  legType)

A call to build should return an instance of LegAdditionalData corresponding to the required legType. For example, a call to build("Fixed") should return a FixedLegData instance.

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

Definition at line 29 of file legdatafactory.cpp.

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

◆ addBuilder()

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

Add a builder function builder for a given legType

Definition at line 37 of file legdatafactory.cpp.

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

Friends And Related Function Documentation

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

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

Definition at line 49 of file legdatafactory.hpp.

Member Data Documentation

◆ mutex_

boost::shared_mutex mutex_
private

Definition at line 89 of file legdatafactory.hpp.

◆ map_

map_type map_
private

Definition at line 90 of file legdatafactory.hpp.