From: Luca Heltai Date: Sat, 18 Nov 2017 19:18:27 +0000 (+0100) Subject: Added support for tuple serialization in Utilities. X-Git-Tag: v9.0.0-rc1~754^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F5500%2Fhead;p=dealii.git Added support for tuple serialization in Utilities. --- diff --git a/include/deal.II/base/utilities.h b/include/deal.II/base/utilities.h index 4c44c34643..9aef3ed0fe 100644 --- a/include/deal.II/base/utilities.h +++ b/include/deal.II/base/utilities.h @@ -23,6 +23,7 @@ #include #include #include +#include #ifdef DEAL_II_WITH_TRILINOS # include @@ -833,4 +834,43 @@ namespace Utilities DEAL_II_NAMESPACE_CLOSE +#ifndef DOXYGEN +namespace boost +{ + namespace serialization + { + + // Provides boost and c++11 with a way to serialize tuples and pairs automatically + template + struct Serialize + { + template + static void serialize(Archive &ar, std::tuple &t, const unsigned int version) + { + ar &std::get(t); + Serialize::serialize(ar, t, version); + } + }; + + template<> + struct Serialize<0> + { + template + static void serialize(Archive &ar, std::tuple &t, const unsigned int version) + { + (void) ar; + (void) t; + (void) version; + } + }; + + template + void serialize(Archive &ar, std::tuple &t, const unsigned int version) + { + Serialize::serialize(ar, t, version); + } + } +} +#endif + #endif diff --git a/tests/base/utilities_pack_unpack_02.cc b/tests/base/utilities_pack_unpack_02.cc new file mode 100644 index 0000000000..194354ee55 --- /dev/null +++ b/tests/base/utilities_pack_unpack_02.cc @@ -0,0 +1,68 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// test Utilities::pack/unpack on some types. + +#include "../tests.h" + +#include +#include +#include + +#include + +template +void test(const unsigned int &size) +{ + std::vector > points(size); + auto a_pair = std::make_pair(1, 3.14); + + for (auto &p : points) + for (unsigned int i=0; i(buffer); + + auto pair_unpacked = std::get<0>(tuple_unpacked); + auto points_unpacked = std::get<1>(tuple_unpacked); + + unsigned int i=0; + bool ok = (pair_unpacked == a_pair); + + for (const auto &p : points) + if (p.distance(points_unpacked[i++]) > 1e-12) + { + deallog << "NOT OK: " + << p << " != " << points_unpacked[i-1] << std::endl; + ok = false; + } + + if (ok) + deallog << "OK!" << std::endl; +} + +int main() +{ + initlog(); + + test<1>(10); + test<2>(10); + test<3>(10); +} diff --git a/tests/base/utilities_pack_unpack_02.output b/tests/base/utilities_pack_unpack_02.output new file mode 100644 index 0000000000..7ca52c43a9 --- /dev/null +++ b/tests/base/utilities_pack_unpack_02.output @@ -0,0 +1,4 @@ + +DEAL::OK! +DEAL::OK! +DEAL::OK!