From 0a72984c07b489d0da08f38f27f7052e964e9c93 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 27 Apr 2021 00:32:52 +0100 Subject: Fix the odd difference with arrays and vectors and objects --- lib/jsonParse-persistance.cpp | 2 ++ lib/persistance.h | 47 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/jsonParse-persistance.cpp b/lib/jsonParse-persistance.cpp index ad9fc2a..00b84dd 100644 --- a/lib/jsonParse-persistance.cpp +++ b/lib/jsonParse-persistance.cpp @@ -19,6 +19,7 @@ namespace Persistanace { void JsonParsePersistance::BeginArray() { + current()->beforeValue(stk); current()->BeginArray(stk); } @@ -56,6 +57,7 @@ namespace Persistanace { JsonParsePersistance::EndArray() { stk.pop(); + stk.pop(); } void diff --git a/lib/persistance.h b/lib/persistance.h index 8e38250..2568e8e 100644 --- a/lib/persistance.h +++ b/lib/persistance.h @@ -72,36 +72,63 @@ namespace Persistanace { }; template struct SelectionT> : public Selection { - explicit SelectionT(glm::vec & value) : v {value} { } + using V = glm::vec; + + struct Members : public Selection { + explicit Members(V & value) : v {value} { } + + void + beforeValue(Stack & stk) override + { + stk.push(std::make_unique>(std::ref(v[idx++]))); + } + + V & v; + glm::length_t idx {0}; + }; + + explicit SelectionT(V & value) : v {value} { } void - BeginArray(Stack &) override + BeginArray(Stack & stk) override { + stk.push(std::make_unique(std::ref(v))); } void - beforeValue(Stack & stk) override + beforeValue(Stack &) override { - stk.push(std::make_unique>(std::ref(v[idx++]))); } - glm::vec & v; - glm::length_t idx {0}; + V & v; }; template struct SelectionT> : public Selection { - explicit SelectionT(std::vector & value) : v {value} { } + using V = std::vector; + + struct Members : public Selection { + explicit Members(V & value) : v {value} { } + + void + beforeValue(Stack & stk) override + { + stk.push(std::make_unique>(std::ref(v.emplace_back()))); + } + + V & v; + }; + + explicit SelectionT(V & value) : v {value} { } void BeginArray(Stack & stk) override { - stk.push(std::make_unique>(std::ref(v.emplace_back()))); + stk.push(std::make_unique(std::ref(v))); } void - beforeValue(Stack & stk) override + beforeValue(Stack &) override { - stk.push(std::make_unique>(std::ref(v.emplace_back()))); } std::vector & v; -- cgit v1.2.3