From d6ab3e6e67f5abf74fbff43e892765566cacd129 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Tue, 8 Sep 2020 19:55:14 +0200 Subject: [PATCH] Move File method definitions outside the class for tidiness --- src/File.hpp | 114 ++++++++++++++++++++++++++++----------------------- 1 file changed, 63 insertions(+), 51 deletions(-) diff --git a/src/File.hpp b/src/File.hpp index 0d51f6024..d021dd08f 100644 --- a/src/File.hpp +++ b/src/File.hpp @@ -28,65 +28,77 @@ class File : public NonCopyable { public: File() = default; + File(const std::string& path, const char* mode); + File(File&& other); + ~File(); - File(const std::string& path, const char* mode) - { - open(path, mode); - } + File& operator=(File&& other); - File(File&& other) : m_file(other.m_file) - { - other.m_file = nullptr; - } + void open(const std::string& path, const char* mode); + void close(); - File& - operator=(File&& other) - { - m_file = other.m_file; - other.m_file = nullptr; - return *this; - } + operator bool() const; + FILE* operator*() const; + FILE* get(); - void - open(const std::string& path, const char* mode) - { - close(); - m_file = fopen(path.c_str(), mode); - } +private: + FILE* m_file = nullptr; +}; - void - close() - { - if (m_file) { - fclose(m_file); - m_file = nullptr; - } - } +inline File::File(const std::string& path, const char* mode) +{ + open(path, mode); +} - ~File() - { - close(); - } +inline File::File(File&& other) : m_file(other.m_file) +{ + other.m_file = nullptr; +} - operator bool() const - { - return m_file; - } +inline File::~File() +{ + close(); +} - // clang-format off - FILE* - operator*() const - // clang-format on - { - return m_file; - } +inline File& +File::operator=(File&& other) +{ + m_file = other.m_file; + other.m_file = nullptr; + return *this; +} + +inline void +File::open(const std::string& path, const char* mode) +{ + close(); + m_file = fopen(path.c_str(), mode); +} - FILE* - get() - { - return m_file; +inline void +File::close() +{ + if (m_file) { + fclose(m_file); + m_file = nullptr; } +} -private: - FILE* m_file = nullptr; -}; +inline File::operator bool() const +{ + return m_file; +} + +// clang-format off +inline FILE* +File::operator*() const +// clang-format on +{ + return m_file; +} + +inline FILE* +File::get() +{ + return m_file; +} -- 2.47.3