diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-02-20 19:14:55 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-02-21 00:36:06 +0000 |
commit | 223ecbc450fede9f8ca246895d5f82495f8665e8 (patch) | |
tree | e20a1ba0bb48b47e3c4649527058ce878e6856c0 /lib | |
parent | Make sure an object is created before remembering it (diff) | |
download | ilt-223ecbc450fede9f8ca246895d5f82495f8665e8.tar.bz2 ilt-223ecbc450fede9f8ca246895d5f82495f8665e8.tar.xz ilt-223ecbc450fede9f8ca246895d5f82495f8665e8.zip |
Allow override member variable names and selection helper when mapping members for persistence
Diffstat (limited to 'lib')
-rw-r--r-- | lib/persistence.h | 13 |
1 files changed, 8 insertions, 5 deletions
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<typename T> [[nodiscard]] inline bool persistType(const T * const, const std::type_info & ti); enum class NameAction { Push, HandleAndContinue, Ignore }; - template<typename T> + template<typename Helper, typename T> [[nodiscard]] inline bool persistValue(const std::string_view key, T & value) { - SelectionT<T> s {value}; - const auto act {setName(key, s)}; + auto s = std::make_unique<Helper>(value); + const auto act {setName(key, *s)}; if (act != NameAction::Ignore) { - sel = std::make_unique<decltype(s)>(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<Persistence::SelectionT<decltype(mbr)>>(name, mbr) +#define STORE_HELPER(mbr, Helper) STORE_NAME_HELPER(#mbr, mbr, Helper) +#define STORE_NAME_HELPER(name, mbr, Helper) store.persistValue<Helper>(name, mbr) |