From f6b71341feb71730e7ab416f5733b774f620374c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 26 Aug 2022 15:21:54 +0200 Subject: FileView: Add move constructor, assignment operator. --- c/data.h | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'c/data.h') 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&) = delete; - FileView(FileView&& fv) = delete; + FileView& operator =(const FileView&) = delete; + + FileView(FileView&& other) + { + hf = other.hf; + hm = other.hf; + view = other.view; + c = other.c; + other.view = nullptr; + } + FileView& operator =(FileView&& 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 -- cgit v1.2.3