SourceXtractorPlusPlus
0.15
Please provide a description of the project.
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
SEFramework
SEFramework
Task
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
32
#include "
SEFramework/Configuration/Configurable.h
"
33
34
namespace
SourceXtractor {
35
36
class
OutputRegistry;
37
class
TaskFactory;
38
39
class
TaskFactoryRegistry
:
public
Configurable
{
40
public
:
41
43
class
DuplicateFactoryException
:
public
Elements::Exception
{
44
public
:
45
DuplicateFactoryException
() : Elements::
Exception
(
"Duplicate PropertyId in TaskProvider"
) {}
46
};
47
48
virtual
~TaskFactoryRegistry
() =
default
;
49
50
template
<
typename
FactoryType,
typename
... Ts>
51
void
registerTaskFactory
() {
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>
71
void
registerTaskFactoryImpl
(
std::shared_ptr<TaskFactory>
task_factory) {
72
auto
type_index
=
std::type_index
(
typeid
(T));
73
// if we already have a factory for a property_id, throw an exception
74
if
(
m_type_task_factories_map
.find(
type_index
) !=
m_type_task_factories_map
.end()) {
75
throw
DuplicateFactoryException
();
76
}
77
m_type_task_factories_map
[
type_index
] = task_factory;
78
}
79
80
template
<
typename
T,
typename
T2,
typename
... Ts>
81
void
registerTaskFactoryImpl
(
std::shared_ptr<TaskFactory>
task_factory) {
82
registerTaskFactoryImpl<T>(task_factory);
83
registerTaskFactoryImpl
<T2, Ts...>(task_factory);
84
}
85
86
std::unordered_set<std::shared_ptr<TaskFactory>
>
m_task_factories
;
87
std::unordered_map<std::type_index, std::shared_ptr<TaskFactory>
>
m_type_task_factories_map
;
88
};
89
90
}
91
92
93
94
#endif
/* _SEFRAMEWORK_TASK_TASKFACTORYREGISTRY_H_ */
SourceXtractor::TaskFactoryRegistry::registerTaskFactoryImpl
void registerTaskFactoryImpl(std::shared_ptr< TaskFactory > task_factory)
Definition:
TaskFactoryRegistry.h:81
std::shared_ptr
SourceXtractor::TaskFactoryRegistry::m_type_task_factories_map
std::unordered_map< std::type_index, std::shared_ptr< TaskFactory > > m_type_task_factories_map
Definition:
TaskFactoryRegistry.h:87
SourceXtractor::OutputRegistry
Definition:
OutputRegistry.h:36
SourceXtractor::TaskFactoryRegistry::DuplicateFactoryException
Exception raised when trying to register 2 TaskFactories that produce the same PropertyType.
Definition:
TaskFactoryRegistry.h:43
SourceXtractor::Configurable
Interface of objects which can be configured.
Definition:
Configurable.h:37
SourceXtractor::TaskFactoryRegistry::registerTaskFactory
void registerTaskFactory()
Definition:
TaskFactoryRegistry.h:51
SourceXtractor::TaskFactoryRegistry::reportConfigDependencies
virtual void reportConfigDependencies(Euclid::Configuration::ConfigManager &manager) const override
Registers all the Configuration dependencies.
Definition:
TaskFactoryRegistry.cpp:29
SourceXtractor::TaskFactoryRegistry::~TaskFactoryRegistry
virtual ~TaskFactoryRegistry()=default
SourceXtractor::TaskFactoryRegistry::getFactory
const TaskFactory & getFactory(std::type_index type_id) const
Definition:
TaskFactoryRegistry.h:59
std::type_index
Euclid::Configuration::ConfigManager
SourceXtractor::TaskFactory
Creates a Task for computing a given property.
Definition:
TaskFactory.h:42
std::unordered_set
STL class.
SourceXtractor::TaskFactoryRegistry::m_task_factories
std::unordered_set< std::shared_ptr< TaskFactory > > m_task_factories
Definition:
TaskFactoryRegistry.h:86
Elements::Exception::Exception
Exception(ExitCode e=ExitCode::NOT_OK)
SourceXtractor::TaskFactoryRegistry::registerPropertyInstances
void registerPropertyInstances(OutputRegistry &output_registry)
Definition:
TaskFactoryRegistry.cpp:42
SourceXtractor::TaskFactoryRegistry
Definition:
TaskFactoryRegistry.h:39
std::unique_ptr
STL class.
Elements::Exception
SourceXtractor::TaskFactoryRegistry::configure
virtual void configure(Euclid::Configuration::ConfigManager &manager) override
Method which should initialize the object.
Definition:
TaskFactoryRegistry.cpp:36
SourceXtractor::TaskFactoryRegistry::registerTaskFactoryImpl
void registerTaskFactoryImpl(std::shared_ptr< TaskFactory > task_factory)
Definition:
TaskFactoryRegistry.h:71
Configurable.h
SourceXtractor::TaskFactoryRegistry::DuplicateFactoryException::DuplicateFactoryException
DuplicateFactoryException()
Definition:
TaskFactoryRegistry.h:45
std::unordered_map
STL class.
Generated by
1.8.5