diff options
Diffstat (limited to 'lib')
-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; |