diff --git a/dune/matrix-vector/genericvectortools.hh b/dune/matrix-vector/genericvectortools.hh index 8cafcb433ad738435f4cde74944cc29b9b3cb18f..27aa99594889e8276b2154a76fc05063ae877c63 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