From f650eccf9ea98eecbd528cca0be0b54d90b10099 Mon Sep 17 00:00:00 2001 From: Phil Miller Date: Mon, 23 Nov 2020 19:15:28 -0500 Subject: [PATCH] #156: Get serializeArray working for non-serializable types --- src/checkpoint/dispatch/dispatch.h | 4 ++-- src/checkpoint/dispatch/dispatch.impl.h | 23 ++++++++++++++------- src/checkpoint/traits/serializable_traits.h | 9 ++------ tests/unit/test_footprinter.cc | 6 ------ 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/checkpoint/dispatch/dispatch.h b/src/checkpoint/dispatch/dispatch.h index 297e0198..d40b3178 100644 --- a/src/checkpoint/dispatch/dispatch.h +++ b/src/checkpoint/dispatch/dispatch.h @@ -194,8 +194,8 @@ buffer::ImplReturnType packBuffer( T& target, SerialSizeType size, BufferObtainFnType fn ); -template -inline void serializeArray(Serializer& s, T* array, SerialSizeType const len); + //template + //inline void serializeArray(Serializer& s, T* array, SerialSizeType const len); template buffer::ImplReturnType serializeType(T& target, BufferObtainFnType fn = nullptr); diff --git a/src/checkpoint/dispatch/dispatch.impl.h b/src/checkpoint/dispatch/dispatch.impl.h index 3ca73889..fbef0a97 100644 --- a/src/checkpoint/dispatch/dispatch.impl.h +++ b/src/checkpoint/dispatch/dispatch.impl.h @@ -120,8 +120,11 @@ T* Standard::construct(SerialByteType* mem) { return Traverse::reconstruct(mem); } -template -inline void serializeArray(Serializer& s, T* array, SerialSizeType const len) { +template < + typename Serializer, + typename T +> +inline std::enable_if_t< SerializableTraits::is_traversable, void > serializeArray(Serializer& s, T* array, SerialSizeType const len) { if (len > 0) { Traverse::with(*array, s, len); } @@ -129,13 +132,17 @@ inline void serializeArray(Serializer& s, T* array, SerialSizeType const len) { template < typename Serializer, - typename T, - typename = std::enable_if_t< - not SerializableTraits::is_footprintable_v - > + typename T > -inline void serializeArray(Serializer& s, T* array, SerialSizeType const len) { - // count bytes +inline +std::enable_if_t< + not SerializableTraits::is_traversable + and + std::is_same::value, + void + > +serializeArray(Serializer& s, T* array, SerialSizeType const len) { + s.addBytes(sizeof(T) * len); } template diff --git a/src/checkpoint/traits/serializable_traits.h b/src/checkpoint/traits/serializable_traits.h index 3f4af970..e6cda215 100644 --- a/src/checkpoint/traits/serializable_traits.h +++ b/src/checkpoint/traits/serializable_traits.h @@ -211,13 +211,8 @@ struct SerializableTraits { static constexpr auto const is_serializable = has_serialize_function and is_constructible; - using is_footprintable = std::is_same< - std::size_t, - decltype(checkpoint::getMemoryFootprint(std::declval())) - >; - - static constexpr auto const is_footprintable_v = - is_footprintable::value; + static constexpr auto const is_traversable = + has_serialize_function or is_bytecopyable; }; } // end namespace checkpoint diff --git a/tests/unit/test_footprinter.cc b/tests/unit/test_footprinter.cc index 52ee5186..8ae2a2c0 100644 --- a/tests/unit/test_footprinter.cc +++ b/tests/unit/test_footprinter.cc @@ -601,12 +601,6 @@ struct TestNoSerialize { TEST_F(TestFootprinter, test_no_serialize) { std::vector v(7); - std::cout << std::boolalpha; - std::cout << SerializableTraits::is_footprintable_v << std::endl; - std::cout << SerializableTraits::is_footprintable_v << std::endl; - std::cout << SerializableTraits::is_footprintable_v << std::endl; - // all 3 return 'true' - EXPECT_EQ( checkpoint::getMemoryFootprint(v), sizeof(v) + v.capacity() * sizeof(TestNoSerialize)