SourceXtractorPlusPlus  0.16
Please provide a description of the project.
TaskFactoryRegistry.h
Go to the documentation of this file.
1 
17 /*
18  * TaskFactoryRegistry.h
19  *
20  * Created on: Aug 2, 2016
21  * Author: mschefer
22  */
23 
24 #ifndef _SEFRAMEWORK_TASK_TASKFACTORYREGISTRY_H_
25 #define _SEFRAMEWORK_TASK_TASKFACTORYREGISTRY_H_
26 
27 #include <memory>
28 #include <vector>
29 #include <unordered_map>
30 #include <unordered_set>
31 
33 
34 namespace SourceXtractor {
35 
36 class OutputRegistry;
37 class TaskFactory;
38 
40 public:
41 
44  public:
45  DuplicateFactoryException() : Elements::Exception("Duplicate PropertyId in TaskProvider") {}
46  };
47 
48  virtual ~TaskFactoryRegistry() = default;
49 
50  template<typename FactoryType, typename... Ts>
52  auto task_factory_shared = std::shared_ptr<TaskFactory>(std::unique_ptr<TaskFactory>(new FactoryType));
53 
54  m_task_factories.insert(task_factory_shared);
55 
56  registerTaskFactoryImpl<Ts...>(task_factory_shared);
57  }
58 
59  const TaskFactory& getFactory(std::type_index type_id) const {
60  return *m_type_task_factories_map.at(type_id);
61  }
62 
63  // Configurable interface
64  virtual void reportConfigDependencies(Euclid::Configuration::ConfigManager& manager) const override;
65  virtual void configure(Euclid::Configuration::ConfigManager& manager) override;
66 
67  void registerPropertyInstances(OutputRegistry& output_registry);
68 
69 private:
70  template<typename T>
72  auto type_index = std::type_index(typeid(T));
73  // if we already have a factory for a property_id, throw an exception
76  }
77  m_type_task_factories_map[type_index] = task_factory;
78  }
79 
80  template<typename T, typename T2, typename... Ts>
82  registerTaskFactoryImpl<T>(task_factory);
83  registerTaskFactoryImpl<T2, Ts...>(task_factory);
84  }
85 
88 };
89 
90 }
91 
92 
93 
94 #endif /* _SEFRAMEWORK_TASK_TASKFACTORYREGISTRY_H_ */
Exception(ExitCode e=ExitCode::NOT_OK)
Interface of objects which can be configured.
Definition: Configurable.h:37
Exception raised when trying to register 2 TaskFactories that produce the same PropertyType.
virtual ~TaskFactoryRegistry()=default
std::unordered_set< std::shared_ptr< TaskFactory > > m_task_factories
void registerTaskFactoryImpl(std::shared_ptr< TaskFactory > task_factory)
virtual void configure(Euclid::Configuration::ConfigManager &manager) override
Method which should initialize the object.
void registerTaskFactoryImpl(std::shared_ptr< TaskFactory > task_factory)
const TaskFactory & getFactory(std::type_index type_id) const
void registerPropertyInstances(OutputRegistry &output_registry)
virtual void reportConfigDependencies(Euclid::Configuration::ConfigManager &manager) const override
Registers all the Configuration dependencies.
std::unordered_map< std::type_index, std::shared_ptr< TaskFactory > > m_type_task_factories_map
Creates a Task for computing a given property.
Definition: TaskFactory.h:42