diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2024-10-15 20:56:26 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2024-10-15 20:56:26 -0500 |
commit | f3ac764684c64fbdd2094853a80b23e570cd5d9c (patch) | |
tree | 3b7f64480a1247455d28e23b6bb5ff63303c9170 /include/fud_c_file.hpp | |
parent | 71976e927cca43b970cb659c03fd6908c352ea3d (diff) |
Conver to using static constructors for string, sqlite, files.
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}; }; |