From 223ecbc450fede9f8ca246895d5f82495f8665e8 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 20 Feb 2023 19:14:55 +0000 Subject: Allow override member variable names and selection helper when mapping members for persistence --- lib/persistence.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/persistence.h b/lib/persistence.h index dbaee44..e1f7605 100644 --- a/lib/persistence.h +++ b/lib/persistence.h @@ -113,14 +113,14 @@ namespace Persistence { template [[nodiscard]] inline bool persistType(const T * const, const std::type_info & ti); enum class NameAction { Push, HandleAndContinue, Ignore }; - template + template [[nodiscard]] inline bool persistValue(const std::string_view key, T & value) { - SelectionT s {value}; - const auto act {setName(key, s)}; + auto s = std::make_unique(value); + const auto act {setName(key, *s)}; if (act != NameAction::Ignore) { - sel = std::make_unique(std::move(s)); + sel = std::move(s); if (act == NameAction::HandleAndContinue) { selHandler(); } @@ -462,4 +462,7 @@ namespace Persistence { } #define STORE_TYPE store.persistType(this, typeid(*this)) -#define STORE_MEMBER(mbr) store.persistValue(#mbr, mbr) +#define STORE_MEMBER(mbr) STORE_NAME_MEMBER(#mbr, mbr) +#define STORE_NAME_MEMBER(name, mbr) store.persistValue>(name, mbr) +#define STORE_HELPER(mbr, Helper) STORE_NAME_HELPER(#mbr, mbr, Helper) +#define STORE_NAME_HELPER(name, mbr, Helper) store.persistValue(name, mbr) -- cgit v1.2.3