diff options
Diffstat (limited to 'include/cru')
-rw-r--r-- | include/cru/common/Exception.h | 3 | ||||
-rw-r--r-- | include/cru/common/io/FileNotExistException.h | 19 | ||||
-rw-r--r-- | include/cru/common/io/OpenFileFlag.h | 12 |
3 files changed, 33 insertions, 1 deletions
diff --git a/include/cru/common/Exception.h b/include/cru/common/Exception.h index 6f458d35..d7e32a5a 100644 --- a/include/cru/common/Exception.h +++ b/include/cru/common/Exception.h @@ -20,6 +20,9 @@ class CRU_BASE_API Exception : public std::exception { const char* what() const noexcept override; + protected: + void SetMessage(String message) { message_ = std::move(message); } + private: String message_; mutable std::string utf8_message_; diff --git a/include/cru/common/io/FileNotExistException.h b/include/cru/common/io/FileNotExistException.h new file mode 100644 index 00000000..f49271b1 --- /dev/null +++ b/include/cru/common/io/FileNotExistException.h @@ -0,0 +1,19 @@ +#pragma once + +#include "../Base.h" +#include "../Exception.h" + +namespace cru::io { + class CRU_BASE_API FileNotExistException : public Exception { + public: + FileNotExistException(String path); + + CRU_DEFAULT_COPY(FileNotExistException) + CRU_DEFAULT_MOVE(FileNotExistException) + + ~FileNotExistException() override = default; + + private: + String path_; + }; +} diff --git a/include/cru/common/io/OpenFileFlag.h b/include/cru/common/io/OpenFileFlag.h index fd8b6e2c..4a5789fb 100644 --- a/include/cru/common/io/OpenFileFlag.h +++ b/include/cru/common/io/OpenFileFlag.h @@ -11,11 +11,14 @@ using OpenFileFlag = Bitmask<details::OpenFileFlagTag>; struct OpenFileFlags { /** * \brief for reading + * If the file does not exist, FileNotExistException should be thrown. */ static constexpr OpenFileFlag Read{0x1}; /** * \brief for writing + * If the file does not exist and Create is not specified, + * FileNotExistException should be thrown. */ static constexpr OpenFileFlag Write{0x2}; @@ -34,7 +37,8 @@ struct OpenFileFlags { /** * \brief when writing, if the file does not exist, create one - * Only effective for writing. + * Only effective for writing. When file does not exist, FileNotExistException + * will NOT be thrown and a new file will be created. */ static constexpr OpenFileFlag Create{0x10}; @@ -43,4 +47,10 @@ struct OpenFileFlags { */ static constexpr OpenFileFlag Exclusive{0x20}; }; + +/** + * Append, Truncate, Create must be used with Write. + * Append and Truncate must not be used together. + */ +bool CheckOpenFileFlag(OpenFileFlag flags); } // namespace cru::io |