DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
AbstractFactory.hpp
Go to the documentation of this file.
1
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>
28 using create_processor_func = std::function<std::shared_ptr<T>()>;
30 using name_creator_map = std::unordered_map<std::string, create_processor_func>;
31
32 public:
36 virtual ~AbstractFactory() = default;
37
43 std::shared_ptr<T> create_processor(const std::string& processor_name);
44
50 static void register_creator(const std::string& processor_name, create_processor_func creator);
51
53 static std::shared_ptr<AbstractFactory<T>> get_instance();
54
55 protected:
57 static std::shared_ptr<AbstractFactory<T>> s_single_factory;
58
59 private:
62};
63
64} // namespace tpglibs
65
67
68#endif // TPGLIBS_ABSTRACTFACTORY_HPP_
General singleton, abstract factory.
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 std::shared_ptr< AbstractFactory< T > > s_single_factory
Singleton instance.
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.