From 1511e3f3faadc61b462577ccc9c740157982b867 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 26 Feb 2024 22:26:10 +0000 Subject: Add read persistence support for tuple and pair --- lib/persistence.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/lib/persistence.h b/lib/persistence.h index 75f578e..3c95a00 100644 --- a/lib/persistence.h +++ b/lib/persistence.h @@ -331,6 +331,65 @@ namespace Persistence { } }; + template struct SelectionT> : public SelectionV> { + using V = std::tuple; + using SelectionV::SelectionV; + + struct Members : public SelectionV { + template + explicit Members(V & v, std::integer_sequence) : + SelectionV {v}, members {SelectionV>::make(std::get(v))...} + { + } + + void + beforeValue(Stack & stk) override + { + stk.push(std::move(members[idx++])); + } + + std::size_t idx {0}; + std::array> members; + }; + + void + beginArray(Stack & stk) override + { + stk.push(this->template make_s( + this->v, std::make_integer_sequence>())); + } + }; + + template struct SelectionT> : public SelectionV> { + using V = std::pair; + using SelectionV::SelectionV; + + struct Members : public SelectionV { + explicit Members(V & v) : + SelectionV {v}, members { + SelectionV::make(v.first), + SelectionV::make(v.second), + } + { + } + + void + beforeValue(Stack & stk) override + { + stk.push(std::move(members[idx++])); + } + + std::size_t idx {0}; + std::array members; + }; + + void + beginArray(Stack & stk) override + { + stk.push(this->template make_s(this->v)); + } + }; + template struct MapByMember : public Persistence::SelectionT { MapByMember(Map & m) : Persistence::SelectionT {s}, map {m} { } -- cgit v1.2.3