diff options
| author | Leo Lam <leolino.lam@gmail.com> | 2017-06-15 23:28:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-15 23:28:36 +0200 |
| commit | 8f460a1cda1a4d4208c4da9e01bf775f5f704498 (patch) | |
| tree | 3ceea68574665cde97e5d2276bd9c320ceb579ad /Source/Core/Common/FileUtil.h | |
| parent | 9bc1b652fed28caac9042c42fce33f89363a88d3 (diff) | |
| parent | cf94ce63051458a2d8ac8b340a1020b863f1a6dd (diff) | |
Merge pull request #5611 from JosJuice/reorganize-file-namespace
Reorganize File namespace
Diffstat (limited to 'Source/Core/Common/FileUtil.h')
| -rw-r--r-- | Source/Core/Common/FileUtil.h | 82 |
1 files changed, 2 insertions, 80 deletions
diff --git a/Source/Core/Common/FileUtil.h b/Source/Core/Common/FileUtil.h index d0aca675dc..5eec5382ce 100644 --- a/Source/Core/Common/FileUtil.h +++ b/Source/Core/Common/FileUtil.h @@ -5,7 +5,6 @@ #pragma once #include <cstddef> -#include <cstdio> #include <fstream> #include <string> #include <vector> @@ -163,85 +162,6 @@ std::string& GetExeDirectory(); bool WriteStringToFile(const std::string& str, const std::string& filename); bool ReadFileToString(const std::string& filename, std::string& str); -// simple wrapper for cstdlib file functions to -// hopefully will make error checking easier -// and make forgetting an fclose() harder -class IOFile : public NonCopyable -{ -public: - IOFile(); - IOFile(std::FILE* file); - IOFile(const std::string& filename, const char openmode[]); - - ~IOFile(); - - IOFile(IOFile&& other) noexcept; - IOFile& operator=(IOFile&& other) noexcept; - - void Swap(IOFile& other) noexcept; - - bool Open(const std::string& filename, const char openmode[]); - bool Close(); - - template <typename T> - bool ReadArray(T* data, size_t length, size_t* pReadBytes = nullptr) - { - size_t read_bytes = 0; - if (!IsOpen() || length != (read_bytes = std::fread(data, sizeof(T), length, m_file))) - m_good = false; - - if (pReadBytes) - *pReadBytes = read_bytes; - - return m_good; - } - - template <typename T> - bool WriteArray(const T* data, size_t length) - { - if (!IsOpen() || length != std::fwrite(data, sizeof(T), length, m_file)) - m_good = false; - - return m_good; - } - - bool ReadBytes(void* data, size_t length) - { - return ReadArray(reinterpret_cast<char*>(data), length); - } - - bool WriteBytes(const void* data, size_t length) - { - return WriteArray(reinterpret_cast<const char*>(data), length); - } - - bool IsOpen() const { return nullptr != m_file; } - // m_good is set to false when a read, write or other function fails - bool IsGood() const { return m_good; } - explicit operator bool() const { return IsGood() && IsOpen(); } - std::FILE* GetHandle() { return m_file; } - void SetHandle(std::FILE* file); - - bool Seek(s64 off, int origin); - u64 Tell() const; - u64 GetSize(); - bool Resize(u64 size); - bool Flush(); - - // clear error state - void Clear() - { - m_good = true; - std::clearerr(m_file); - } - -private: - std::FILE* m_file; - bool m_good; -}; - -} // namespace - // To deal with Windows being dumb at unicode: template <typename T> void OpenFStream(T& fstream, const std::string& filename, std::ios_base::openmode openmode) @@ -252,3 +172,5 @@ void OpenFStream(T& fstream, const std::string& filename, std::ios_base::openmod fstream.open(filename.c_str(), openmode); #endif } + +} // namespace |
