DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
AbstractFactory.hpp
Go to the documentation of this file.
1/* @file: AbstractFactory.hpp
2 *
3 * This is part of the DUNE DAQ Application Framework, copyright 2023.
4 * Licensing/copyright details are in the COPYING file that you should have
5 * received with this code.
6 */
7
8#ifndef TRIGGERALGS_ABSTRACT_FACTORY_HPP_
9#define TRIGGERALGS_ABSTRACT_FACTORY_HPP_
10
11#include "logging/Logging.hpp"
12
13#include <functional>
14#include <memory>
15#include <string>
16#include <unordered_map>
17
18namespace triggeralgs {
19
20template <typename T>
22{
23 using maker_creator = std::function<std::unique_ptr<T>()>;
24 using creation_map = std::unordered_map<std::string, maker_creator>;
25
26 public:
30 virtual ~AbstractFactory() {}
31
32 std::unique_ptr<T> build_maker(const std::string& alg_name);
33
34 static void register_creator(const std::string alg_name, maker_creator creator);
35
36 static std::shared_ptr<AbstractFactory<T>> get_instance();
37
38 protected:
39 static std::shared_ptr<AbstractFactory<T>> s_single_factory;
40
41 private:
42 static creation_map& get_makers();
43};
44
45} /* namespace triggeralgs */
46
48
49#endif // TRIGGERALGS_ABSTRACT_FACTORY_HPP_
AbstractFactory(const AbstractFactory &)=delete
AbstractFactory & operator=(const AbstractFactory &)=delete
static creation_map & get_makers()
static std::shared_ptr< AbstractFactory< T > > get_instance()
std::unordered_map< std::string, maker_creator > creation_map
static std::shared_ptr< AbstractFactory< T > > s_single_factory
static void register_creator(const std::string alg_name, maker_creator creator)
std::unique_ptr< T > build_maker(const std::string &alg_name)
std::function< std::unique_ptr< T >()> maker_creator