diff options
Diffstat (limited to 'lib/persistance.cpp')
-rw-r--r-- | lib/persistance.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/persistance.cpp b/lib/persistance.cpp index 0dd7cba..204e8f0 100644 --- a/lib/persistance.cpp +++ b/lib/persistance.cpp @@ -2,19 +2,28 @@ #include <map> namespace Persistanace { - using NamedTypeFactories = std::map<std::string_view, std::function<std::unique_ptr<Persistable>()>>; + 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; void - Persistable::addFactory(const std::string_view t, std::function<std::unique_ptr<Persistable>()> f) + 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::move(f)); + 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)(); + return namedTypeFactories.at(t).first(); + } + + std::shared_ptr<Persistable> + Persistable::callSharedFactory(const std::string_view t) + { + return namedTypeFactories.at(t).second(); } void |