DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
triggeralgs::AbstractFactory< T > Class Template Reference

#include <AbstractFactory.hpp>

Public Member Functions

 AbstractFactory ()
 
 AbstractFactory (const AbstractFactory &)=delete
 
AbstractFactoryoperator= (const AbstractFactory &)=delete
 
virtual ~AbstractFactory ()
 
std::unique_ptr< T > build_maker (const std::string &alg_name)
 

Static Public Member Functions

static void register_creator (const std::string alg_name, maker_creator creator)
 
static std::shared_ptr< AbstractFactory< T > > get_instance ()
 

Static Protected Attributes

static std::shared_ptr< AbstractFactory< T > > s_single_factory = nullptr
 

Private Types

using maker_creator = std::function<std::unique_ptr<T>()>
 
using creation_map = std::unordered_map<std::string, maker_creator>
 

Static Private Member Functions

static creation_mapget_makers ()
 

Detailed Description

template<typename T>
class triggeralgs::AbstractFactory< T >

Definition at line 21 of file AbstractFactory.hpp.

Member Typedef Documentation

◆ creation_map

template<typename T >
using triggeralgs::AbstractFactory< T >::creation_map = std::unordered_map<std::string, maker_creator>
private

Definition at line 24 of file AbstractFactory.hpp.

◆ maker_creator

template<typename T >
using triggeralgs::AbstractFactory< T >::maker_creator = std::function<std::unique_ptr<T>()>
private

Definition at line 23 of file AbstractFactory.hpp.

Constructor & Destructor Documentation

◆ AbstractFactory() [1/2]

template<typename T >
triggeralgs::AbstractFactory< T >::AbstractFactory ( )
inline

Definition at line 27 of file AbstractFactory.hpp.

27{}

◆ AbstractFactory() [2/2]

template<typename T >
triggeralgs::AbstractFactory< T >::AbstractFactory ( const AbstractFactory< T > & )
delete

◆ ~AbstractFactory()

template<typename T >
virtual triggeralgs::AbstractFactory< T >::~AbstractFactory ( )
inlinevirtual

Definition at line 30 of file AbstractFactory.hpp.

30{}

Member Function Documentation

◆ build_maker()

template<typename T >
std::unique_ptr< T > triggeralgs::AbstractFactory< T >::build_maker ( const std::string & alg_name)

Definition at line 39 of file AbstractFactory.hxx.

40{
41 creation_map& makers = get_makers();
42 auto it = makers.find(alg_name);
43
44 if (it != makers.end()) {
45 TLOG() << "[AF] Factory building " << alg_name << ".";
46 return it->second();
47 }
48
49 throw FactoryNotFound(ERS_HERE, alg_name);
50 return nullptr;
51}
#define ERS_HERE
static creation_map & get_makers()
std::unordered_map< std::string, maker_creator > creation_map
#define TLOG(...)
Definition macro.hpp:22
FactoryNotFound
Definition Issues.hpp:23

◆ get_instance()

template<typename T >
std::shared_ptr< AbstractFactory< T > > triggeralgs::AbstractFactory< T >::get_instance ( )
static

Definition at line 54 of file AbstractFactory.hxx.

55{
56 if (s_single_factory == nullptr) {
57 s_single_factory = std::make_shared<AbstractFactory<T>>();
58 }
59 return s_single_factory;
60}
static std::shared_ptr< AbstractFactory< T > > s_single_factory

◆ get_makers()

template<typename T >
AbstractFactory< T >::creation_map & triggeralgs::AbstractFactory< T >::get_makers ( )
staticprivate

Definition at line 19 of file AbstractFactory.hxx.

19 {
20 static creation_map s_makers;
21 return s_makers;
22}

◆ operator=()

template<typename T >
AbstractFactory & triggeralgs::AbstractFactory< T >::operator= ( const AbstractFactory< T > & )
delete

◆ register_creator()

template<typename T >
void triggeralgs::AbstractFactory< T >::register_creator ( const std::string alg_name,
maker_creator creator )
static

Definition at line 25 of file AbstractFactory.hxx.

26{
27 creation_map& makers = get_makers();
28 auto it = makers.find(alg_name);
29
30 if (it == makers.end()) {
31 makers[alg_name] = creator;
32 return;
33 }
34 throw FactoryOverwrite(ERS_HERE, alg_name);
35 return;
36}

Member Data Documentation

◆ s_single_factory

template<typename T >
std::shared_ptr< AbstractFactory< T > > triggeralgs::AbstractFactory< T >::s_single_factory = nullptr
staticprotected

Definition at line 39 of file AbstractFactory.hpp.


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