9#ifndef TPGLIBS_ABSTRACTFACTORY_HXX_
10#define TPGLIBS_ABSTRACTFACTORY_HXX_
26 auto it = creators.find(processor_name);
28 if (it == creators.end()) {
29 creators[processor_name] = creator;
32 throw std::runtime_error(
"Attempted to overwrite a creator in factory with " + processor_name);
39 auto it = creators.find(processor_name);
41 if (it != creators.end()) {
45 throw std::runtime_error(
"Factory failed to find " + processor_name);
52 if (s_single_factory ==
nullptr) {
53 s_single_factory = std::make_shared<AbstractFactory<T>>();
56 return s_single_factory;
std::unordered_map< std::string, create_processor_func > name_creator_map
Map from processor name to processor creation function.
static std::shared_ptr< AbstractFactory< T > > s_single_factory
Singleton instance.
static name_creator_map & get_creators()
Returns singleton instance of creation map.
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.