fire v0.19.0
Framework for sImulation and Reconstruction of Events
fire::Processor::Factory Class Reference

The special factory used to create processors. More...

#include <Processor.h>

Public Types

using PrototypePtr = std::unique_ptr< Processor >
 The base pointer for processors.
 
using PrototypeMaker = std::function< PrototypePtr(const config::Parameters &, Process &)>
 the signature of a function that can be used by this factory to dynamically create a new object. More...
 

Public Member Functions

template<typename DerivedType >
uint64_t declare ()
 register a new object to be constructible More...
 
PrototypePtr make (const std::string &full_name, const config::Parameters &ps, Process &p)
 make a new object by name More...
 
 Factory (Factory const &)=delete
 delete the copy constructor
 
void operator= (Factory const &)=delete
 delete the assignment operator
 

Static Public Member Functions

static Factoryget ()
 get the factory instance More...
 

Private Member Functions

 Factory ()=default
 private constructor to prevent creation
 

Static Private Member Functions

template<typename DerivedType >
static PrototypePtr maker (const config::Parameters &parameters, Process &process)
 make a DerivedType returning a PrototypePtr More...
 

Private Attributes

std::unordered_map< std::string, PrototypeMakerlibrary_
 library of possible objects to create
 

Detailed Description

The special factory used to create processors.

we need a special factory because it needs to be able to create processors with two different construtor options

When "old-style" processors can be abandoned, this redundant code can be removed in favor of the templated factory:

using Factory = factory::Factory<Processor, std::unique_ptr<Processor>,
const config::Parameters &>;
Factory()=default
private constructor to prevent creation

and then adding the following line to the loop constructing Processors in the Process constructor:

sequence_.emplace_back(Processor::Factory::get().make(class_name, proc));
sequence_.back()->attach(this);
PrototypePtr make(const std::string &full_name, const config::Parameters &ps, Process &p)
make a new object by name
Definition: Processor.h:292
static Factory & get()
get the factory instance
Definition: Processor.h:244

Member Typedef Documentation

◆ PrototypeMaker

the signature of a function that can be used by this factory to dynamically create a new object.

This is merely here to make the definition of the Factory simpler.

Member Function Documentation

◆ declare()

template<typename DerivedType >
uint64_t fire::Processor::Factory::declare ( )
inline

register a new object to be constructible

We insert the new object into the library after checking that it hasn't been defined before.

Note
This uses the demangled name of the input type as the key in our library of objects. Using the demangled name effectively assumes that all of the libraries being loaded were compiled with the same compiler version. We could undo this assumption by having the key be an input into this function.
Template Parameters
DerivedTypetype of processor to declare
Returns
value to define a static variable to force running this function at library load time. It relates to variables so that it cannot be optimized away.

◆ get()

static Factory & fire::Processor::Factory::get ( )
inlinestatic

get the factory instance

Using a static function variable gaurantees that the factory is created as soon as it is needed and that it is deleted before the program completes.

Returns
reference to single Factory instance

◆ make()

PrototypePtr fire::Processor::Factory::make ( const std::string full_name,
const config::Parameters ps,
Process p 
)
inline

make a new object by name

We look through the library to find the requested object. If found, we create one and return a pointer to the newly created object. If not found, we raise an exception.

Exceptions
Exceptionif the input object name could not be found

The arguments to the maker are determined at compiletime using the template parameters of Factory.

Parameters
[in]full_namename of object to create, same name as passed to declare
[in]psParameters to configure the Processor
[in]phandle to current Process
Returns
a pointer to the parent class that the objects derive from.

◆ maker()

template<typename DerivedType >
static PrototypePtr fire::Processor::Factory::maker ( const config::Parameters parameters,
Process process 
)
inlinestaticprivate

make a DerivedType returning a PrototypePtr

We do a constexpr check on which type of processor it is. If it can be constructed from a Parameters alone, then it is a "new" type. Otherewise, it is a "legacy" type as defined in the framework namespace.

Template Parameters
DerivedTypetype of derived object we should create
Parameters
[in]parametersconfig::Parameters to configure Processor
[in]processhandle to current Process

The documentation for this class was generated from the following file: