summaryrefslogtreecommitdiff
path: root/lib/persistance.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-04-27 00:32:52 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-11-07 16:41:37 +0000
commit0a72984c07b489d0da08f38f27f7052e964e9c93 (patch)
tree2f42443ba7e90deb64ee5969d490e28eced9a3d4 /lib/persistance.h
parentRemove ArrayLike (diff)
downloadilt-0a72984c07b489d0da08f38f27f7052e964e9c93.tar.bz2
ilt-0a72984c07b489d0da08f38f27f7052e964e9c93.tar.xz
ilt-0a72984c07b489d0da08f38f27f7052e964e9c93.zip
Fix the odd difference with arrays and vectors and objects
Diffstat (limited to 'lib/persistance.h')
-rw-r--r--lib/persistance.h47
1 files changed, 37 insertions, 10 deletions
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;