DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
tpglibs
include
tpglibs
AbstractFactory.hxx
Go to the documentation of this file.
1
8
9
#ifndef TPGLIBS_ABSTRACTFACTORY_HXX_
10
#define TPGLIBS_ABSTRACTFACTORY_HXX_
11
12
namespace
tpglibs
{
13
14
template
<
typename
T>
15
std::shared_ptr<AbstractFactory<T>>
AbstractFactory<T>::s_single_factory
=
nullptr
;
16
17
template
<
typename
T>
18
typename
AbstractFactory<T>::name_creator_map
&
19
AbstractFactory<T>::get_creators
()
20
{
21
static
name_creator_map
s_creators;
22
return
s_creators;
23
}
24
25
template
<
typename
T>
26
void
27
AbstractFactory<T>::register_creator
(
const
std::string& processor_name,
create_processor_func
creator)
28
{
29
name_creator_map
& creators =
get_creators
();
30
auto
it = creators.find(processor_name);
31
32
if
(it == creators.end()) {
33
creators[processor_name] = creator;
34
return
;
35
}
36
throw
std::runtime_error(
"Attempted to overwrite a creator in factory with "
+ processor_name);
37
}
38
39
template
<
typename
T>
40
std::shared_ptr<T>
41
AbstractFactory<T>::create_processor
(
const
std::string& processor_name)
42
{
43
name_creator_map
& creators =
get_creators
();
44
auto
it = creators.find(processor_name);
45
46
if
(it != creators.end()) {
47
return
it->second();
48
}
49
50
throw
std::runtime_error(
"Factory failed to find "
+ processor_name);
51
}
52
53
template
<
typename
T>
54
std::shared_ptr<AbstractFactory<T>>
55
AbstractFactory<T>::get_instance
()
56
{
57
if
(
s_single_factory
==
nullptr
) {
58
s_single_factory
= std::make_shared<AbstractFactory<T>>();
59
}
60
61
return
s_single_factory
;
62
}
63
64
}
// namespace tpglibs
65
66
#endif
// TPGLIBS_ABSTRACTFACTORY_HXX_
tpglibs::AbstractFactory::name_creator_map
std::unordered_map< std::string, create_processor_func > name_creator_map
Map from processor name to processor creation function.
Definition
AbstractFactory.hpp:31
tpglibs::AbstractFactory::get_creators
static name_creator_map & get_creators()
Returns singleton instance of creation map.
Definition
AbstractFactory.hxx:19
tpglibs::AbstractFactory::create_processor_func
std::function< std::shared_ptr< T >()> create_processor_func
Function that creates shared_ptrs of type T.
Definition
AbstractFactory.hpp:29
tpglibs::AbstractFactory::get_instance
static std::shared_ptr< AbstractFactory< T > > get_instance()
Singleton get instance function.
Definition
AbstractFactory.hxx:55
tpglibs::AbstractFactory::create_processor
std::shared_ptr< T > create_processor(const std::string &processor_name)
Create the requested processor.
Definition
AbstractFactory.hxx:41
tpglibs::AbstractFactory::register_creator
static void register_creator(const std::string &processor_name, create_processor_func creator)
Register the processor creation function to a given name.
Definition
AbstractFactory.hxx:27
tpglibs::AbstractFactory::s_single_factory
static std::shared_ptr< AbstractFactory< T > > s_single_factory
Singleton instance.
Definition
AbstractFactory.hpp:58
tpglibs
Definition
AbstractFactory.hpp:20
Generated on
for DUNE-DAQ by
1.18.0