diff options
| author | crupest <crupest@outlook.com> | 2024-10-06 13:57:39 +0800 |
|---|---|---|
| committer | crupest <crupest@outlook.com> | 2024-10-06 13:57:39 +0800 |
| commit | dfe62dcf8bcefc523b466e127c3edc4dc2756629 (patch) | |
| tree | 1c751a14ba0da07ca2ff805633f97568060aa4c9 /include/cru/base/io/OpenFileFlag.h | |
| parent | f51eb955e188858272230a990565931e7403f23b (diff) | |
| download | cru-dfe62dcf8bcefc523b466e127c3edc4dc2756629.tar.gz cru-dfe62dcf8bcefc523b466e127c3edc4dc2756629.tar.bz2 cru-dfe62dcf8bcefc523b466e127c3edc4dc2756629.zip | |
Rename common to base.
Diffstat (limited to 'include/cru/base/io/OpenFileFlag.h')
| -rw-r--r-- | include/cru/base/io/OpenFileFlag.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/include/cru/base/io/OpenFileFlag.h b/include/cru/base/io/OpenFileFlag.h new file mode 100644 index 00000000..4a5789fb --- /dev/null +++ b/include/cru/base/io/OpenFileFlag.h @@ -0,0 +1,56 @@ +#pragma once + +#include "../Bitmask.h" + +namespace cru::io { +namespace details { +struct OpenFileFlagTag {}; +} // namespace details +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}; + + /** + * \brief when writing, seek to end first + * Only effective for writing. + */ + static constexpr OpenFileFlag Append{0x4}; + + /** + * \brief when writing, truncate the file to empty + * Only effective for writing. + * So the content is erased! Be careful! + */ + static constexpr OpenFileFlag Truncate{0x8}; + + /** + * \brief when writing, if the file does not exist, create one + * 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}; + + /** + * TODO: ??? + */ + 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 |
