mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #4108 from akva2/serializer_simplify
Simplifications in serializer
This commit is contained in:
commit
304788dbe8
@ -24,6 +24,8 @@
|
|||||||
#include <opm/simulators/utils/MPIPacker.hpp>
|
#include <opm/simulators/utils/MPIPacker.hpp>
|
||||||
#include <opm/simulators/utils/ParallelCommunication.hpp>
|
#include <opm/simulators/utils/ParallelCommunication.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <set>
|
#include <set>
|
||||||
@ -35,9 +37,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Opm {
|
namespace Opm {
|
||||||
|
namespace detail {
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
|
|
||||||
template<typename ...Ts>
|
template<typename ...Ts>
|
||||||
struct MakeVariantImpl
|
struct MakeVariantImpl
|
||||||
@ -81,9 +81,7 @@ public:
|
|||||||
m_comm(comm)
|
m_comm(comm)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//! \brief (De-)serialization for simple types.
|
//! \brief Applies current serialization op to the passed data.
|
||||||
//! \details The data handled by this depends on the underlying serialization used.
|
|
||||||
//! Currently you can call this for scalars, and stl containers with scalars.
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void operator()(const T& data)
|
void operator()(const T& data)
|
||||||
{
|
{
|
||||||
@ -96,292 +94,22 @@ public:
|
|||||||
} else if constexpr (is_optional<T>::value) {
|
} else if constexpr (is_optional<T>::value) {
|
||||||
optional(data);
|
optional(data);
|
||||||
} else if constexpr (is_vector<T>::value) {
|
} else if constexpr (is_vector<T>::value) {
|
||||||
vector(const_cast<T&>(data));
|
vector(data);
|
||||||
} else if constexpr (is_map<T>::value) {
|
} else if constexpr (is_map<T>::value) {
|
||||||
map(const_cast<T&>(data));
|
map(data);
|
||||||
} else if constexpr (is_array<T>::value) {
|
} else if constexpr (is_array<T>::value) {
|
||||||
array(const_cast<T&>(data));
|
array(data);
|
||||||
} else if constexpr (is_set<T>::value) {
|
} else if constexpr (is_set<T>::value) {
|
||||||
set(const_cast<T&>(data));
|
set(data);
|
||||||
} else if constexpr (has_serializeOp<detail::remove_cvr_t<T>>::value) {
|
} else if constexpr (has_serializeOp<detail::remove_cvr_t<T>>::value) {
|
||||||
const_cast<T&>(data).serializeOp(*this);
|
const_cast<T&>(data).serializeOp(*this);
|
||||||
} else {
|
} else {
|
||||||
if (m_op == Operation::PACKSIZE)
|
if (m_op == Operation::PACKSIZE)
|
||||||
m_packSize += Mpi::Packer::packSize(data, m_comm);
|
m_packSize += Mpi::Packer::packSize(data, m_comm);
|
||||||
else if (m_op == Operation::PACK)
|
else if (m_op == Operation::PACK)
|
||||||
Mpi::Packer::pack(data, m_buffer, m_position, m_comm);
|
Mpi::Packer::pack(data, m_buffer, m_position, m_comm);
|
||||||
else if (m_op == Operation::UNPACK)
|
else if (m_op == Operation::UNPACK)
|
||||||
Mpi::Packer::unpack(const_cast<T&>(data), m_buffer, m_position, m_comm);
|
Mpi::Packer::unpack(const_cast<T&>(data), m_buffer, m_position, m_comm);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \brief Handler for vectors.
|
|
||||||
//! \tparam T Type for vector elements
|
|
||||||
//! \param data The vector to (de-)serialize
|
|
||||||
template <typename T>
|
|
||||||
void vector(std::vector<T>& data)
|
|
||||||
{
|
|
||||||
[[maybe_unused]] auto handle = [&](auto& d)
|
|
||||||
{
|
|
||||||
for (auto& it : d) {
|
|
||||||
if constexpr (is_pair_or_tuple<T>::value)
|
|
||||||
tuple(it);
|
|
||||||
else if constexpr (is_ptr<T>::value)
|
|
||||||
ptr(it);
|
|
||||||
else if constexpr (is_vector<T>::value)
|
|
||||||
vector(it);
|
|
||||||
else if constexpr (has_serializeOp<T>::value)
|
|
||||||
it.serializeOp(*this);
|
|
||||||
else
|
|
||||||
(*this)(it);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (m_op == Operation::PACKSIZE) {
|
|
||||||
m_packSize += Mpi::Packer::packSize(data.size(), m_comm);
|
|
||||||
if constexpr (std::is_pod_v<T>)
|
|
||||||
m_packSize += Mpi::Packer::packSize(data.data(), data.size(), m_comm);
|
|
||||||
else
|
|
||||||
handle(data);
|
|
||||||
} else if (m_op == Operation::PACK) {
|
|
||||||
Mpi::Packer::pack(data.size(), m_buffer, m_position, m_comm);
|
|
||||||
if constexpr (std::is_pod_v<T>)
|
|
||||||
Mpi::Packer::pack(data.data(), data.size(), m_buffer, m_position, m_comm);
|
|
||||||
else
|
|
||||||
handle(data);
|
|
||||||
} else if (m_op == Operation::UNPACK) {
|
|
||||||
size_t size;
|
|
||||||
Mpi::Packer::unpack(size, m_buffer, m_position, m_comm);
|
|
||||||
data.resize(size);
|
|
||||||
if constexpr (std::is_pod_v<T>)
|
|
||||||
Mpi::Packer::unpack(data.data(), size, m_buffer, m_position, m_comm);
|
|
||||||
else
|
|
||||||
handle(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \brief Handler for bool vectors.
|
|
||||||
//! \param data The vector to (de-)serialize
|
|
||||||
void vector(std::vector<bool>& data)
|
|
||||||
{
|
|
||||||
if (m_op == Operation::PACKSIZE) {
|
|
||||||
m_packSize += Mpi::Packer::packSize(data.size(), m_comm);
|
|
||||||
m_packSize += data.size()*Mpi::Packer::packSize(bool(), m_comm);
|
|
||||||
} else if (m_op == Operation::PACK) {
|
|
||||||
(*this)(data.size());
|
|
||||||
for (const auto entry : data) { // Not a reference: vector<bool> range
|
|
||||||
bool b = entry;
|
|
||||||
(*this)(b);
|
|
||||||
}
|
|
||||||
} else if (m_op == Operation::UNPACK) {
|
|
||||||
size_t size;
|
|
||||||
(*this)(size);
|
|
||||||
data.clear();
|
|
||||||
data.reserve(size);
|
|
||||||
for (size_t i = 0; i < size; ++i) {
|
|
||||||
bool entry;
|
|
||||||
(*this)(entry);
|
|
||||||
data.push_back(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \brief Handler for arrays.
|
|
||||||
//! \param data The array to (de-)serialize
|
|
||||||
template <class Array>
|
|
||||||
void array(Array& data)
|
|
||||||
{
|
|
||||||
using T = typename Array::value_type;
|
|
||||||
|
|
||||||
[[maybe_unused]] auto handle = [&](auto& d) {
|
|
||||||
for (auto& it : d) {
|
|
||||||
if constexpr (is_pair_or_tuple<T>::value)
|
|
||||||
tuple(it);
|
|
||||||
else if constexpr (is_ptr<T>::value)
|
|
||||||
ptr(it);
|
|
||||||
else if constexpr (has_serializeOp<T>::value)
|
|
||||||
it.serializeOp(*this);
|
|
||||||
else
|
|
||||||
(*this)(it);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (m_op == Operation::PACKSIZE) {
|
|
||||||
if constexpr (std::is_pod_v<T>)
|
|
||||||
m_packSize += Mpi::Packer::packSize(data.data(), data.size(), m_comm);
|
|
||||||
else
|
|
||||||
handle(data);
|
|
||||||
} else if (m_op == Operation::PACK) {
|
|
||||||
if constexpr (std::is_pod_v<T>)
|
|
||||||
Mpi::Packer::pack(data.data(), data.size(), m_buffer, m_position, m_comm);
|
|
||||||
else
|
|
||||||
handle(data);
|
|
||||||
} else if (m_op == Operation::UNPACK) {
|
|
||||||
if constexpr (std::is_pod_v<T>)
|
|
||||||
Mpi::Packer::unpack(data.data(), data.size(), m_buffer, m_position, m_comm);
|
|
||||||
else
|
|
||||||
handle(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \brief Handler for std::variant.
|
|
||||||
//! \param data The variant to (de-)serialize
|
|
||||||
template<class... Args>
|
|
||||||
void variant(const std::variant<Args...>& data)
|
|
||||||
{
|
|
||||||
auto visitor = [&](auto& d)
|
|
||||||
{
|
|
||||||
if constexpr (has_serializeOp<detail::remove_cvr_t<decltype(d)>>::value)
|
|
||||||
const_cast<detail::remove_cvr_t<decltype(d)>&>(d).serializeOp(*this);
|
|
||||||
else
|
|
||||||
(*this)(d);
|
|
||||||
};
|
|
||||||
if (m_op == Operation::PACKSIZE) {
|
|
||||||
m_packSize += Mpi::Packer::packSize(data.index(), m_comm);
|
|
||||||
std::visit(visitor, data);
|
|
||||||
} else if (m_op == Operation::PACK) {
|
|
||||||
Mpi::Packer::pack(data.index(), m_buffer, m_position, m_comm);
|
|
||||||
std::visit(visitor, data);
|
|
||||||
} else if (m_op == Operation::UNPACK) {
|
|
||||||
size_t index;
|
|
||||||
Mpi::Packer::unpack(index, m_buffer, m_position, m_comm);
|
|
||||||
auto& data_mut = const_cast<std::variant<Args...>&>(data);
|
|
||||||
data_mut = detail::make_variant<Args...>(index);
|
|
||||||
std::visit(visitor, data_mut);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \brief Handler for std::optional.
|
|
||||||
//! \tparam T Type for data
|
|
||||||
//! \param data The optional to (de-)serialize
|
|
||||||
template<class T>
|
|
||||||
void optional(const std::optional<T>& data)
|
|
||||||
{
|
|
||||||
if (m_op == Operation::PACKSIZE) {
|
|
||||||
m_packSize += Mpi::Packer::packSize(data.has_value(), m_comm);
|
|
||||||
if (data.has_value()) {
|
|
||||||
(*this)(*data);
|
|
||||||
}
|
|
||||||
} else if (m_op == Operation::PACK) {
|
|
||||||
Mpi::Packer::pack(data.has_value(), m_buffer, m_position, m_comm);
|
|
||||||
if (data.has_value()) {
|
|
||||||
(*this)(*data);
|
|
||||||
}
|
|
||||||
} else if (m_op == Operation::UNPACK) {
|
|
||||||
bool has;
|
|
||||||
Mpi::Packer::unpack(has, m_buffer, m_position, m_comm);
|
|
||||||
if (has) {
|
|
||||||
T res;
|
|
||||||
(*this)(res);
|
|
||||||
const_cast<std::optional<T>&>(data) = res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \brief Handler for std::tuple.
|
|
||||||
//! \param data The tuple to (de-)serialize
|
|
||||||
template<class Tuple>
|
|
||||||
void tuple(const Tuple& data)
|
|
||||||
{
|
|
||||||
tuple_call(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \brief Handler for maps.
|
|
||||||
//! \tparam Map map type
|
|
||||||
//! \param map The map to (de-)serialize
|
|
||||||
template<class Map>
|
|
||||||
void map(Map& data)
|
|
||||||
{
|
|
||||||
using Key = typename Map::key_type;
|
|
||||||
using Data = typename Map::mapped_type;
|
|
||||||
|
|
||||||
auto handle = [&](auto& d)
|
|
||||||
{
|
|
||||||
if constexpr (is_vector<Data>::value)
|
|
||||||
vector(d);
|
|
||||||
else if constexpr (is_ptr<Data>::value)
|
|
||||||
ptr(d);
|
|
||||||
else if constexpr (is_map<Data>::value)
|
|
||||||
map(d);
|
|
||||||
else if constexpr (has_serializeOp<Data>::value)
|
|
||||||
d.serializeOp(*this);
|
|
||||||
else
|
|
||||||
(*this)(d);
|
|
||||||
};
|
|
||||||
|
|
||||||
auto keyHandle = [&](auto& d)
|
|
||||||
{
|
|
||||||
if constexpr (is_pair_or_tuple<Key>::value)
|
|
||||||
tuple(d);
|
|
||||||
else if constexpr (has_serializeOp<Key>::value)
|
|
||||||
d.serializeOp(*this);
|
|
||||||
else
|
|
||||||
(*this)(d);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (m_op == Operation::PACKSIZE) {
|
|
||||||
m_packSize += Mpi::Packer::packSize(data.size(), m_comm);
|
|
||||||
for (auto& it : data) {
|
|
||||||
keyHandle(it.first);
|
|
||||||
handle(it.second);
|
|
||||||
}
|
|
||||||
} else if (m_op == Operation::PACK) {
|
|
||||||
Mpi::Packer::pack(data.size(), m_buffer, m_position, m_comm);
|
|
||||||
for (auto& it : data) {
|
|
||||||
keyHandle(it.first);
|
|
||||||
handle(it.second);
|
|
||||||
}
|
|
||||||
} else if (m_op == Operation::UNPACK) {
|
|
||||||
size_t size;
|
|
||||||
Mpi::Packer::unpack(size, m_buffer, m_position, m_comm);
|
|
||||||
for (size_t i = 0; i < size; ++i) {
|
|
||||||
Key key;
|
|
||||||
keyHandle(key);
|
|
||||||
Data entry;
|
|
||||||
handle(entry);
|
|
||||||
data.insert(std::make_pair(key, entry));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \brief Handler for sets.
|
|
||||||
//! \tparam Set set type
|
|
||||||
//! \param data The set to (de-)serialize
|
|
||||||
template<class Set>
|
|
||||||
void set(Set& data)
|
|
||||||
{
|
|
||||||
using Data = typename Set::value_type;
|
|
||||||
|
|
||||||
auto handle = [&](auto& d)
|
|
||||||
{
|
|
||||||
if constexpr (is_vector<Data>::value)
|
|
||||||
vector(d);
|
|
||||||
else if constexpr (is_ptr<Data>::value)
|
|
||||||
ptr(d);
|
|
||||||
else if constexpr (has_serializeOp<Data>::value)
|
|
||||||
d.serializeOp(*this);
|
|
||||||
else
|
|
||||||
(*this)(d);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (m_op == Operation::PACKSIZE) {
|
|
||||||
m_packSize += Mpi::Packer::packSize(data.size(), m_comm);
|
|
||||||
for (auto& it : data) {
|
|
||||||
handle(it);
|
|
||||||
}
|
|
||||||
} else if (m_op == Operation::PACK) {
|
|
||||||
Mpi::Packer::pack(data.size(), m_buffer, m_position, m_comm);
|
|
||||||
for (auto& it : data) {
|
|
||||||
handle(it);
|
|
||||||
}
|
|
||||||
} else if (m_op == Operation::UNPACK) {
|
|
||||||
size_t size;
|
|
||||||
Mpi::Packer::unpack(size, m_buffer, m_position, m_comm);
|
|
||||||
for (size_t i = 0; i < size; ++i) {
|
|
||||||
Data entry;
|
|
||||||
handle(entry);
|
|
||||||
data.insert(entry);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,15 +117,15 @@ public:
|
|||||||
//! \tparam T Type of class to serialize
|
//! \tparam T Type of class to serialize
|
||||||
//! \param data Class to serialize
|
//! \param data Class to serialize
|
||||||
template<class T>
|
template<class T>
|
||||||
void pack(T& data)
|
void pack(const T& data)
|
||||||
{
|
{
|
||||||
m_op = Operation::PACKSIZE;
|
m_op = Operation::PACKSIZE;
|
||||||
m_packSize = 0;
|
m_packSize = 0;
|
||||||
data.serializeOp(*this);
|
(*this)(data);
|
||||||
m_position = 0;
|
m_position = 0;
|
||||||
m_buffer.resize(m_packSize);
|
m_buffer.resize(m_packSize);
|
||||||
m_op = Operation::PACK;
|
m_op = Operation::PACK;
|
||||||
data.serializeOp(*this);
|
(*this)(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief Call this to de-serialize data.
|
//! \brief Call this to de-serialize data.
|
||||||
@ -408,7 +136,7 @@ public:
|
|||||||
{
|
{
|
||||||
m_position = 0;
|
m_position = 0;
|
||||||
m_op = Operation::UNPACK;
|
m_op = Operation::UNPACK;
|
||||||
data.serializeOp(*this);
|
(*this)(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief Serialize and broadcast on root process, de-serialize on
|
//! \brief Serialize and broadcast on root process, de-serialize on
|
||||||
@ -515,6 +243,174 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
//! \brief Handler for vectors.
|
||||||
|
//! \tparam T Type for vector elements
|
||||||
|
//! \param data The vector to (de-)serialize
|
||||||
|
template <typename T>
|
||||||
|
void vector(const std::vector<T>& data)
|
||||||
|
{
|
||||||
|
if constexpr (std::is_pod_v<T>) {
|
||||||
|
if (m_op == Operation::PACKSIZE) {
|
||||||
|
(*this)(data.size());
|
||||||
|
m_packSize += Mpi::Packer::packSize(data.data(), data.size(), m_comm);
|
||||||
|
} else if (m_op == Operation::PACK) {
|
||||||
|
(*this)(data.size());
|
||||||
|
Mpi::Packer::pack(data.data(), data.size(), m_buffer, m_position, m_comm);
|
||||||
|
} else if (m_op == Operation::UNPACK) {
|
||||||
|
std::size_t size = 0;
|
||||||
|
(*this)(size);
|
||||||
|
auto& data_mut = const_cast<std::vector<T>&>(data);
|
||||||
|
data_mut.resize(size);
|
||||||
|
Mpi::Packer::unpack(data_mut.data(), size, m_buffer, m_position, m_comm);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (m_op == Operation::UNPACK) {
|
||||||
|
std::size_t size = 0;
|
||||||
|
(*this)(size);
|
||||||
|
auto& data_mut = const_cast<std::vector<T>&>(data);
|
||||||
|
data_mut.resize(size);
|
||||||
|
std::for_each(data_mut.begin(), data_mut.end(), std::ref(*this));
|
||||||
|
} else {
|
||||||
|
(*this)(data.size());
|
||||||
|
std::for_each(data.begin(), data.end(), std::ref(*this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Handler for bool vectors.
|
||||||
|
//! \param data The vector to (de-)serialize
|
||||||
|
void vector(const std::vector<bool>& data)
|
||||||
|
{
|
||||||
|
if (m_op == Operation::UNPACK) {
|
||||||
|
std::size_t size = 0;
|
||||||
|
(*this)(size);
|
||||||
|
auto& data_mut = const_cast<std::vector<bool>&>(data);
|
||||||
|
data_mut.clear();
|
||||||
|
data_mut.reserve(size);
|
||||||
|
for (size_t i = 0; i < size; ++i) {
|
||||||
|
bool entry = false;
|
||||||
|
(*this)(entry);
|
||||||
|
data_mut.push_back(entry);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(*this)(data.size());
|
||||||
|
for (const auto entry : data) { // Not a reference: vector<bool> range
|
||||||
|
bool b = entry;
|
||||||
|
(*this)(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Handler for arrays.
|
||||||
|
//! \param data The array to (de-)serialize
|
||||||
|
template <class Array>
|
||||||
|
void array(const Array& data)
|
||||||
|
{
|
||||||
|
using T = typename Array::value_type;
|
||||||
|
|
||||||
|
if constexpr (std::is_pod_v<T>) {
|
||||||
|
if (m_op == Operation::PACKSIZE)
|
||||||
|
m_packSize += Mpi::Packer::packSize(data.data(), data.size(), m_comm);
|
||||||
|
else if (m_op == Operation::PACK)
|
||||||
|
Mpi::Packer::pack(data.data(), data.size(), m_buffer, m_position, m_comm);
|
||||||
|
else if (m_op == Operation::UNPACK) {
|
||||||
|
auto& data_mut = const_cast<Array&>(data);
|
||||||
|
Mpi::Packer::unpack(data_mut.data(), data_mut.size(), m_buffer, m_position, m_comm);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::for_each(data.begin(), data.end(), std::ref(*this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Handler for std::variant.
|
||||||
|
//! \param data The variant to (de-)serialize
|
||||||
|
template<class... Args>
|
||||||
|
void variant(const std::variant<Args...>& data)
|
||||||
|
{
|
||||||
|
if (m_op == Operation::UNPACK) {
|
||||||
|
std::size_t index = 0;
|
||||||
|
(*this)(index);
|
||||||
|
auto& data_mut = const_cast<std::variant<Args...>&>(data);
|
||||||
|
data_mut = detail::make_variant<Args...>(index);
|
||||||
|
std::visit(std::ref(*this), data_mut);
|
||||||
|
} else {
|
||||||
|
(*this)(data.index());
|
||||||
|
std::visit(std::ref(*this), data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Handler for std::optional.
|
||||||
|
//! \tparam T Type for data
|
||||||
|
//! \param data The optional to (de-)serialize
|
||||||
|
template<class T>
|
||||||
|
void optional(const std::optional<T>& data)
|
||||||
|
{
|
||||||
|
if (m_op == Operation::UNPACK) {
|
||||||
|
bool has = false;
|
||||||
|
(*this)(has);
|
||||||
|
if (has) {
|
||||||
|
T res;
|
||||||
|
(*this)(res);
|
||||||
|
const_cast<std::optional<T>&>(data) = res;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(*this)(data.has_value());
|
||||||
|
if (data.has_value()) {
|
||||||
|
(*this)(*data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Handler for std::tuple.
|
||||||
|
//! \param data The tuple to (de-)serialize
|
||||||
|
template<class Tuple>
|
||||||
|
void tuple(const Tuple& data)
|
||||||
|
{
|
||||||
|
tuple_call(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Handler for maps.
|
||||||
|
//! \tparam Map map type
|
||||||
|
//! \param map The map to (de-)serialize
|
||||||
|
template<class Map>
|
||||||
|
void map(const Map& data)
|
||||||
|
{
|
||||||
|
if (m_op == Operation::UNPACK) {
|
||||||
|
std::size_t size = 0;
|
||||||
|
(*this)(size);
|
||||||
|
auto& data_mut = const_cast<Map&>(data);
|
||||||
|
for (size_t i = 0; i < size; ++i) {
|
||||||
|
typename Map::value_type entry;
|
||||||
|
(*this)(entry);
|
||||||
|
data_mut.insert(entry);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(*this)(data.size());
|
||||||
|
std::for_each(data.begin(), data.end(), std::ref(*this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Handler for sets.
|
||||||
|
//! \tparam Set set type
|
||||||
|
//! \param data The set to (de-)serialize
|
||||||
|
template<class Set>
|
||||||
|
void set(const Set& data)
|
||||||
|
{
|
||||||
|
if (m_op == Operation::UNPACK) {
|
||||||
|
std::size_t size = 0;
|
||||||
|
(*this)(size);
|
||||||
|
auto& data_mut = const_cast<Set&>(data);
|
||||||
|
for (size_t i = 0; i < size; ++i) {
|
||||||
|
typename Set::value_type entry;
|
||||||
|
(*this)(entry);
|
||||||
|
data_mut.insert(entry);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(*this)(data.size());
|
||||||
|
std::for_each(data.begin(), data.end(), std::ref(*this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
void variadic_call(T& first,
|
void variadic_call(T& first,
|
||||||
Args&&... args)
|
Args&&... args)
|
||||||
@ -679,10 +575,7 @@ protected:
|
|||||||
const_cast<PtrType&>(data).reset(new T1);
|
const_cast<PtrType&>(data).reset(new T1);
|
||||||
}
|
}
|
||||||
if (data) {
|
if (data) {
|
||||||
if constexpr (has_serializeOp<T1>::value)
|
(*this)(*data);
|
||||||
data->serializeOp(*this);
|
|
||||||
else
|
|
||||||
(*this)(*data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,9 +128,8 @@ unpack(time_point& data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template struct Packing<false,std::bitset<4>>;
|
template struct Packing<false,std::bitset<4>>;
|
||||||
|
template struct Packing<false,std::bitset<10>>;
|
||||||
|
|
||||||
}
|
} // end namespace detail
|
||||||
|
|
||||||
} // end namespace Mpi
|
} // end namespace Mpi
|
||||||
|
|
||||||
} // end namespace Opm
|
} // end namespace Opm
|
||||||
|
@ -116,7 +116,7 @@ public:
|
|||||||
template<class Serializer>
|
template<class Serializer>
|
||||||
void serializeOp(Serializer& serializer)
|
void serializeOp(Serializer& serializer)
|
||||||
{
|
{
|
||||||
serializer.map(m_tran);
|
serializer(m_tran);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
Reference in New Issue
Block a user