51 typedef std::function<std::unique_ptr<I>()> fn;
52 typedef std::map<std::string, fn> map;
54 static void setExternalImplementation(fn generator)
57 staticInstance = std::move(spf());
60 static void setImplementation(
const std::string& implName)
64 setExternalImplementation(functionMap.at(implName));
65 }
catch (
const std::out_of_range& oor) {
66 std::throw_with_nested(std::runtime_error(
67 "No implementation named " + implName +
" found for Module " + moduleName()));
71 static std::unique_ptr<I> getInstance() {
return spf(); }
73 static I& getImplementation() {
return *staticInstance; }
75 static std::list<std::string> listImplementations()
77 std::list<std::string> keys;
78 for (
auto entry : functionMap) {
79 keys.push_back(entry.first);
84 static std::string implementation()
86 typedef std::unique_ptr<I>(fnType)();
90 for (
auto entry : functionMap) {
91 if (*entry.second.template target<fnType*>() == *spf.template target<fnType*>()) {
98 static std::string moduleName();
102 static std::unique_ptr<I> staticInstance;
103 static map functionMap;