From 404de2dfde39ca181db531427638f249c6e334e7 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Mon, 23 Sep 2024 22:46:38 -0500 Subject: Expand CBinaryFile interface. --- include/fud_c_file.hpp | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/fud_c_file.hpp b/include/fud_c_file.hpp index 281d216..b48e8a0 100644 --- a/include/fud_c_file.hpp +++ b/include/fud_c_file.hpp @@ -26,6 +26,7 @@ namespace fud { +/** \brief Access Modes for */ enum class CFileMode : uint8_t { ReadOnly, @@ -76,12 +77,35 @@ constexpr const char* CTextFileModeFromFlags(CFileMode mode) } } -enum class FileResult +enum class FileStatus { Success, + InvalidName, + InvalidArgument, + InvalidState, + NullPointer, Error, }; +static inline const char* FileStatusToString(FileStatus status) { + switch (status) { + case FileStatus::Success: + return "Success"; + case FileStatus::InvalidName: + return "InvalidName"; + case FileStatus::InvalidArgument: + return "InvalidArgument"; + case FileStatus::InvalidState: + return "InvalidState"; + case FileStatus::NullPointer: + return "NullPointer"; + case FileStatus::Error: + return "Error"; + default: + return "Unknown"; + } +} + class CBinaryFile { public: CBinaryFile(const String& filename, CFileMode mode); @@ -89,13 +113,29 @@ class CBinaryFile { CBinaryFile(const CBinaryFile& rhs) = delete; ~CBinaryFile(); CBinaryFile& operator=(const CBinaryFile& rhs) = delete; - FileResult open(); + FileStatus open(); void close(); const FILE* file() const; - FILE* file(); + [[nodiscard]] FILE* file(); + + [[nodiscard]] bool isOpen() const; + + [[nodiscard]] Result size() const; + + template + [[nodiscard]] FileStatus read(T& destination, size_t length); + + template + [[nodiscard]] FileStatus read(T& destination, size_t length, size_t offset); + + [[nodiscard]] FileStatus read(void* destination, size_t destinationSize, size_t length); + + [[nodiscard]] FileStatus read(void* destination, size_t destinationSize, size_t length, size_t offset); private: - String m_filename; + FileStatus reset() const; + + const String m_filename; String m_extraFlags{}; String m_mode; CFileMode m_modeFlags; -- cgit v1.2.3