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

General singleton, abstract factory. More...

#include <AbstractFactory.hpp>

Public Member Functions

 AbstractFactory ()
 AbstractFactory (const AbstractFactory &)=delete
AbstractFactoryoperator= (const AbstractFactory &)=delete
virtual ~AbstractFactory ()=default
std::shared_ptr< T > create_processor (const std::string &processor_name)
 Create the requested processor.

Static Public Member Functions

static void register_creator (const std::string &processor_name, create_processor_func creator)
 Register the processor creation function to a given name.
static std::shared_ptr< AbstractFactory< T > > get_instance ()
 Singleton get instance function.

Static Protected Attributes

static std::shared_ptr< AbstractFactory< T > > s_single_factory
 Singleton instance.

Private Types

using create_processor_func = std::function<std::shared_ptr<T>()>
 Function that creates shared_ptrs of type T.
using name_creator_map = std::unordered_map<std::string, create_processor_func>
 Map from processor name to processor creation function.

Static Private Member Functions

static name_creator_mapget_creators ()
 Returns singleton instance of creation map.

Detailed Description

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

General singleton, abstract factory.

Definition at line 26 of file AbstractFactory.hpp.

Member Typedef Documentation

◆ create_processor_func

template<typename T>
using tpglibs::AbstractFactory< T >::create_processor_func = std::function<std::shared_ptr<T>()>
private

Function that creates shared_ptrs of type T.

Definition at line 28 of file AbstractFactory.hpp.

◆ name_creator_map

template<typename T>
using tpglibs::AbstractFactory< T >::name_creator_map = std::unordered_map<std::string, create_processor_func>
private

Map from processor name to processor creation function.

Definition at line 30 of file AbstractFactory.hpp.

Constructor & Destructor Documentation

◆ AbstractFactory() [1/2]

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

Definition at line 33 of file AbstractFactory.hpp.

33{}

◆ AbstractFactory() [2/2]

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

◆ ~AbstractFactory()

template<typename T>
virtual tpglibs::AbstractFactory< T >::~AbstractFactory ( )
virtualdefault

Member Function Documentation

◆ create_processor()

template<typename T>
std::shared_ptr< T > tpglibs::AbstractFactory< T >::create_processor ( const std::string & processor_name)

Create the requested processor.

Parameters
processor_nameName of the processor being created.
Returns
shared_ptr of the requested processor. nullptr if it doesn't exist/isn't registered.

Definition at line 36 of file AbstractFactory.hxx.

36 {
38 auto it = creators.find(processor_name);
39
40 if (it != creators.end()) {
41 return it->second();
42 }
43
44 throw std::runtime_error("Factory failed to find " + processor_name);
45}
General singleton, abstract factory.
std::unordered_map< std::string, create_processor_func > name_creator_map
Map from processor name to processor creation function.
static name_creator_map & get_creators()
Returns singleton instance of creation map.

◆ get_creators()

template<typename T>
AbstractFactory< T >::name_creator_map & tpglibs::AbstractFactory< T >::get_creators ( )
staticprivate

Returns singleton instance of creation map.

Definition at line 18 of file AbstractFactory.hxx.

18 {
20 return s_creators;
21}

◆ get_instance()

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

Singleton get instance function.

Definition at line 48 of file AbstractFactory.hxx.

49{
50 if (s_single_factory == nullptr) {
52 }
53
54 return s_single_factory;
55}
static std::shared_ptr< AbstractFactory< T > > s_single_factory
Singleton instance.

◆ operator=()

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

◆ register_creator()

template<typename T>
void tpglibs::AbstractFactory< T >::register_creator ( const std::string & processor_name,
create_processor_func creator )
static

Register the processor creation function to a given name.

Parameters
processor_nameString name of the processor to be registered as.
creatorProcessor creation function.

Definition at line 24 of file AbstractFactory.hxx.

24 {
26 auto it = creators.find(processor_name);
27
28 if (it == creators.end()) {
30 return;
31 }
32 throw std::runtime_error("Attempted to overwrite a creator in factory with " + processor_name);
33}

Member Data Documentation

◆ s_single_factory

template<typename T>
std::shared_ptr<AbstractFactory<T> > tpglibs::AbstractFactory< T >::s_single_factory
staticprotected

Singleton instance.

Definition at line 57 of file AbstractFactory.hpp.


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