summaryrefslogtreecommitdiff
path: root/lib/persistence.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/persistence.h')
-rw-r--r--lib/persistence.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/persistence.h b/lib/persistence.h
index 1cb3af0..d38d4b1 100644
--- a/lib/persistence.h
+++ b/lib/persistence.h
@@ -149,6 +149,7 @@ namespace Persistence {
struct Persistable;
struct PersistenceStore {
+ using SelectionFactory = std::function<SelectionPtr()>;
PersistenceStore() = default;
virtual ~PersistenceStore() = default;
DEFAULT_MOVE_NO_COPY(PersistenceStore);
@@ -156,12 +157,14 @@ namespace Persistence {
template<typename T> [[nodiscard]] inline bool persistType(const T * const, const std::type_info & ti);
enum class NameAction { Push, HandleAndContinue, Ignore };
+ using NameActionSelection = std::pair<NameAction, SelectionPtr>;
template<typename Helper, typename T>
[[nodiscard]] inline bool
persistValue(const std::string_view key, T & value)
{
- auto s = std::make_unique<Helper>(value);
- const auto act {setName(key, *s)};
+ auto [act, s] = setName(key, [&value]() {
+ return std::make_unique<Helper>(value);
+ });
if (act != NameAction::Ignore) {
sel = std::move(s);
if (act == NameAction::HandleAndContinue) {
@@ -171,7 +174,7 @@ namespace Persistence {
return (act != NameAction::Push);
}
- virtual NameAction setName(const std::string_view key, const Selection &) = 0;
+ [[nodiscard]] virtual NameActionSelection setName(const std::string_view key, SelectionFactory &&) = 0;
virtual void selHandler() {};
virtual void setType(const std::string_view, const Persistable *) = 0;
@@ -181,7 +184,7 @@ namespace Persistence {
struct PersistenceSelect : public PersistenceStore {
explicit PersistenceSelect(const std::string & n);
- NameAction setName(const std::string_view key, const Selection &) override;
+ NameActionSelection setName(const std::string_view key, SelectionFactory &&) override;
void setType(const std::string_view, const Persistable *) override;
@@ -191,7 +194,7 @@ namespace Persistence {
struct PersistenceWrite : public PersistenceStore {
explicit PersistenceWrite(const Writer & o, bool sh);
- NameAction setName(const std::string_view key, const Selection &) override;
+ NameActionSelection setName(const std::string_view key, SelectionFactory &&) override;
void selHandler() override;