diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2024-09-24 07:33:05 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2024-09-24 07:33:05 -0500 |
commit | 204dad55119df079ca54309bc4b740280fa54c31 (patch) | |
tree | 4f224b7a652cfb567aa197d0fd29de6eaafe630e /include | |
parent | 404de2dfde39ca181db531427638f249c6e334e7 (diff) |
Fine tune read interface of CBinaryFile.
Diffstat (limited to 'include')
-rw-r--r-- | include/fud_c_file.hpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/include/fud_c_file.hpp b/include/fud_c_file.hpp index b48e8a0..f563a35 100644 --- a/include/fud_c_file.hpp +++ b/include/fud_c_file.hpp @@ -80,6 +80,7 @@ constexpr const char* CTextFileModeFromFlags(CFileMode mode) enum class FileStatus { Success, + PartialSuccess, InvalidName, InvalidArgument, InvalidState, @@ -91,6 +92,8 @@ static inline const char* FileStatusToString(FileStatus status) { switch (status) { case FileStatus::Success: return "Success"; + case FileStatus::PartialSuccess: + return "PartialSuccess"; case FileStatus::InvalidName: return "InvalidName"; case FileStatus::InvalidArgument: @@ -106,6 +109,11 @@ static inline const char* FileStatusToString(FileStatus status) { } } +struct [[nodiscard]] ReadResult { + size_t bytesRead{0}; + FileStatus status{FileStatus::Success}; +}; + class CBinaryFile { public: CBinaryFile(const String& filename, CFileMode mode); @@ -122,15 +130,21 @@ class CBinaryFile { [[nodiscard]] Result<size_t, FileStatus> size() const; - template <typename T> - [[nodiscard]] FileStatus read(T& destination, size_t length); + [[nodiscard]] ReadResult read(void* destination, size_t destinationSize, size_t length); - template <typename T> - [[nodiscard]] FileStatus read(T& destination, size_t length, size_t offset); + [[nodiscard]] ReadResult read(void* destination, size_t destinationSize, size_t length, size_t offset); - [[nodiscard]] FileStatus read(void* destination, size_t destinationSize, size_t length); + template <typename T> + [[nodiscard]] ReadResult read(T& destination, size_t length) + { + return read(destination, length, 0); + } - [[nodiscard]] FileStatus read(void* destination, size_t destinationSize, size_t length, size_t offset); + template <typename T> + [[nodiscard]] ReadResult read(T& destination, size_t length, size_t offset) + { + return read(&destination, sizeof(destination), length, offset); + } private: FileStatus reset() const; |