Skip to content
Snippets Groups Projects
Commit 5ced4fff authored by Max Kahnt's avatar Max Kahnt
Browse files

Refactorization:

 - smoothen docu
 - name helper struct
 - add implementation namespace
parent 7eefb642
Branches
No related tags found
No related merge requests found
#ifndef DUNE_MATRIX_VECTOR_GENERICVECTORTOOLS_HH #ifndef DUNE_MATRIX_VECTOR_GENERICVECTORTOOLS_HH
#define DUNE_MATRIX_VECTOR_GENERICVECTORTOOLS_HH #define DUNE_MATRIX_VECTOR_GENERICVECTORTOOLS_HH
/** \file /** \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/fvector.hh>
#include <dune/common/hybridutilities.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 Dune {
namespace MatrixVector { namespace MatrixVector {
namespace Generic { // TODO change namespace name namespace Generic { // TODO change namespace name
// forward declaration for helper struct
namespace Impl {
template <class Vector, typename Enable = void> template <class Vector, typename Enable = void>
struct Helper; struct ScalarSwitch;
} // end namespace Impl
//! Write vector to given stream //! Write vector to given stream
template <class Vector> template <class Vector>
void writeBinary(std::ostream& s, const Vector& v) { void writeBinary(std::ostream& s, const Vector& v) {
Helper<Vector>::writeBinary(s, v); Impl::ScalarSwitch<Vector>::writeBinary(s, v);
} }
//! Read vector from given stream //! Read vector from given stream
template <class Vector> template <class Vector>
void readBinary(std::istream& s, Vector& v) { void readBinary(std::istream& s, Vector& v) {
Helper<Vector>::readBinary(s, v); Impl::ScalarSwitch<Vector>::readBinary(s, v);
} }
//! Truncate vector by given bit set //! Truncate vector by given bit set
template <class Vector, class BitVector> template <class Vector, class BitVector>
void truncate(Vector& v, const BitVector& tr) { 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) //! recursion helper for scalars nested in iterables (vectors)
template <class Vector> 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) { static void writeBinary(std::ostream& s, const Vector& v) {
Hybrid::forEach(v, [&s](auto&& vi) { Generic::writeBinary(s, vi); }); 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>> { ...@@ -58,7 +65,8 @@ struct Helper<Vector, typename std::enable_if_t<not IsNumber<Vector>::value>> {
//! recursion anchors for scalars //! recursion anchors for scalars
template <class Scalar> 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) { static void writeBinary(std::ostream& s, const Scalar& v) {
s.write(reinterpret_cast<const char*>(&v), sizeof(Scalar)); s.write(reinterpret_cast<const char*>(&v), sizeof(Scalar));
} }
...@@ -75,6 +83,8 @@ struct Helper<Scalar, typename std::enable_if_t<IsNumber<Scalar>::value>> { ...@@ -75,6 +83,8 @@ struct Helper<Scalar, typename std::enable_if_t<IsNumber<Scalar>::value>> {
} }
}; };
} // end namespace Impl
} // end namespace Generic } // end namespace Generic
} // end namespace MatrixVector } // end namespace MatrixVector
} // end namespace Dune } // end namespace Dune
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment