From 4c7bbd96e435a7516b05d3e8c791ab41505e2e0f Mon Sep 17 00:00:00 2001 From: comex Date: Sun, 25 Aug 2013 20:06:58 -0400 Subject: [PATCH] Improve ChunkFile.h: - Add support for std::set and std:pair. - Switch from std::is_pod to std::is_trivially_copyable, to allow for types that have constructors but trivial copy constructors. Easy, except there are three different nonstandard versions of it required on different platforms, in addition to the standard one. --- Source/Core/Common/Src/ChunkFile.h | 58 +++++++++++++++++-- .../Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h | 7 --- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/Source/Core/Common/Src/ChunkFile.h b/Source/Core/Common/Src/ChunkFile.h index 6fed73a7ed..ae5d9522e7 100644 --- a/Source/Core/Common/Src/ChunkFile.h +++ b/Source/Core/Common/Src/ChunkFile.h @@ -16,6 +16,7 @@ // - Serialization code for anything complex has to be manually written. #include +#include #include #include #include @@ -25,6 +26,21 @@ #include "Common.h" #include "FileUtil.h" +// ewww +#if _LIBCPP_VERSION +#define IsTriviallyCopyable(T) std::is_trivially_copyable::value +#elif __GNUC__ +#define IsTriviallyCopyable(T) std::has_trivial_copy_constructor::value +#elif _MSC_VER >= 1800 +// work around bug +#define IsTriviallyCopyable(T) (std::is_trivially_copyable::value || std::is_pod::value) +#elif defined(_MSC_VER) +#define IsTriviallyCopyable(T) std::has_trivial_copy::value +#else +#error No version of is_trivially_copyable +#endif + + template struct LinkedListItem : public T { @@ -83,6 +99,34 @@ public: } } + template + void Do(std::set& x) + { + u32 count = (u32)x.size(); + Do(count); + + switch (mode) + { + case MODE_READ: + for (x.clear(); count != 0; --count) + { + V value; + Do(value); + x.insert(value); + } + break; + + case MODE_WRITE: + case MODE_MEASURE: + case MODE_VERIFY: + for (auto itr = x.begin(); itr != x.end(); ++itr) + { + Do(*itr); + } + break; + } + } + template void DoContainer(T& x) { @@ -118,6 +162,13 @@ public: DoContainer(x); } + template + void Do(std::pair& x) + { + Do(x.first); + Do(x.second); + } + template void DoArray(T* x, u32 count) { @@ -128,12 +179,11 @@ public: template void Do(T& x) { - // Ideally this would be std::is_trivially_copyable, but not enough support yet - static_assert(std::is_pod::value, "Only sane for POD types"); - + static_assert(IsTriviallyCopyable(T), "Only sane for trivially copyable types"); + DoVoid((void*)&x, sizeof(x)); } - + template void DoPOD(T& x) { diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h index 253f2d08de..f6abbc67fe 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h @@ -39,13 +39,6 @@ struct SQueuedEvent } }; -// Hacks for ChunkFile to accept SQueuedEvent as POD -namespace std -{ -template <> -struct is_pod : std::true_type {}; -} - // Important to remember that this class is for /dev/usb/oh1/57e/305 ONLY // /dev/usb/oh1 -> internal usb bus // 57e/305 -> VendorID/ProductID of device on usb bus