diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-11-28 01:53:41 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-11-28 01:53:41 +0000 |
commit | 6e511725b79cbb961633b6d61491e72d6fad49b7 (patch) | |
tree | 25c572de22f071d574f153bfd2fd16a4aba4e1a5 | |
parent | Fix up lots of static analyzer warnings (diff) | |
download | ilt-6e511725b79cbb961633b6d61491e72d6fad49b7.tar.bz2 ilt-6e511725b79cbb961633b6d61491e72d6fad49b7.tar.xz ilt-6e511725b79cbb961633b6d61491e72d6fad49b7.zip |
No global static for factory map
-rw-r--r-- | lib/persistence.cpp | 14 |
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 |