From 82c6f22465bcca2fc8c8b2cb45a060a426b640da Mon Sep 17 00:00:00 2001 From: Arkadiusz Szczepkowicz Date: Mon, 27 May 2024 18:44:08 +0200 Subject: [PATCH 1/3] #335: Add unit tests for std::queue serializer --- tests/unit/test_container.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_container.cc b/tests/unit/test_container.cc index 06bdd0df..ec67cb40 100644 --- a/tests/unit/test_container.cc +++ b/tests/unit/test_container.cc @@ -58,6 +58,11 @@ struct TestContainerUnordered : TestHarness { }; TYPED_TEST_CASE_P(TestContainer); TYPED_TEST_CASE_P(TestContainerUnordered); +template +static void testEqualityContainerOrdered(std::queue c1, std::queue t1) { + EXPECT_EQ(c1, t1); +} + template static void testEqualityContainerOrdered(ContainerT& c1, ContainerT& t1) { for (auto i = c1.begin(), j = t1.begin(), i_end = c1.end(), j_end = t1.end(); @@ -155,7 +160,8 @@ using ContOrderedTypes = ::testing::Types< std::list, std::deque, std::set, - std::multiset + std::multiset, + std::queue >; template From 9ba50c4717b64a3633baeea9d32b8a112dfac22c Mon Sep 17 00:00:00 2001 From: Arkadiusz Szczepkowicz Date: Mon, 27 May 2024 18:44:33 +0200 Subject: [PATCH 2/3] #335: Add std::queue serializer --- src/checkpoint/container/queue_serialize.h | 43 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/checkpoint/container/queue_serialize.h b/src/checkpoint/container/queue_serialize.h index a1e88db2..ddca1da2 100644 --- a/src/checkpoint/container/queue_serialize.h +++ b/src/checkpoint/container/queue_serialize.h @@ -51,8 +51,49 @@ namespace checkpoint { +template +void deserializeQueueElems(SerializerT& s, std::queue& q, typename std::queue::size_type size) { + using Reconstructor = + dispatch::Reconstructor::CleanT>; + + dispatch::Allocator allocated; + for (typename std::queue::size_type i = 0; i < size; ++i) { + auto* reconstructed = Reconstructor::construct(allocated.buf); + s | *reconstructed; + q.push(std::move(*reconstructed)); + } +} + +template +void serializeQueueElems(SerializerT& s, std::queue q) { + while(!q.empty()) { + s | q.front(); + q.pop(); + } +} + +template < + typename SerializerT, + typename T, + typename = std::enable_if_t< + not std::is_same< + SerializerT, + checkpoint::Footprinter + >::value + > +> +void serializeQueueLikeContainer(SerializerT& s, std::queue& q) { + typename std::queue::size_type size = serializeContainerSize(s, q); + + if (s.isUnpacking()) { + deserializeQueueElems(s, q, size); + } else { + serializeQueueElems(s, q); + } +} + template -void serialize(Serializer& s, const std::queue& q) { +void serialize(Serializer& s, std::queue& q) { serializeQueueLikeContainer(s, q); } From 26d428a3d62a5e4a7a573bc4c9bcc9ecdd148550 Mon Sep 17 00:00:00 2001 From: Arkadiusz Szczepkowicz Date: Tue, 28 May 2024 18:11:41 +0200 Subject: [PATCH 3/3] #335: Update is_same to is_same_v --- src/checkpoint/container/queue_serialize.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/checkpoint/container/queue_serialize.h b/src/checkpoint/container/queue_serialize.h index ddca1da2..0ac6573e 100644 --- a/src/checkpoint/container/queue_serialize.h +++ b/src/checkpoint/container/queue_serialize.h @@ -76,10 +76,7 @@ template < typename SerializerT, typename T, typename = std::enable_if_t< - not std::is_same< - SerializerT, - checkpoint::Footprinter - >::value + not std::is_same_v > > void serializeQueueLikeContainer(SerializerT& s, std::queue& q) { @@ -111,10 +108,7 @@ template < typename SerializerT, typename Q, typename = std::enable_if_t< - std::is_same< - SerializerT, - checkpoint::Footprinter - >::value + std::is_same_v > > void serializeQueueLikeContainer(SerializerT& s, const Q& q) {