diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/fud_c_file.hpp | 48 |
1 files changed, 44 insertions, 4 deletions
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_t, FileStatus> size() const; + + template <typename T> + [[nodiscard]] FileStatus read(T& destination, size_t length); + + template <typename T> + [[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; |