forked from cms-patatrack/pixeltrack-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginFactory.cc
34 lines (29 loc) · 1.04 KB
/
PluginFactory.cc
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
#include "PluginFactory.h"
#include <stdexcept>
namespace edm {
namespace PluginFactory {
namespace impl {
void Registry::add(std::string const& name, std::unique_ptr<MakerBase> maker) {
auto found = pluginRegistry_.find(name);
if (found != pluginRegistry_.end()) {
throw std::logic_error("Plugin " + name + " is already registered");
}
pluginRegistry_.emplace(name, std::move(maker));
}
MakerBase const* Registry::get(std::string const& name) {
auto found = pluginRegistry_.find(name);
if (found == pluginRegistry_.end()) {
throw std::logic_error("Plugin " + name + " is not registered");
}
return found->second.get();
}
Registry& getGlobalRegistry() {
static Registry reg;
return reg;
}
}; // namespace impl
std::unique_ptr<Worker> create(std::string const& name, ProductRegistry& reg) {
return impl::getGlobalRegistry().get(name)->create(reg);
}
} // namespace PluginFactory
} // namespace edm