forked from cms-patatrack/pixeltrack-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PluginFactory.h
55 lines (42 loc) · 1.41 KB
/
PluginFactory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef PluginFactory_h
#define PluginFactory_h
#include <memory>
#include <string>
#include <unordered_map>
#include "Framework/Worker.h"
class ProductRegistry;
// Nothing here is thread safe
namespace edm {
namespace PluginFactory {
namespace impl {
class MakerBase {
public:
virtual ~MakerBase() = default;
virtual std::unique_ptr<Worker> create(ProductRegistry& reg) const = 0;
};
template <typename T>
class Maker : public MakerBase {
public:
virtual std::unique_ptr<Worker> create(ProductRegistry& reg) const override {
return std::make_unique<WorkerT<T>>(reg);
};
};
class Registry {
public:
void add(std::string const& name, std::unique_ptr<MakerBase> maker);
MakerBase const* get(std::string const& name);
private:
std::unordered_map<std::string, std::unique_ptr<MakerBase>> pluginRegistry_;
};
Registry& getGlobalRegistry();
template <typename T>
class Registrar {
public:
Registrar(std::string const& name) { getGlobalRegistry().add(name, std::make_unique<Maker<T>>()); }
};
} // namespace impl
std::unique_ptr<Worker> create(std::string const& name, ProductRegistry& reg);
} // namespace PluginFactory
} // namespace edm
#define DEFINE_FWK_MODULE(name) static edm::PluginFactory::impl::Registrar<name> reg_##name(#name);
#endif