summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-02-26 22:26:10 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-02-26 22:26:10 +0000
commit1511e3f3faadc61b462577ccc9c740157982b867 (patch)
tree4b83fed103a0aac9eac6b1b8f3f8ad829a85afdf /lib
parentSupport extra arguments in SelectionV::make_s (diff)
downloadilt-1511e3f3faadc61b462577ccc9c740157982b867.tar.bz2
ilt-1511e3f3faadc61b462577ccc9c740157982b867.tar.xz
ilt-1511e3f3faadc61b462577ccc9c740157982b867.zip
Add read persistence support for tuple and pair
Diffstat (limited to 'lib')
-rw-r--r--lib/persistence.h59
1 files changed, 59 insertions, 0 deletions
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<typename... T> struct SelectionT<std::tuple<T...>> : public SelectionV<std::tuple<T...>> {
+ using V = std::tuple<T...>;
+ using SelectionV<V>::SelectionV;
+
+ struct Members : public SelectionV<V> {
+ template<size_t... Idx>
+ explicit Members(V & v, std::integer_sequence<size_t, Idx...>) :
+ SelectionV<V> {v}, members {SelectionV<std::tuple_element_t<Idx, V>>::make(std::get<Idx>(v))...}
+ {
+ }
+
+ void
+ beforeValue(Stack & stk) override
+ {
+ stk.push(std::move(members[idx++]));
+ }
+
+ std::size_t idx {0};
+ std::array<SelectionPtr, std::tuple_size_v<V>> members;
+ };
+
+ void
+ beginArray(Stack & stk) override
+ {
+ stk.push(this->template make_s<Members>(
+ this->v, std::make_integer_sequence<size_t, std::tuple_size_v<V>>()));
+ }
+ };
+
+ template<typename T, typename U> struct SelectionT<std::pair<T, U>> : public SelectionV<std::pair<T, U>> {
+ using V = std::pair<T, U>;
+ using SelectionV<V>::SelectionV;
+
+ struct Members : public SelectionV<V> {
+ explicit Members(V & v) :
+ SelectionV<V> {v}, members {
+ SelectionV<T>::make(v.first),
+ SelectionV<U>::make(v.second),
+ }
+ {
+ }
+
+ void
+ beforeValue(Stack & stk) override
+ {
+ stk.push(std::move(members[idx++]));
+ }
+
+ std::size_t idx {0};
+ std::array<SelectionPtr, 2> members;
+ };
+
+ void
+ beginArray(Stack & stk) override
+ {
+ stk.push(this->template make_s<Members>(this->v));
+ }
+ };
+
template<typename Map, typename Type = typename Map::mapped_type, auto Key = &Type::element_type::id>
struct MapByMember : public Persistence::SelectionT<Type> {
MapByMember(Map & m) : Persistence::SelectionT<Type> {s}, map {m} { }