summaryrefslogtreecommitdiff
path: root/lib/persistence.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-03-20 19:32:26 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-03-20 19:32:26 +0000
commit5bfeeb70c6a7ed6ccda0576dc39050eb4240434f (patch)
treee922a446eae5418b725d54bc93d59120dbced3fc /lib/persistence.cpp
parentSlightly tidier FaceController? It's still a mess (diff)
downloadilt-5bfeeb70c6a7ed6ccda0576dc39050eb4240434f.tar.bz2
ilt-5bfeeb70c6a7ed6ccda0576dc39050eb4240434f.tar.xz
ilt-5bfeeb70c6a7ed6ccda0576dc39050eb4240434f.zip
Lazy initialisation of SelectionPtr in persistValue
Always needed for write phase, but only need on read if their's a name match.
Diffstat (limited to 'lib/persistence.cpp')
-rw-r--r--lib/persistence.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/persistence.cpp b/lib/persistence.cpp
index 06e40c7..e22d74d 100644
--- a/lib/persistence.cpp
+++ b/lib/persistence.cpp
@@ -48,10 +48,15 @@ namespace Persistence {
PersistenceSelect::PersistenceSelect(const std::string & n) : name {n} { }
- PersistenceStore::NameAction
- PersistenceSelect::setName(const std::string_view key, const Selection &)
+ PersistenceStore::NameActionSelection
+ PersistenceSelect::setName(const std::string_view key, SelectionFactory && factory)
{
- return (key == name) ? NameAction::Push : NameAction::Ignore;
+ if (key == name) {
+ return {NameAction::Push, factory()};
+ }
+ else {
+ return {NameAction::Ignore, nullptr};
+ }
}
void
@@ -61,10 +66,11 @@ namespace Persistence {
PersistenceWrite::PersistenceWrite(const Writer & o, bool sh) : out {o}, shared {sh} { }
- PersistenceStore::NameAction
- PersistenceWrite::setName(const std::string_view key, const Selection & s)
+ PersistenceStore::NameActionSelection
+ PersistenceWrite::setName(const std::string_view key, SelectionFactory && factory)
{
- if (s.needsWrite()) {
+ auto s = factory();
+ if (s->needsWrite()) {
if (!first) {
out.nextValue();
}
@@ -72,9 +78,9 @@ namespace Persistence {
first = false;
}
out.pushKey(key);
- return NameAction::HandleAndContinue;
+ return {NameAction::HandleAndContinue, std::move(s)};
}
- return NameAction::Ignore;
+ return {NameAction::Ignore, nullptr};
}
void