diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-04-27 00:32:52 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-11-07 16:41:37 +0000 |
commit | 0a72984c07b489d0da08f38f27f7052e964e9c93 (patch) | |
tree | 2f42443ba7e90deb64ee5969d490e28eced9a3d4 | |
parent | Remove ArrayLike (diff) | |
download | ilt-0a72984c07b489d0da08f38f27f7052e964e9c93.tar.bz2 ilt-0a72984c07b489d0da08f38f27f7052e964e9c93.tar.xz ilt-0a72984c07b489d0da08f38f27f7052e964e9c93.zip |
Fix the odd difference with arrays and vectors and objects
-rw-r--r-- | lib/jsonParse-persistance.cpp | 2 | ||||
-rw-r--r-- | lib/persistance.h | 47 |
2 files changed, 39 insertions, 10 deletions
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<glm::length_t L, typename T, glm::qualifier Q> struct SelectionT<glm::vec<L, T, Q>> : public Selection { - explicit SelectionT(glm::vec<L, float, Q> & value) : v {value} { } + using V = glm::vec<L, float, Q>; + + struct Members : public Selection { + explicit Members(V & value) : v {value} { } + + void + beforeValue(Stack & stk) override + { + stk.push(std::make_unique<SelectionT<T>>(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<Members>(std::ref(v))); } void - beforeValue(Stack & stk) override + beforeValue(Stack &) override { - stk.push(std::make_unique<SelectionT<T>>(std::ref(v[idx++]))); } - glm::vec<L, T, Q> & v; - glm::length_t idx {0}; + V & v; }; template<typename T> struct SelectionT<std::vector<T>> : public Selection { - explicit SelectionT(std::vector<T> & value) : v {value} { } + using V = std::vector<T>; + + struct Members : public Selection { + explicit Members(V & value) : v {value} { } + + void + beforeValue(Stack & stk) override + { + stk.push(std::make_unique<SelectionT<T>>(std::ref(v.emplace_back()))); + } + + V & v; + }; + + explicit SelectionT(V & value) : v {value} { } void BeginArray(Stack & stk) override { - stk.push(std::make_unique<SelectionT<T>>(std::ref(v.emplace_back()))); + stk.push(std::make_unique<Members>(std::ref(v))); } void - beforeValue(Stack & stk) override + beforeValue(Stack &) override { - stk.push(std::make_unique<SelectionT<T>>(std::ref(v.emplace_back()))); } std::vector<T> & v; |