mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Adapt variant serialization to four types
This commit is contained in:
@@ -103,22 +103,22 @@ public:
|
|||||||
The std::variant<> serialization is a first attempt and *not* particularly
|
The std::variant<> serialization is a first attempt and *not* particularly
|
||||||
general. In particular that implies:
|
general. In particular that implies:
|
||||||
|
|
||||||
1. It is hardcoded to hold exactly three alternative types T1, T2 and
|
1. It is hardcoded to hold exactly four alternative types T0, T1, T2 and
|
||||||
T3.
|
T3.
|
||||||
|
|
||||||
2. All the three types T1, T2 and T3 must implement the ::serializeOp( )
|
2. All the four types T0, T1, T2 and T3 must implement the ::serializeOp( )
|
||||||
method. This implies that a variant with a fundamental type like e.g.
|
method. This implies that a variant with a fundamental type like e.g.
|
||||||
std::variant<int, Opm::Well, Opm::Group> will *not* work in the
|
std::variant<int, double, Opm::Well, Opm::Group> will *not* work in the
|
||||||
current implementation.
|
current implementation.
|
||||||
*/
|
*/
|
||||||
template<class T1, class T2, class T3>
|
template<class T0, class T1, class T2, class T3>
|
||||||
void variant(const std::variant<T1,T2,T3>& _data)
|
void variant(const std::variant<T0,T1,T2,T3>& _data)
|
||||||
{
|
{
|
||||||
auto handle = [&](auto& d) {
|
auto handle = [&](auto& d) {
|
||||||
d.serializeOp(*this);
|
d.serializeOp(*this);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::variant<T1,T2,T3>& data = const_cast<std::variant<T1,T2,T3>&>(_data);
|
std::variant<T0,T1,T2,T3>& data = const_cast<std::variant<T0,T1,T2,T3>&>(_data);
|
||||||
if (m_op == Operation::PACKSIZE) {
|
if (m_op == Operation::PACKSIZE) {
|
||||||
m_packSize += Mpi::packSize(data.index(), m_comm);
|
m_packSize += Mpi::packSize(data.index(), m_comm);
|
||||||
std::visit( [&] (auto& arg) { handle(arg); }, data);
|
std::visit( [&] (auto& arg) { handle(arg); }, data);
|
||||||
@@ -130,16 +130,19 @@ public:
|
|||||||
Mpi::unpack(index, m_buffer, m_position, m_comm);
|
Mpi::unpack(index, m_buffer, m_position, m_comm);
|
||||||
|
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
data = T1();
|
data = T0();
|
||||||
handle(std::get<0>(data));
|
handle(std::get<0>(data));
|
||||||
} else if (index == 1) {
|
} else if (index == 1) {
|
||||||
data = T2();
|
data = T1();
|
||||||
handle(std::get<1>(data));
|
handle(std::get<1>(data));
|
||||||
} else if (index == 2) {
|
} else if (index == 2) {
|
||||||
data = T3();
|
data = T2();
|
||||||
handle(std::get<2>(data));
|
handle(std::get<2>(data));
|
||||||
|
} else if (index == 3) {
|
||||||
|
data = T3();
|
||||||
|
handle(std::get<3>(data));
|
||||||
} else
|
} else
|
||||||
std::logic_error("Internal meltdown in std::variant<T1,T2,T3> unpack");
|
std::logic_error("Internal meltdown in std::variant<T0,T1,T2,T3> unpack");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user