Skip to content

Commit

Permalink
Merge pull request #342 from DARMA-tasking/335-add-std-queue-serializer
Browse files Browse the repository at this point in the history
#335: Add `std::queue` serializer
  • Loading branch information
lifflander authored Jun 5, 2024
2 parents c985084 + 26d428a commit f43638e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
45 changes: 40 additions & 5 deletions src/checkpoint/container/queue_serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,46 @@

namespace checkpoint {

template<typename SerializerT, typename T>
void deserializeQueueElems(SerializerT& s, std::queue<T>& q, typename std::queue<T>::size_type size) {
using Reconstructor =
dispatch::Reconstructor<typename dispatch::CleanType<T>::CleanT>;

dispatch::Allocator<T> allocated;
for (typename std::queue<T>::size_type i = 0; i < size; ++i) {
auto* reconstructed = Reconstructor::construct(allocated.buf);
s | *reconstructed;
q.push(std::move(*reconstructed));
}
}

template<typename SerializerT, typename T>
void serializeQueueElems(SerializerT& s, std::queue<T> q) {
while(!q.empty()) {
s | q.front();
q.pop();
}
}

template <
typename SerializerT,
typename T,
typename = std::enable_if_t<
not std::is_same_v<SerializerT, checkpoint::Footprinter>
>
>
void serializeQueueLikeContainer(SerializerT& s, std::queue<T>& q) {
typename std::queue<T>::size_type size = serializeContainerSize(s, q);

if (s.isUnpacking()) {
deserializeQueueElems(s, q, size);
} else {
serializeQueueElems(s, q);
}
}

template <typename Serializer, typename T>
void serialize(Serializer& s, const std::queue<T>& q) {
void serialize(Serializer& s, std::queue<T>& q) {
serializeQueueLikeContainer(s, q);
}

Expand All @@ -70,10 +108,7 @@ template <
typename SerializerT,
typename Q,
typename = std::enable_if_t<
std::is_same<
SerializerT,
checkpoint::Footprinter
>::value
std::is_same_v<SerializerT, checkpoint::Footprinter>
>
>
void serializeQueueLikeContainer(SerializerT& s, const Q& q) {
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/test_container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ struct TestContainerUnordered : TestHarness { };
TYPED_TEST_CASE_P(TestContainer);
TYPED_TEST_CASE_P(TestContainerUnordered);

template <typename T>
static void testEqualityContainerOrdered(std::queue<T> c1, std::queue<T> t1) {
EXPECT_EQ(c1, t1);
}

template <typename ContainerT>
static void testEqualityContainerOrdered(ContainerT& c1, ContainerT& t1) {
for (auto i = c1.begin(), j = t1.begin(), i_end = c1.end(), j_end = t1.end();
Expand Down Expand Up @@ -155,7 +160,8 @@ using ContOrderedTypes = ::testing::Types<
std::list<T>,
std::deque<T>,
std::set<T>,
std::multiset<T>
std::multiset<T>,
std::queue<T>
>;

template <typename T>
Expand Down

0 comments on commit f43638e

Please sign in to comment.