summaryrefslogtreecommitdiff
path: root/include/fud_c_file.hpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-09-23 22:46:38 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-09-23 22:46:38 -0500
commit404de2dfde39ca181db531427638f249c6e334e7 (patch)
tree9d1bd13e6c98ff441fdbb673dc91c8b8b67277c1 /include/fud_c_file.hpp
parentd6497e9ad3924711990b4452993f20c2603fd955 (diff)
Expand CBinaryFile interface.
Diffstat (limited to 'include/fud_c_file.hpp')
-rw-r--r--include/fud_c_file.hpp48
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;