From a9a4938f87cb3ce2a0214d45925bcdb4ba8d2a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Thu, 18 Aug 2022 01:52:32 +0200 Subject: Move file views out of EpisodeListView and DataListView. --- c/data.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'c/data.h') diff --git a/c/data.h b/c/data.h index 6d6edd3..da8d108 100644 --- a/c/data.h +++ b/c/data.h @@ -123,7 +123,8 @@ struct FileView } /* Access element by index, performing bounds check and, if - * applicable for T, version validation. */ + * applicable for T, version validation as well as + * initialization, if needed. */ T& At(size_t i) { if (i >= c) @@ -131,9 +132,13 @@ struct FileView T& t = view[i]; - if constexpr (HasVersion) - if (t.version != Version) + if constexpr (HasVersion) { + if (t.version == 0) { + T t_; + memcpy(&t, &t_, sizeof(T)); + } else if (t.version != Version) throw std::runtime_error("invalid struct version"); + } /* TODO: Use a custom exception type that informs the * user of possible data corruption. */ -- cgit v1.2.3