DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
AbstractFactory.hpp
Go to the documentation of this file.
1
8
9#ifndef TPGLIBS_ABSTRACTFACTORY_HPP_
10#define TPGLIBS_ABSTRACTFACTORY_HPP_
11
12#include <cstdint>
13#include <exception>
14#include <functional>
15#include <iostream>
16#include <memory>
17#include <string>
18#include <unordered_map>
19
20namespace tpglibs {
21
25template<typename T>
27{
29 using create_processor_func = std::function<std::shared_ptr<T>()>;
31 using name_creator_map = std::unordered_map<std::string, create_processor_func>;
32
33public:
37 virtual ~AbstractFactory() = default;
38
44 std::shared_ptr<T> create_processor(const std::string& processor_name);
45
51 static void register_creator(const std::string& processor_name, create_processor_func creator);
52
54 static std::shared_ptr<AbstractFactory<T>> get_instance();
55
56protected:
58 static std::shared_ptr<AbstractFactory<T>> s_single_factory;
59
60private:
63};
64
65} // namespace tpglibs
66
68
69#endif // TPGLIBS_ABSTRACTFACTORY_HPP_
AbstractFactory(const AbstractFactory &)=delete
std::unordered_map< std::string, create_processor_func > name_creator_map
Map from processor name to processor creation function.
AbstractFactory & operator=(const AbstractFactory &)=delete
static name_creator_map & get_creators()
Returns singleton instance of creation map.
virtual ~AbstractFactory()=default
std::function< std::shared_ptr< T >()> create_processor_func
Function that creates shared_ptrs of type T.
static std::shared_ptr< AbstractFactory< T > > get_instance()
Singleton get instance function.
std::shared_ptr< T > create_processor(const std::string &processor_name)
Create the requested processor.
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 > > s_single_factory
Singleton instance.