diff options
| author | 2015-04-18 02:31:00 +0200 | |
|---|---|---|
| committer | 2015-07-13 22:27:20 +0200 | |
| commit | 279e19732c5f955de31f59f0690992c816aa8337 (patch) | |
| tree | 7ea233941e64cf3cc83ac10f4efd9f91b5a00c96 /src | |
| parent | HW: Fix a stupid issue which led to unknown register reads/writes. (diff) | |
| download | yuzu-279e19732c5f955de31f59f0690992c816aa8337.tar.gz yuzu-279e19732c5f955de31f59f0690992c816aa8337.tar.xz yuzu-279e19732c5f955de31f59f0690992c816aa8337.zip | |
FileUtil: Add a WriteObject method for writing a single, POD-type object.
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/file_util.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/common/file_util.h b/src/common/file_util.h index 8fe772aee..9637d1b85 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h | |||
| @@ -181,6 +181,10 @@ public: | |||
| 181 | template <typename T> | 181 | template <typename T> |
| 182 | size_t WriteArray(const T* data, size_t length) | 182 | size_t WriteArray(const T* data, size_t length) |
| 183 | { | 183 | { |
| 184 | static_assert(std::is_standard_layout<T>::value, "Given array does not consist of standard layout objects"); | ||
| 185 | // TODO: gcc 4.8 does not support is_trivially_copyable, but we really should check for it here. | ||
| 186 | //static_assert(std::is_trivially_copyable<T>::value, "Given array does not consist of trivially copyable objects"); | ||
| 187 | |||
| 184 | if (!IsOpen()) { | 188 | if (!IsOpen()) { |
| 185 | m_good = false; | 189 | m_good = false; |
| 186 | return -1; | 190 | return -1; |
| @@ -203,6 +207,12 @@ public: | |||
| 203 | return WriteArray(reinterpret_cast<const char*>(data), length); | 207 | return WriteArray(reinterpret_cast<const char*>(data), length); |
| 204 | } | 208 | } |
| 205 | 209 | ||
| 210 | template<typename T> | ||
| 211 | size_t WriteObject(const T& object) { | ||
| 212 | static_assert(!std::is_pointer<T>::value, "Given object is a pointer"); | ||
| 213 | return WriteArray(&object, 1); | ||
| 214 | } | ||
| 215 | |||
| 206 | bool IsOpen() { return nullptr != m_file; } | 216 | bool IsOpen() { return nullptr != m_file; } |
| 207 | 217 | ||
| 208 | // m_good is set to false when a read, write or other function fails | 218 | // m_good is set to false when a read, write or other function fails |