Skip to content

Commit

Permalink
#156: Get serializeArray working for non-serializable types
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilMiller committed Nov 24, 2020
1 parent cc0f0d4 commit f650ecc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/checkpoint/dispatch/dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ buffer::ImplReturnType packBuffer(
T& target, SerialSizeType size, BufferObtainFnType fn
);

template <typename Serializer, typename T>
inline void serializeArray(Serializer& s, T* array, SerialSizeType const len);
//template <typename Serializer, typename T>
//inline void serializeArray(Serializer& s, T* array, SerialSizeType const len);

template <typename T>
buffer::ImplReturnType serializeType(T& target, BufferObtainFnType fn = nullptr);
Expand Down
23 changes: 15 additions & 8 deletions src/checkpoint/dispatch/dispatch.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,29 @@ T* Standard::construct(SerialByteType* mem) {
return Traverse::reconstruct<T>(mem);
}

template <typename Serializer, typename T>
inline void serializeArray(Serializer& s, T* array, SerialSizeType const len) {
template <
typename Serializer,
typename T
>
inline std::enable_if_t< SerializableTraits<T, Serializer>::is_traversable, void > serializeArray(Serializer& s, T* array, SerialSizeType const len) {
if (len > 0) {
Traverse::with<T, Serializer>(*array, s, len);
}
}

template <
typename Serializer,
typename T,
typename = std::enable_if_t<
not SerializableTraits<T>::is_footprintable_v
>
typename T
>
inline void serializeArray(Serializer& s, T* array, SerialSizeType const len) {
// count bytes
inline
std::enable_if_t<
not SerializableTraits<T, Serializer>::is_traversable
and
std::is_same<Serializer, checkpoint::Footprinter>::value,
void
>
serializeArray(Serializer& s, T* array, SerialSizeType const len) {
s.addBytes(sizeof(T) * len);
}

template <typename T>
Expand Down
9 changes: 2 additions & 7 deletions src/checkpoint/traits/serializable_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T&>()))
>;

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
Expand Down
6 changes: 0 additions & 6 deletions tests/unit/test_footprinter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -601,12 +601,6 @@ struct TestNoSerialize {
TEST_F(TestFootprinter, test_no_serialize) {
std::vector<TestNoSerialize> v(7);

std::cout << std::boolalpha;
std::cout << SerializableTraits<int>::is_footprintable_v << std::endl;
std::cout << SerializableTraits<Test1>::is_footprintable_v << std::endl;
std::cout << SerializableTraits<TestNoSerialize>::is_footprintable_v << std::endl;
// all 3 return 'true'

EXPECT_EQ(
checkpoint::getMemoryFootprint(v),
sizeof(v) + v.capacity() * sizeof(TestNoSerialize)
Expand Down

0 comments on commit f650ecc

Please sign in to comment.