From 3ee4432fe391282ac2a5ab5492ff915b0c2adf28 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 13 Apr 2016 19:10:54 -0400 Subject: file_util: Make IOFile data members private --- src/common/file_util.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/common/file_util.h') diff --git a/src/common/file_util.h b/src/common/file_util.h index 880b8a1e3..80e618aca 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -260,6 +260,7 @@ public: // clear error state void Clear() { m_good = true; std::clearerr(m_file); } +private: std::FILE* m_file; bool m_good; }; -- cgit v1.2.3 From bf9945b81bf7d41c197ac8b190cab9e1c7176733 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 13 Apr 2016 19:20:23 -0400 Subject: file_util: Check for is_trivially_copyable Also applies the template checks to ReadArray as well. --- src/common/file_util.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/common/file_util.h') diff --git a/src/common/file_util.h b/src/common/file_util.h index 80e618aca..dd151575f 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -192,6 +192,9 @@ public: template size_t ReadArray(T* data, size_t length) { + static_assert(std::is_standard_layout(), "Given array does not consist of standard layout objects"); + static_assert(std::is_trivially_copyable(), "Given array does not consist of trivially copyable objects"); + if (!IsOpen()) { m_good = false; return -1; @@ -207,9 +210,8 @@ public: template size_t WriteArray(const T* data, size_t length) { - static_assert(std::is_standard_layout::value, "Given array does not consist of standard layout objects"); - // TODO: gcc 4.8 does not support is_trivially_copyable, but we really should check for it here. - //static_assert(std::is_trivially_copyable::value, "Given array does not consist of trivially copyable objects"); + static_assert(std::is_standard_layout(), "Given array does not consist of standard layout objects"); + static_assert(std::is_trivially_copyable(), "Given array does not consist of trivially copyable objects"); if (!IsOpen()) { m_good = false; -- cgit v1.2.3 From a4120ca66cc6c0f3a8056c6ea247c15f63c7feff Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 13 Apr 2016 19:29:16 -0400 Subject: file_util: Don't expose IOFile internals through the API --- src/common/file_util.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'src/common/file_util.h') diff --git a/src/common/file_util.h b/src/common/file_util.h index dd151575f..8f72fb4e2 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -176,7 +176,6 @@ class IOFile : public NonCopyable { public: IOFile(); - explicit IOFile(std::FILE* file); IOFile(const std::string& filename, const char openmode[]); ~IOFile(); @@ -245,13 +244,7 @@ public: // m_good is set to false when a read, write or other function fails bool IsGood() const { return m_good; } - operator void*() { return m_good ? m_file : nullptr; } - - std::FILE* ReleaseHandle(); - - std::FILE* GetHandle() { return m_file; } - - void SetHandle(std::FILE* file); + explicit operator bool() const { return IsGood(); } bool Seek(s64 off, int origin); u64 Tell(); -- cgit v1.2.3 From 655623ebb2dd6f3f1451e5b8b92dc755868347c8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 13 Apr 2016 19:38:01 -0400 Subject: file_util: const qualify IOFile's Tell and GetSize functions --- src/common/file_util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/common/file_util.h') diff --git a/src/common/file_util.h b/src/common/file_util.h index 8f72fb4e2..d520130ce 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -247,8 +247,8 @@ public: explicit operator bool() const { return IsGood(); } bool Seek(s64 off, int origin); - u64 Tell(); - u64 GetSize(); + u64 Tell() const; + u64 GetSize() const; bool Resize(u64 size); bool Flush(); -- cgit v1.2.3 From 5f51622e9de0483519f47c749888fe7d5b120c79 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 13 Apr 2016 19:48:03 -0400 Subject: file_util: In-class initialize data members --- src/common/file_util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/common/file_util.h') diff --git a/src/common/file_util.h b/src/common/file_util.h index d520130ce..b54a9fb72 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -256,8 +256,8 @@ public: void Clear() { m_good = true; std::clearerr(m_file); } private: - std::FILE* m_file; - bool m_good; + std::FILE* m_file = nullptr; + bool m_good = true; }; } // namespace -- cgit v1.2.3