summaryrefslogtreecommitdiff
path: root/lib/persistence.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-03-05 02:39:16 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-03-05 02:39:21 +0000
commitd30757fb3534b4f053e9da2e3ba35323b508e339 (patch)
treea6f845852bc0d4c2b19f955ff203ddb690988a7d /lib/persistence.h
parentMerge branch 'model-factory' (diff)
downloadilt-d30757fb3534b4f053e9da2e3ba35323b508e339.tar.bz2
ilt-d30757fb3534b4f053e9da2e3ba35323b508e339.tar.xz
ilt-d30757fb3534b4f053e9da2e3ba35323b508e339.zip
Replace SelectionT for glm::vec with one for std::span, reimplement it as a wrapper
All the implementation is now shared, regardless of length and qualifier.
Diffstat (limited to 'lib/persistence.h')
-rw-r--r--lib/persistence.h18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/persistence.h b/lib/persistence.h
index 05cb49b..35d60ca 100644
--- a/lib/persistence.h
+++ b/lib/persistence.h
@@ -6,6 +6,7 @@
#include <iosfwd>
#include <map>
#include <memory>
+#include <span>
#include <special_members.hpp>
#include <sstream>
#include <stack>
@@ -201,9 +202,8 @@ namespace Persistence {
bool shared;
};
- template<glm::length_t L, typename T, glm::qualifier Q>
- struct SelectionT<glm::vec<L, T, Q>> : public SelectionV<glm::vec<L, T, Q>> {
- using V = glm::vec<L, T, Q>;
+ template<typename T> struct SelectionT<std::span<T>> : public SelectionV<std::span<T>> {
+ using V = std::span<T>;
struct Members : public SelectionV<V> {
using SelectionV<V>::SelectionV;
@@ -214,12 +214,12 @@ namespace Persistence {
stk.push(SelectionV<T>::make(this->v[idx++]));
}
- glm::length_t idx {0};
+ std::size_t idx {0};
void
write(const Writer & out) const override
{
- for (glm::length_t n = 0; n < L; n += 1) {
+ for (std::size_t n = 0; n < this->v.size(); n += 1) {
if (n) {
out.nextValue();
}
@@ -235,7 +235,7 @@ namespace Persistence {
setValue(std::string && s) override
{
std::stringstream ss {std::move(s)};
- for (glm::length_t n = 0; n < L; n += 1) {
+ for (std::size_t n = 0; n < this->v.size(); n += 1) {
ss >> this->v[n];
ss.get();
}
@@ -256,6 +256,12 @@ namespace Persistence {
}
};
+ template<glm::length_t L, typename T, glm::qualifier Q>
+ struct SelectionT<glm::vec<L, T, Q>> : public SelectionT<std::span<T>> {
+ SelectionT(glm::vec<L, T, Q> & v) : SelectionT<std::span<T>> {spn}, spn {&v[0], L} { }
+ std::span<T> spn;
+ };
+
template<typename T> struct SelectionT<std::vector<T>> : public SelectionV<std::vector<T>> {
using V = std::vector<T>;