From bf0a1a219e48007ca51e23ea45d08d295e398fcd Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 21 Feb 2023 00:03:08 +0000 Subject: Add helper Selection to insert into a map based on a member value as key --- lib/persistence.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/persistence.h b/lib/persistence.h index 01b2a7e..d55062a 100644 --- a/lib/persistence.h +++ b/lib/persistence.h @@ -256,6 +256,23 @@ namespace Persistence { } }; + template + struct MapByMember : public Persistence::SelectionT> { + MapByMember(Map & m) : Persistence::SelectionT> {s}, map {m} { } + + using Persistence::SelectionT>::SelectionT; + void + endObject(Persistence::Stack & stk) override + { + map.emplace(std::invoke(Key, s), s); + stk.pop(); + } + + private: + std::shared_ptr s; + Map & map; + }; + struct Persistable { Persistable() = default; virtual ~Persistable() = default; -- cgit v1.2.3