diff options
author | John Ankarström <john@ankarstrom.se> | 2022-08-26 15:21:54 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-08-26 15:21:54 +0200 |
commit | f6b71341feb71730e7ab416f5733b774f620374c (patch) | |
tree | ab0217e96c57252f5e70648c07b87ae1984d4ddf /c/data.h | |
parent | 83844c475575a8079fa04734ae399cd5d2cab08b (diff) | |
download | EpisodeBrowser-f6b71341feb71730e7ab416f5733b774f620374c.tar.gz |
FileView: Add move constructor, assignment operator.
Diffstat (limited to 'c/data.h')
-rw-r--r-- | c/data.h | 32 |
1 files changed, 26 insertions, 6 deletions
@@ -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 |