diff options
author | John Ankarström <john@ankarstrom.se> | 2022-08-18 01:52:32 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-08-18 01:52:32 +0200 |
commit | a9a4938f87cb3ce2a0214d45925bcdb4ba8d2a28 (patch) | |
tree | ff48d053aba1b93dc0771ed20b99d7e0211dd101 /c/data.h | |
parent | 5f92d1e00e12085bedc86c6274b254589053c411 (diff) | |
download | EpisodeBrowser-a9a4938f87cb3ce2a0214d45925bcdb4ba8d2a28.tar.gz |
Move file views out of EpisodeListView and DataListView.
Diffstat (limited to 'c/data.h')
-rw-r--r-- | c/data.h | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -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. */ |