summaryrefslogtreecommitdiff
path: root/src/common/file_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/file_util.h')
-rw-r--r--src/common/file_util.h26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/common/file_util.h b/src/common/file_util.h
index 880b8a1e3..b54a9fb72 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -176,7 +176,6 @@ class IOFile : public NonCopyable
176{ 176{
177public: 177public:
178 IOFile(); 178 IOFile();
179 explicit IOFile(std::FILE* file);
180 IOFile(const std::string& filename, const char openmode[]); 179 IOFile(const std::string& filename, const char openmode[]);
181 180
182 ~IOFile(); 181 ~IOFile();
@@ -192,6 +191,9 @@ public:
192 template <typename T> 191 template <typename T>
193 size_t ReadArray(T* data, size_t length) 192 size_t ReadArray(T* data, size_t length)
194 { 193 {
194 static_assert(std::is_standard_layout<T>(), "Given array does not consist of standard layout objects");
195 static_assert(std::is_trivially_copyable<T>(), "Given array does not consist of trivially copyable objects");
196
195 if (!IsOpen()) { 197 if (!IsOpen()) {
196 m_good = false; 198 m_good = false;
197 return -1; 199 return -1;
@@ -207,9 +209,8 @@ public:
207 template <typename T> 209 template <typename T>
208 size_t WriteArray(const T* data, size_t length) 210 size_t WriteArray(const T* data, size_t length)
209 { 211 {
210 static_assert(std::is_standard_layout<T>::value, "Given array does not consist of standard layout objects"); 212 static_assert(std::is_standard_layout<T>(), "Given array does not consist of standard layout objects");
211 // TODO: gcc 4.8 does not support is_trivially_copyable, but we really should check for it here. 213 static_assert(std::is_trivially_copyable<T>(), "Given array does not consist of trivially copyable objects");
212 //static_assert(std::is_trivially_copyable<T>::value, "Given array does not consist of trivially copyable objects");
213 214
214 if (!IsOpen()) { 215 if (!IsOpen()) {
215 m_good = false; 216 m_good = false;
@@ -243,25 +244,20 @@ public:
243 244
244 // m_good is set to false when a read, write or other function fails 245 // m_good is set to false when a read, write or other function fails
245 bool IsGood() const { return m_good; } 246 bool IsGood() const { return m_good; }
246 operator void*() { return m_good ? m_file : nullptr; } 247 explicit operator bool() const { return IsGood(); }
247
248 std::FILE* ReleaseHandle();
249
250 std::FILE* GetHandle() { return m_file; }
251
252 void SetHandle(std::FILE* file);
253 248
254 bool Seek(s64 off, int origin); 249 bool Seek(s64 off, int origin);
255 u64 Tell(); 250 u64 Tell() const;
256 u64 GetSize(); 251 u64 GetSize() const;
257 bool Resize(u64 size); 252 bool Resize(u64 size);
258 bool Flush(); 253 bool Flush();
259 254
260 // clear error state 255 // clear error state
261 void Clear() { m_good = true; std::clearerr(m_file); } 256 void Clear() { m_good = true; std::clearerr(m_file); }
262 257
263 std::FILE* m_file; 258private:
264 bool m_good; 259 std::FILE* m_file = nullptr;
260 bool m_good = true;
265}; 261};
266 262
267} // namespace 263} // namespace