aboutsummaryrefslogtreecommitdiff
path: root/c/data.h
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-18 01:52:32 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-18 01:52:32 +0200
commita9a4938f87cb3ce2a0214d45925bcdb4ba8d2a28 (patch)
treeff48d053aba1b93dc0771ed20b99d7e0211dd101 /c/data.h
parent5f92d1e00e12085bedc86c6274b254589053c411 (diff)
downloadEpisodeBrowser-a9a4938f87cb3ce2a0214d45925bcdb4ba8d2a28.tar.gz
Move file views out of EpisodeListView and DataListView.
Diffstat (limited to 'c/data.h')
-rw-r--r--c/data.h11
1 files changed, 8 insertions, 3 deletions
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<T>)
- if (t.version != Version<T>)
+ if constexpr (HasVersion<T>) {
+ if (t.version == 0) {
+ T t_;
+ memcpy(&t, &t_, sizeof(T));
+ } else if (t.version != Version<T>)
throw std::runtime_error("invalid struct version");
+ }
/* TODO: Use a custom exception type that informs the
* user of possible data corruption. */