aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-26 15:21:54 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-26 15:21:54 +0200
commitf6b71341feb71730e7ab416f5733b774f620374c (patch)
treeab0217e96c57252f5e70648c07b87ae1984d4ddf
parent83844c475575a8079fa04734ae399cd5d2cab08b (diff)
downloadEpisodeBrowser-f6b71341feb71730e7ab416f5733b774f620374c.tar.gz
FileView: Add move constructor, assignment operator.
-rw-r--r--c/data.h32
1 files changed, 26 insertions, 6 deletions
diff --git a/c/data.h b/c/data.h
index 4fbf3e4..7ca5e6c 100644
--- a/c/data.h
+++ b/c/data.h
@@ -93,11 +93,29 @@ struct FileView
memcpy(fv+i, &t, sizeof(T));
}
- return { filename, c };
+ return {filename, c};
}
FileView(FileView<T>&) = delete;
- FileView(FileView<T>&& fv) = delete;
+ FileView<T>& operator =(const FileView<unsigned char>&) = delete;
+
+ FileView(FileView<T>&& other)
+ {
+ hf = other.hf;
+ hm = other.hf;
+ view = other.view;
+ c = other.c;
+ other.view = nullptr;
+ }
+ FileView<T>& operator =(FileView<unsigned char>&& other)
+ {
+ hf = other.hf;
+ hm = other.hf;
+ view = other.view;
+ c = other.c;
+ other.view = nullptr;
+ return *this;
+ }
FileView(const wchar_t* filename, size_t c) : c(c)
{
@@ -131,10 +149,12 @@ struct FileView
~FileView()
{
- FlushViewOfFile(view, 0);
- UnmapViewOfFile(view);
- CloseHandle(hm);
- CloseHandle(hf);
+ if (view) {
+ FlushViewOfFile(view, 0);
+ UnmapViewOfFile(view);
+ CloseHandle(hm);
+ CloseHandle(hf);
+ }
}
/* Access element by index, performing bounds check and, if