Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#335: Add std::queue serializer #342

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading