diff options
Diffstat (limited to 'src/common/file_util.h')
| -rw-r--r-- | src/common/file_util.h | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/common/file_util.h b/src/common/file_util.h index a85121aa6..b54a9fb72 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h | |||
| @@ -14,6 +14,10 @@ | |||
| 14 | 14 | ||
| 15 | #include "common/common_types.h" | 15 | #include "common/common_types.h" |
| 16 | 16 | ||
| 17 | #ifdef _MSC_VER | ||
| 18 | #include "common/string_util.h" | ||
| 19 | #endif | ||
| 20 | |||
| 17 | // User directory indices for GetUserPath | 21 | // User directory indices for GetUserPath |
| 18 | enum { | 22 | enum { |
| 19 | D_USER_IDX, | 23 | D_USER_IDX, |
| @@ -172,7 +176,6 @@ class IOFile : public NonCopyable | |||
| 172 | { | 176 | { |
| 173 | public: | 177 | public: |
| 174 | IOFile(); | 178 | IOFile(); |
| 175 | IOFile(std::FILE* file); | ||
| 176 | IOFile(const std::string& filename, const char openmode[]); | 179 | IOFile(const std::string& filename, const char openmode[]); |
| 177 | 180 | ||
| 178 | ~IOFile(); | 181 | ~IOFile(); |
| @@ -188,6 +191,9 @@ public: | |||
| 188 | template <typename T> | 191 | template <typename T> |
| 189 | size_t ReadArray(T* data, size_t length) | 192 | size_t ReadArray(T* data, size_t length) |
| 190 | { | 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 | |||
| 191 | if (!IsOpen()) { | 197 | if (!IsOpen()) { |
| 192 | m_good = false; | 198 | m_good = false; |
| 193 | return -1; | 199 | return -1; |
| @@ -203,9 +209,8 @@ public: | |||
| 203 | template <typename T> | 209 | template <typename T> |
| 204 | size_t WriteArray(const T* data, size_t length) | 210 | size_t WriteArray(const T* data, size_t length) |
| 205 | { | 211 | { |
| 206 | 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"); |
| 207 | // 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"); |
| 208 | //static_assert(std::is_trivially_copyable<T>::value, "Given array does not consist of trivially copyable objects"); | ||
| 209 | 214 | ||
| 210 | if (!IsOpen()) { | 215 | if (!IsOpen()) { |
| 211 | m_good = false; | 216 | m_good = false; |
| @@ -235,32 +240,24 @@ public: | |||
| 235 | return WriteArray(&object, 1); | 240 | return WriteArray(&object, 1); |
| 236 | } | 241 | } |
| 237 | 242 | ||
| 238 | bool IsOpen() { return nullptr != m_file; } | 243 | bool IsOpen() const { return nullptr != m_file; } |
| 239 | 244 | ||
| 240 | // 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 |
| 241 | bool IsGood() { return m_good; } | 246 | bool IsGood() const { return m_good; } |
| 242 | operator void*() { return m_good ? m_file : nullptr; } | 247 | explicit operator bool() const { return IsGood(); } |
| 243 | |||
| 244 | std::FILE* ReleaseHandle(); | ||
| 245 | |||
| 246 | std::FILE* GetHandle() { return m_file; } | ||
| 247 | |||
| 248 | void SetHandle(std::FILE* file); | ||
| 249 | 248 | ||
| 250 | bool Seek(s64 off, int origin); | 249 | bool Seek(s64 off, int origin); |
| 251 | u64 Tell(); | 250 | u64 Tell() const; |
| 252 | u64 GetSize(); | 251 | u64 GetSize() const; |
| 253 | bool Resize(u64 size); | 252 | bool Resize(u64 size); |
| 254 | bool Flush(); | 253 | bool Flush(); |
| 255 | 254 | ||
| 256 | // clear error state | 255 | // clear error state |
| 257 | void Clear() { m_good = true; std::clearerr(m_file); } | 256 | void Clear() { m_good = true; std::clearerr(m_file); } |
| 258 | 257 | ||
| 259 | std::FILE* m_file; | ||
| 260 | bool m_good; | ||
| 261 | private: | 258 | private: |
| 262 | IOFile(IOFile&); | 259 | std::FILE* m_file = nullptr; |
| 263 | IOFile& operator=(IOFile& other); | 260 | bool m_good = true; |
| 264 | }; | 261 | }; |
| 265 | 262 | ||
| 266 | } // namespace | 263 | } // namespace |