add support for unique_ptr in EclMpiSerializer

This commit is contained in:
Arne Morten Kvarving
2020-03-19 09:31:07 +01:00
parent 32176b90ef
commit 638a53ac88
+16 -11
View File
@@ -40,8 +40,8 @@ public:
template<class T> template<class T>
void operator()(const T& data) void operator()(const T& data)
{ {
if constexpr (is_shared_ptr<T>::value) { if constexpr (is_ptr<T>::value) {
shared_ptr(data); ptr(data);
} else { } else {
if (m_op == Operation::PACKSIZE) if (m_op == Operation::PACKSIZE)
m_packSize += Mpi::packSize(data, m_comm); m_packSize += Mpi::packSize(data, m_comm);
@@ -60,8 +60,8 @@ public:
for (auto& it : d) { for (auto& it : d) {
if constexpr (is_pair<T>::value) if constexpr (is_pair<T>::value)
pair(it); pair(it);
else if constexpr (is_shared_ptr<T>::value) else if constexpr (is_ptr<T>::value)
shared_ptr(it); ptr(it);
else else
it.serializeOp(*this); it.serializeOp(*this);
} }
@@ -91,8 +91,8 @@ public:
{ {
if constexpr (is_vector<Data>::value) if constexpr (is_vector<Data>::value)
vector(d); vector(d);
else if constexpr (is_shared_ptr<Data>::value) else if constexpr (is_ptr<Data>::value)
shared_ptr(d); ptr(d);
else if constexpr (!complexType) else if constexpr (!complexType)
d.template serializeOp<EclMpiSerializer, false>(*this); d.template serializeOp<EclMpiSerializer, false>(*this);
else else
@@ -196,12 +196,17 @@ protected:
}; };
template<class T> template<class T>
struct is_shared_ptr { struct is_ptr {
constexpr static bool value = false; constexpr static bool value = false;
}; };
template<class T1> template<class T1>
struct is_shared_ptr<std::shared_ptr<T1>> { struct is_ptr<std::shared_ptr<T1>> {
constexpr static bool value = true;
};
template<class T1>
struct is_ptr<std::unique_ptr<T1>> {
constexpr static bool value = true; constexpr static bool value = true;
}; };
@@ -219,13 +224,13 @@ protected:
const_cast<T2&>(data.second).serializeOp(*this); const_cast<T2&>(data.second).serializeOp(*this);
} }
template<class T1> template<template<class T> class PtrType, class T1>
void shared_ptr(const std::shared_ptr<T1>& data) void ptr(const PtrType<T1>& data)
{ {
bool value = data ? true : false; bool value = data ? true : false;
(*this)(value); (*this)(value);
if (m_op == Operation::UNPACK && value) { if (m_op == Operation::UNPACK && value) {
const_cast<std::shared_ptr<T1>&>(data) = std::make_shared<T1>(); const_cast<PtrType<T1>&>(data).reset(new T1);
} }
if (data) if (data)
data->serializeOp(*this); data->serializeOp(*this);