Serialize std::chrono::system_clock::time_point through std::time_t

This commit is contained in:
Joakim Hove
2021-01-03 10:30:51 +01:00
parent c037bd762d
commit fff19a2cf3
2 changed files with 26 additions and 0 deletions

View File

@@ -22,6 +22,7 @@
#endif
#include "ParallelRestart.hpp"
#include <ctime>
#include <dune/common/parallel/mpitraits.hh>
#define HANDLE_AS_POD(T) \
@@ -282,6 +283,13 @@ std::size_t packSize(const RestartValue& data, Dune::MPIHelper::MPICommunicator
+ packSize(data.extra, comm);
}
std::size_t packSize(const std::chrono::system_clock::time_point&, Dune::MPIHelper::MPICommunicator comm)
{
std::time_t tp;
return packSize(tp, comm);
}
////// pack routines
template<class T>
@@ -568,6 +576,13 @@ void pack(const RestartValue& data, std::vector<char>& buffer, int& position,
pack(data.extra, buffer, position, comm);
}
void pack(const std::chrono::system_clock::time_point& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
pack(std::chrono::system_clock::to_time_t(data), buffer, position, comm);
}
/// unpack routines
template<class T>
@@ -872,6 +887,15 @@ void unpack(RestartValue& data, std::vector<char>& buffer, int& position,
unpack(data.extra, buffer, position, comm);
}
void unpack(std::chrono::system_clock::time_point& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
std::time_t tp;
unpack(tp, buffer, position, comm);
data = std::chrono::system_clock::from_time_t(tp);
}
#define INSTANTIATE_PACK_VECTOR(...) \
template std::size_t packSize(const std::vector<__VA_ARGS__>& data, \
Dune::MPIHelper::MPICommunicator comm); \