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

Refactor generic vector tools:

 - remove outdated editor hints
 - fix indentation
 - use range based for loop
 - add a typedef for the central helper specialization type
parent 327eece1
No related branches found
No related tags found
No related merge requests found
// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=8 sw=4 sts=4:
#ifndef DUNE_MATRIX_VECTOR_GENERICVECTORTOOLS_HH #ifndef DUNE_MATRIX_VECTOR_GENERICVECTORTOOLS_HH
#define DUNE_MATRIX_VECTOR_GENERICVECTORTOOLS_HH #define DUNE_MATRIX_VECTOR_GENERICVECTORTOOLS_HH
...@@ -17,38 +15,33 @@ namespace Dune { ...@@ -17,38 +15,33 @@ namespace Dune {
namespace MatrixVector { namespace MatrixVector {
namespace Generic { // TODO change namespace name namespace Generic { // TODO change namespace name
template<class Vector> struct Helper; template <class Vector>
struct Helper;
//! 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) {
{ Dune::MatrixVector::Generic::Helper<Vector>::writeBinary(s, v); } Helper<Vector>::writeBinary(s, v);
}
template <class Vector> template <class Vector>
struct Helper struct Helper {
{ static void writeBinary(std::ostream& s, const Vector& v) {
static void writeBinary(std::ostream& s, const Vector& v) for (auto&& vi : v)
{ Generic::writeBinary(s, vi);
typename Vector::const_iterator it = v.begin(); }
typename Vector::const_iterator end = v.end();
for(; it!=end; ++it)
Helper<typename Vector::block_type>::writeBinary(s, *it);
}
};
template<class Field, int n>
struct Helper<Dune::FieldVector<Field,n>>
{
static void writeBinary(std::ostream& s, const Dune::FieldVector<Field,n>& v)
{
typedef typename Dune::FieldVector<Field,n> Vector;
typename Vector::const_iterator it = v.begin();
typename Vector::const_iterator end = v.end();
for(; it!=end; ++it)
s.write(reinterpret_cast<const char*>(&(*it)), sizeof(Field));
}
}; };
template <class Field, int n>
struct Helper<FieldVector<Field, n>> {
using Vector = FieldVector<Field, n>;
static void writeBinary(std::ostream& s, const Vector& v) {
for (auto&& vi : v)
s.write(reinterpret_cast<const char*>(&vi), sizeof(Field));
}
} // end namespace Generic } // end namespace Generic
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment