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

Add readBinary (import from dune-solvers).

parent 9c41e6a1
Branches
Tags
No related merge requests found
Pipeline #
...@@ -26,6 +26,12 @@ void writeBinary(std::ostream& s, const Vector& v) { ...@@ -26,6 +26,12 @@ void writeBinary(std::ostream& s, const Vector& v) {
Helper<Vector>::writeBinary(s, v); Helper<Vector>::writeBinary(s, v);
} }
//! Read vector from given stream
template <class Vector>
void readBinary(std::istream& s, Vector& v) {
Helper<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) {
...@@ -38,6 +44,10 @@ struct Helper { ...@@ -38,6 +44,10 @@ struct Helper {
Hybrid::forEach(v, [&s](auto&& vi) { Generic::writeBinary(s, vi); }); Hybrid::forEach(v, [&s](auto&& vi) { Generic::writeBinary(s, vi); });
} }
static void readBinary(std::istream& s, Vector& v) {
Hybrid::forEach(v, [&s](auto&& vi) { Generic::readBinary(s, vi); });
}
template <class BitVector> template <class BitVector>
static void truncate(Vector& v, const BitVector& tr) { static void truncate(Vector& v, const BitVector& tr) {
sparseRangeFor(v, [&tr](auto&& vi, auto&& i) { sparseRangeFor(v, [&tr](auto&& vi, auto&& i) {
...@@ -55,6 +65,11 @@ struct Helper<FieldVector<Field, n>> { ...@@ -55,6 +65,11 @@ struct Helper<FieldVector<Field, n>> {
s.write(reinterpret_cast<const char*>(&vi), sizeof(Field)); s.write(reinterpret_cast<const char*>(&vi), sizeof(Field));
} }
static void readBinary(std::ostream& s, Vector& v) {
for (auto&& vi : v)
s.write(reinterpret_cast<char*>(&vi), sizeof(Field));
}
template<class BitVector> template<class BitVector>
static void truncate(Vector& v, const BitVector& tr) { static void truncate(Vector& v, const BitVector& tr) {
for (auto it = v.begin(), end = v.end(); it != end; ++it) for (auto it = v.begin(), end = v.end(); it != end; ++it)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment