add map handler to eclmpiserializer

This commit is contained in:
Arne Morten Kvarving 2020-03-16 14:39:10 +01:00
parent 30cac6b648
commit 5eb2ec30a5

View File

@ -81,6 +81,44 @@ public:
}
}
template<template<class Key, class Data> class Map, class Key, class Data>
void map(Map<Key, Data>& data)
{
auto handle = [&](auto& d)
{
if constexpr (is_vector<Data>::value)
vector(d);
else if constexpr (is_shared_ptr<Data>::value)
shared_ptr(d);
else
d.serializeOp(*this);
};
if (m_op == Operation::PACKSIZE) {
m_packSize += Mpi::packSize(data.size(), m_comm);
for (auto& it : data) {
m_packSize += Mpi::packSize(it.first, m_comm);
handle(it.second);
}
} else if (m_op == Operation::PACK) {
Mpi::pack(data.size(), m_buffer, m_position, m_comm);
for (auto& it : data) {
Mpi::pack(it.first, m_buffer, m_position, m_comm);
handle(it.second);
}
} else if (m_op == Operation::UNPACK) {
size_t size;
Mpi::unpack(size, m_buffer, m_position, m_comm);
for (size_t i = 0; i < size; ++i) {
Key key;
Mpi::unpack(key, m_buffer, m_position, m_comm);
Data entry;
handle(entry);
data.insert(std::make_pair(key, entry));
}
}
}
template<class T>
void pack(T& data)
{
@ -137,6 +175,16 @@ protected:
constexpr static bool value = true;
};
template<class T>
struct is_vector {
constexpr static bool value = false;
};
template<class T1>
struct is_vector<std::vector<T1>> {
constexpr static bool value = true;
};
template<class T>
struct is_shared_ptr {
constexpr static bool value = false;