From 6c7fd1db481ff10a16ecab958c6542784fa60b9c Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Wed, 30 Oct 2024 09:51:54 -0500 Subject: Use std::byte* instead of void* for allocators. --- include/fud_c_file.hpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'include/fud_c_file.hpp') diff --git a/include/fud_c_file.hpp b/include/fud_c_file.hpp index bf148c2..e0be680 100644 --- a/include/fud_c_file.hpp +++ b/include/fud_c_file.hpp @@ -18,11 +18,11 @@ #ifndef FUD_C_FILE_HPP #define FUD_C_FILE_HPP +#include "fud_drain.hpp" #include "fud_permissions.hpp" #include "fud_result.hpp" #include "fud_status.hpp" #include "fud_string.hpp" -#include "fud_file.hpp" #include #include @@ -184,16 +184,16 @@ class CFile { return RetType::okay(fileSize); } - [[nodiscard]] ReadResult read(void* destination, size_t destinationSize, size_t length) + [[nodiscard]] DrainResult read(void* destination, size_t destinationSize, size_t length) { auto& self = static_cast(*this); return self.read(destination, destinationSize, length, 0); } - [[nodiscard]] ReadResult read(void* destination, size_t destinationSize, size_t length, size_t offset) + [[nodiscard]] DrainResult read(void* destination, size_t destinationSize, size_t length, size_t offset) { auto& self = static_cast(*this); - ReadResult result{}; + DrainResult result{}; if (length == 0) { return result; } @@ -227,9 +227,9 @@ class CFile { } auto* destBytes = static_cast(destination); - result.bytesRead = fread(destBytes, 1, length, self.m_file); + result.bytesDrained = fread(destBytes, 1, length, self.m_file); static_cast(self.reset()); - if (result.bytesRead != length) { + if (result.bytesDrained != length) { result.status = FudStatus::Partial; } else { result.status = FudStatus::Success; @@ -239,7 +239,7 @@ class CFile { } template - [[nodiscard]] ReadResult read(T& destination, size_t length) + [[nodiscard]] DrainResult read(T& destination, size_t length) { static_assert(not std::is_pointer_v); auto& self = static_cast(*this); @@ -247,39 +247,39 @@ class CFile { } template - [[nodiscard]] ReadResult read(T& destination, size_t length, size_t offset) + [[nodiscard]] DrainResult read(T& destination, size_t length, size_t offset) { static_assert(not std::is_pointer_v); auto& self = static_cast(*this); return self.read(&destination, sizeof(destination), length, offset); } - [[nodiscard]] WriteResult write(const void* source, size_t sourceSize) + [[nodiscard]] DrainResult write(const void* source, size_t sourceSize) { auto& self = static_cast(*this); auto offsetResult = self.size(); if (offsetResult.isError()) { - return WriteResult{0, offsetResult.getError()}; + return DrainResult{0, offsetResult.getError()}; } return self.write(source, sourceSize, sourceSize, offsetResult.getOkay()); } - [[nodiscard]] WriteResult write(const void* source, size_t sourceSize, size_t length) + [[nodiscard]] DrainResult write(const void* source, size_t sourceSize, size_t length) { auto& self = static_cast(*this); auto offsetResult = self.size(); if (offsetResult.isError()) { - return WriteResult{0, offsetResult.getError()}; + return DrainResult{0, offsetResult.getError()}; } return self.write(source, sourceSize, length, offsetResult.getOkay()); } - [[nodiscard]] WriteResult write(const void* source, size_t sourceSize, size_t length, size_t offset) + [[nodiscard]] DrainResult write(const void* source, size_t sourceSize, size_t length, size_t offset) { auto& self = static_cast(*this); - WriteResult result{}; + DrainResult result{}; if (length == 0) { return result; } @@ -315,9 +315,9 @@ class CFile { } const auto* sourceBytes = static_cast(source); - result.bytesWritten = fwrite(sourceBytes, 1, length, self.m_file); + result.bytesDrained = fwrite(sourceBytes, 1, length, self.m_file); static_cast(self.reset()); - if (result.bytesWritten != length) { + if (result.bytesDrained != length) { result.status = FudStatus::Partial; } else { result.status = FudStatus::Success; @@ -327,7 +327,7 @@ class CFile { } template - [[nodiscard]] WriteResult write(const T& source) + [[nodiscard]] DrainResult write(const T& source) { static_assert(not std::is_pointer_v); auto& self = static_cast(*this); @@ -335,19 +335,19 @@ class CFile { } template - [[nodiscard]] WriteResult write(const T& source, size_t sourceSize, size_t length) + [[nodiscard]] DrainResult write(const T& source, size_t sourceSize, size_t length) { static_assert(not std::is_pointer_v); auto& self = static_cast(*this); auto offsetResult = self.size(); if (offsetResult.isError()) { - return WriteResult{0, offsetResult.getError()}; + return DrainResult{0, offsetResult.getError()}; } return self.write(source, sourceSize, length, offsetResult.getOkay()); } template - [[nodiscard]] WriteResult write(const T& source, size_t sourceSize, size_t length, size_t offset) + [[nodiscard]] DrainResult write(const T& source, size_t sourceSize, size_t length, size_t offset) { static_assert(not std::is_pointer_v); auto& self = static_cast(*this); -- cgit v1.2.3