summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/persistence.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/persistence.cpp b/lib/persistence.cpp
index 5338738..239e425 100644
--- a/lib/persistence.cpp
+++ b/lib/persistence.cpp
@@ -6,25 +6,31 @@ namespace Persistence {
using Factories
= std::pair<std::function<std::unique_ptr<Persistable>()>, std::function<std::shared_ptr<Persistable>()>>;
using NamedTypeFactories = std::map<std::string_view, Factories>;
- static NamedTypeFactories namedTypeFactories;
+
+ inline static auto &
+ namedTypeFactories()
+ {
+ static NamedTypeFactories namedTypeFactories;
+ return namedTypeFactories;
+ }
void
Persistable::addFactory(const std::string_view t, std::function<std::unique_ptr<Persistable>()> fu,
std::function<std::shared_ptr<Persistable>()> fs)
{
- namedTypeFactories.emplace(t, std::make_pair(std::move(fu), std::move(fs)));
+ namedTypeFactories().emplace(t, std::make_pair(std::move(fu), std::move(fs)));
}
std::unique_ptr<Persistable>
Persistable::callFactory(const std::string_view t)
{
- return namedTypeFactories.at(t).first();
+ return namedTypeFactories().at(t).first();
}
std::shared_ptr<Persistable>
Persistable::callSharedFactory(const std::string_view t)
{
- return namedTypeFactories.at(t).second();
+ return namedTypeFactories().at(t).second();
}
[[nodiscard]] std::string