From 5ced4fff4fdec901ecb2360aad4a24cab1e0aa05 Mon Sep 17 00:00:00 2001 From: Max Kahnt <max.kahnt@fu-berlin.de> Date: Thu, 28 Sep 2017 15:37:45 +0200 Subject: [PATCH] Refactorization: - smoothen docu - name helper struct - add implementation namespace --- dune/matrix-vector/genericvectortools.hh | 36 +++++++++++++++--------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/dune/matrix-vector/genericvectortools.hh b/dune/matrix-vector/genericvectortools.hh index 8cafcb4..27aa995 100644 --- a/dune/matrix-vector/genericvectortools.hh +++ b/dune/matrix-vector/genericvectortools.hh @@ -1,46 +1,53 @@ -#ifndef DUNE_MATRIX_VECTOR_GENERICVECTORTOOLS_HH +#ifndef DUNE_MATRIX_VECTOR_GENERICVECTORTOOLS_HH #define DUNE_MATRIX_VECTOR_GENERICVECTORTOOLS_HH /** \file - \brief Various tools for working with istl vectors of arbitrary nesting depth -*/ + * \brief Various tools for working with istl vectors of arbitrary nesting depth + */ +#include <iostream> #include <dune/common/fvector.hh> #include <dune/common/hybridutilities.hh> -#include <dune/matrix-vector/algorithm.hh> -#include <iostream> +#include <dune/matrix-vector/algorithm.hh> -/** \brief Various tools for working with istl vectors of arbitrary nesting depth -*/ +//! \brief Various tools for working with istl vectors of arbitrary nesting depth namespace Dune { namespace MatrixVector { namespace Generic { // TODO change namespace name +// forward declaration for helper struct +namespace Impl { template <class Vector, typename Enable = void> -struct Helper; +struct ScalarSwitch; +} // end namespace Impl //! Write vector to given stream template <class Vector> void writeBinary(std::ostream& s, const Vector& v) { - Helper<Vector>::writeBinary(s, v); + Impl::ScalarSwitch<Vector>::writeBinary(s, v); } //! Read vector from given stream template <class Vector> void readBinary(std::istream& s, Vector& v) { - Helper<Vector>::readBinary(s, v); + Impl::ScalarSwitch<Vector>::readBinary(s, v); } //! Truncate vector by given bit set template <class Vector, class BitVector> void truncate(Vector& v, const BitVector& tr) { - Helper<Vector>::truncate(v, tr); + Impl::ScalarSwitch<Vector>::truncate(v, tr); } +namespace Impl { + //! recursion helper for scalars nested in iterables (vectors) template <class Vector> -struct Helper<Vector, typename std::enable_if_t<not IsNumber<Vector>::value>> { +struct ScalarSwitch<Vector, + typename std::enable_if_t<not IsNumber<Vector>::value>> { + using This = ScalarSwitch<Vector>; + static void writeBinary(std::ostream& s, const Vector& v) { Hybrid::forEach(v, [&s](auto&& vi) { Generic::writeBinary(s, vi); }); } @@ -58,7 +65,8 @@ struct Helper<Vector, typename std::enable_if_t<not IsNumber<Vector>::value>> { //! recursion anchors for scalars template <class Scalar> -struct Helper<Scalar, typename std::enable_if_t<IsNumber<Scalar>::value>> { +struct ScalarSwitch<Scalar, + typename std::enable_if_t<IsNumber<Scalar>::value>> { static void writeBinary(std::ostream& s, const Scalar& v) { s.write(reinterpret_cast<const char*>(&v), sizeof(Scalar)); } @@ -75,6 +83,8 @@ struct Helper<Scalar, typename std::enable_if_t<IsNumber<Scalar>::value>> { } }; +} // end namespace Impl + } // end namespace Generic } // end namespace MatrixVector } // end namespace Dune -- GitLab