From 204dad55119df079ca54309bc4b740280fa54c31 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Tue, 24 Sep 2024 07:33:05 -0500 Subject: Fine tune read interface of CBinaryFile. --- include/fud_c_file.hpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'include/fud_c_file.hpp') 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() const; - template - [[nodiscard]] FileStatus read(T& destination, size_t length); + [[nodiscard]] ReadResult read(void* destination, size_t destinationSize, size_t length); - template - [[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 + [[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 + [[nodiscard]] ReadResult read(T& destination, size_t length, size_t offset) + { + return read(&destination, sizeof(destination), length, offset); + } private: FileStatus reset() const; -- cgit v1.2.3