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
&
AbstractFactory<T>::get_creators
() {
19
static
name_creator_map
s_creators;
20
return
s_creators;
21
}
22
23
template
<
typename
T>
24
void
AbstractFactory<T>::register_creator
(
const
std::string& processor_name,
create_processor_func
creator) {
25
name_creator_map
& creators =
get_creators
();
26
auto
it = creators.find(processor_name);
27
28
if
(it == creators.end()) {
29
creators[processor_name] = creator;
30
return
;
31
}
32
throw
std::runtime_error(
"Attempted to overwrite a creator in factory with "
+ processor_name);
33
}
34
35
template
<
typename
T>
36
std::shared_ptr<T>
AbstractFactory<T>::create_processor
(
const
std::string& processor_name) {
37
name_creator_map
& creators =
get_creators
();
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
}
46
47
template
<
typename
T>
48
std::shared_ptr<AbstractFactory<T>>
AbstractFactory<T>::get_instance
()
49
{
50
if
(
s_single_factory
==
nullptr
) {
51
s_single_factory
= std::make_shared<AbstractFactory<T>>();
52
}
53
54
return
s_single_factory
;
55
}
56
57
}
// namespace tpglibs
58
59
#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:30
tpglibs::AbstractFactory::get_creators
static name_creator_map & get_creators()
Returns singleton instance of creation map.
Definition
AbstractFactory.hxx:18
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:28
tpglibs::AbstractFactory::get_instance
static std::shared_ptr< AbstractFactory< T > > get_instance()
Singleton get instance function.
Definition
AbstractFactory.hxx:48
tpglibs::AbstractFactory::create_processor
std::shared_ptr< T > create_processor(const std::string &processor_name)
Create the requested processor.
Definition
AbstractFactory.hxx:36
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:24
tpglibs::AbstractFactory::s_single_factory
static std::shared_ptr< AbstractFactory< T > > s_single_factory
Singleton instance.
Definition
AbstractFactory.hpp:57
tpglibs
Definition
AbstractFactory.hpp:20
Generated on
for DUNE-DAQ by
1.17.0