#include <ored/portfolio/legdatafactory.hpp>
Public Types | |
typedef std::map< std::string, std::function< boost::shared_ptr< LegAdditionalData >)> > | map_type |
Public Member Functions | |
boost::shared_ptr< LegAdditionalData > | build (const std::string &legType) |
void | addBuilder (const std::string &legType, std::function< boost::shared_ptr< LegAdditionalData >()> builder, const bool allowOverwrite=false) |
Friends | |
class | QuantLib::Singleton< LegDataFactory, std::integral_constant< bool, true > > |
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.
typedef std::map<std::string, std::function<boost::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.
boost::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.
legType
has not been added to the factory then a call to this method for that legType
will return a nullptr
void addBuilder | ( | const std::string & | legType, |
std::function< boost::shared_ptr< LegAdditionalData >()> | builder, | ||
const bool | allowOverwrite = false |
||
) |
Add a builder function builder
for a given legType