diff options
Diffstat (limited to 'src/common/io')
-rw-r--r-- | src/common/io/CFileStream.cpp | 6 | ||||
-rw-r--r-- | src/common/io/FileNotExistException.cpp | 12 | ||||
-rw-r--r-- | src/common/io/Stream.cpp | 4 |
3 files changed, 7 insertions, 15 deletions
diff --git a/src/common/io/CFileStream.cpp b/src/common/io/CFileStream.cpp index de195538..29d4819f 100644 --- a/src/common/io/CFileStream.cpp +++ b/src/common/io/CFileStream.cpp @@ -97,6 +97,7 @@ bool CFileStream::CanRead() { Index CFileStream::Read(std::byte* buffer, Index offset, Index size) { CheckClosed(); + StreamOperationNotSupportedException::CheckRead(readable_); auto count = std::fread(buffer + offset, 1, size, file_); return count; } @@ -108,6 +109,7 @@ bool CFileStream::CanWrite() { Index CFileStream::Write(const std::byte* buffer, Index offset, Index size) { CheckClosed(); + StreamOperationNotSupportedException::CheckWrite(writable_); auto count = std::fwrite(buffer + offset, 1, size, file_); return count; } @@ -125,8 +127,6 @@ void CFileStream::Close() { } void CFileStream::CheckClosed() { - if (file_ == nullptr) { - throw StreamAlreadyClosedException(u"File is closed."); - } + StreamAlreadyClosedException::Check(file_ == nullptr); } } // namespace cru::io diff --git a/src/common/io/FileNotExistException.cpp b/src/common/io/FileNotExistException.cpp deleted file mode 100644 index a2e1fdb1..00000000 --- a/src/common/io/FileNotExistException.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "cru/common/io/FileNotExistException.h" - -#include "cru/common/Exception.h" -#include "cru/common/Format.h" - -#include <utility> - -namespace cru::io { - FileNotExistException::FileNotExistException(String path): Exception(), path_(std::move(path)) { - SetMessage(Format(u"File {} does not exist.", path_)); - } -} diff --git a/src/common/io/Stream.cpp b/src/common/io/Stream.cpp index 07677fa8..97669944 100644 --- a/src/common/io/Stream.cpp +++ b/src/common/io/Stream.cpp @@ -1,4 +1,5 @@ #include "cru/common/io/Stream.h" +#include "cru/common/Exception.h" #include "cru/common/Format.h" #include <utility> @@ -22,6 +23,9 @@ void StreamOperationNotSupportedException::CheckWrite(bool writable) { if (!writable) throw StreamOperationNotSupportedException(u"write"); } +StreamAlreadyClosedException::StreamAlreadyClosedException() + : Exception(u"Stream is already closed.") {} + void StreamAlreadyClosedException::Check(bool closed) { if (closed) throw StreamAlreadyClosedException(); } |