diff options
Diffstat (limited to 'include/fud_c_file.hpp')
-rw-r--r-- | include/fud_c_file.hpp | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/include/fud_c_file.hpp b/include/fud_c_file.hpp index c81a340..4905643 100644 --- a/include/fud_c_file.hpp +++ b/include/fud_c_file.hpp @@ -18,10 +18,10 @@ #ifndef FUD_C_FILE_HPP #define FUD_C_FILE_HPP +#include "fud_permissions.hpp" #include "fud_result.hpp" #include "fud_status.hpp" #include "fud_string.hpp" -#include "fud_permissions.hpp" #include <cstdint> #include <cstdio> @@ -155,7 +155,8 @@ class CFile { return self.m_file; } - FudStatus setPermissions(Permissions permissions) { + FudStatus setPermissions(Permissions permissions) + { auto& self = static_cast<Derived&>(*this); if (!self.isOpen()) { return FudStatus::OperationInvalid; @@ -383,14 +384,20 @@ class CFile { } // namespace detail +class CBinaryFile; +using CBinaryFileResult = Result<CBinaryFile, FudStatus>; + class CBinaryFile : public detail::CFile<CBinaryFile> { friend class CFile; public: - CBinaryFile(const String& filename, CFileMode mode); + static CBinaryFileResult make(const String& filename, CFileMode mode); + static CBinaryFileResult make(const String& filename, CFileMode mode, const char* extraFlags); - CBinaryFile(const String& filename, CFileMode mode, const String& extraFlags); + private: + CBinaryFile() = default; + public: CBinaryFile(const CBinaryFile& rhs) = delete; CBinaryFile(CBinaryFile&& rhs) noexcept; @@ -402,21 +409,26 @@ class CBinaryFile : public detail::CFile<CBinaryFile> { CBinaryFile& operator=(CBinaryFile&& rhs) noexcept; private: - String m_filename; - String m_extraFlags{}; - String m_mode; - CFileMode m_modeFlags; + String m_filename{}; + String m_mode{}; + CFileMode m_modeFlags{}; FILE* m_file{nullptr}; }; +class CTextFile; +using CTextFileResult = Result<CTextFile, FudStatus>; + class CTextFile : public detail::CFile<CTextFile> { friend class CFile; public: - CTextFile(const String& filename, CFileMode mode); + static CTextFileResult make(const String& filename, CFileMode mode); + static CTextFileResult make(const String& filename, CFileMode mode, const char* extraFlags); - CTextFile(const String& filename, CFileMode mode, const String& extraFlags); + private: + CTextFile() = default; + public: CTextFile(const CTextFile& rhs) = delete; CTextFile(CTextFile&& rhs) noexcept; @@ -428,10 +440,9 @@ class CTextFile : public detail::CFile<CTextFile> { CTextFile& operator=(CTextFile&& rhs) noexcept; private: - String m_filename; - String m_extraFlags{}; - String m_mode; - CFileMode m_modeFlags; + String m_filename{}; + String m_mode{}; + CFileMode m_modeFlags{}; FILE* m_file{nullptr}; }; |