From 645d354ffa214cf366521e7f601b401d8f2c5879 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 16 Nov 2020 14:51:50 -0800 Subject: Add a close method to the win32 ifstream --- common/alfstream.cpp | 13 ++++++++----- common/alfstream.h | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'common') diff --git a/common/alfstream.cpp b/common/alfstream.cpp index 7378c678..3beda833 100644 --- a/common/alfstream.cpp +++ b/common/alfstream.cpp @@ -88,11 +88,7 @@ auto filebuf::seekpos(pos_type pos, std::ios_base::openmode mode) -> pos_type } filebuf::~filebuf() -{ - if(mFile != INVALID_HANDLE_VALUE) - CloseHandle(mFile); - mFile = INVALID_HANDLE_VALUE; -} +{ close(); } bool filebuf::open(const wchar_t *filename, std::ios_base::openmode mode) { @@ -115,6 +111,13 @@ bool filebuf::open(const char *filename, std::ios_base::openmode mode) return open(wname.c_str(), mode); } +void filebuf::close() +{ + if(mFile != INVALID_HANDLE_VALUE) + CloseHandle(mFile); + mFile = INVALID_HANDLE_VALUE; +} + ifstream::ifstream(const wchar_t *filename, std::ios_base::openmode mode) : std::istream{nullptr} diff --git a/common/alfstream.h b/common/alfstream.h index 046a6e2a..353fd2de 100644 --- a/common/alfstream.h +++ b/common/alfstream.h @@ -34,6 +34,8 @@ public: bool open(const char *filename, std::ios_base::openmode mode); bool is_open() const noexcept { return mFile != INVALID_HANDLE_VALUE; } + + void close(); }; // Inherit from std::istream to use our custom streambuf @@ -50,6 +52,8 @@ public: ~ifstream() override; bool is_open() const noexcept { return mStreamBuf.is_open(); } + + void close() { mStreamBuf.close(); } }; } // namespace al -- cgit v1.2.3