summaryrefslogtreecommitdiff
path: root/Source/Core/Common/ChunkFile.h
diff options
context:
space:
mode:
authorTillmann Karras <tilkax@gmail.com>2019-02-01 02:02:22 +0000
committerTillmann Karras <tilkax@gmail.com>2019-02-01 05:13:16 +0000
commit04a92482bf7a3374fcd0451de15add2acba8dea0 (patch)
tree0733d5aa898a1fb6367e8b505152432b85933fd2 /Source/Core/Common/ChunkFile.h
parenta129d60a570c73b614c02a3145bef42f2d329b64 (diff)
ChunkFile: treat vectors/strings as sized arrays
Diffstat (limited to 'Source/Core/Common/ChunkFile.h')
-rw-r--r--Source/Core/Common/ChunkFile.h26
1 files changed, 21 insertions, 5 deletions
diff --git a/Source/Core/Common/ChunkFile.h b/Source/Core/Common/ChunkFile.h
index bb2764ce54..b4383d2570 100644
--- a/Source/Core/Common/ChunkFile.h
+++ b/Source/Core/Common/ChunkFile.h
@@ -116,7 +116,7 @@ public:
template <typename T>
void Do(std::vector<T>& x)
{
- DoContainer(x);
+ DoContiguousContainer(x);
}
template <typename T>
@@ -134,7 +134,7 @@ public:
template <typename T>
void Do(std::basic_string<T>& x)
{
- DoContainer(x);
+ DoContiguousContainer(x);
}
template <typename T, typename U>
@@ -147,16 +147,22 @@ public:
template <typename T, std::size_t N>
void DoArray(std::array<T, N>& x)
{
- DoArray(x.data(), (u32)x.size());
+ DoArray(x.data(), static_cast<u32>(x.size()));
}
- template <typename T>
+ template <typename T, typename std::enable_if_t<IsTriviallyCopyable<T>, int> = 0>
void DoArray(T* x, u32 count)
{
- static_assert(IsTriviallyCopyable<T>, "Only sane for trivially copyable types");
DoVoid(x, count * sizeof(T));
}
+ template <typename T, typename std::enable_if_t<!IsTriviallyCopyable<T>, int> = 0>
+ void DoArray(T* x, u32 count)
+ {
+ for (u32 i = 0; i < count; ++i)
+ Do(x[i]);
+ }
+
template <typename T, std::size_t N>
void DoArray(T (&arr)[N])
{
@@ -250,6 +256,16 @@ public:
private:
template <typename T>
+ void DoContiguousContainer(T& container)
+ {
+ u32 size = static_cast<u32>(container.size());
+ Do(size);
+ container.resize(size);
+
+ DoArray(&container[0], size);
+ }
+
+ template <typename T>
void DoContainer(T& x)
{
DoEachElement(x, [](PointerWrap& p, typename T::value_type& elem) { p.Do(elem); });