From: kanschat Date: Tue, 16 Nov 2010 15:16:53 +0000 (+0000) Subject: add LogStream output for Vector X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d9f0ad4c1649f8726b7f3ac0525ed19a1a90b8a;p=dealii-svn.git add LogStream output for Vector git-svn-id: https://svn.dealii.org/trunk@22751 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/lac/vector.h b/deal.II/include/deal.II/lac/vector.h index f21cb7b5cf..4bf499550e 100644 --- a/deal.II/include/deal.II/lac/vector.h +++ b/deal.II/include/deal.II/lac/vector.h @@ -15,12 +15,14 @@ #include +#include #include #include #include #include #include +#include #include #include @@ -877,10 +879,26 @@ class Vector : public Subscriptor * are printed on a separate line * each. */ - void print (std::ostream &out, - const unsigned int precision = 3, - const bool scientific = true, - const bool across = true) const; + void print (std::ostream& out, + const unsigned int precision = 3, + const bool scientific = true, + const bool across = true) const; + + /** + * Print to a + * LogStream. width is + * used as argument to the + * std::setw manipulator, if + * printing across. If @p + * across is @p true then the + * vector is printed in a line, + * while if @p false then the + * elements are printed on a + * separate line each. + */ + void print (LogStream& out, + const unsigned int width = 6, + const bool across = true) const; /** * Write the vector en bloc to a @@ -1422,7 +1440,6 @@ Vector::swap (Vector &v) } - #endif @@ -1446,6 +1463,31 @@ void swap (Vector &u, Vector &v) u.swap (v); } + +/** + * Output operator writing a vector to a stream. + */ +template +inline +std::ostream& +operator << (std::ostream& os, const Vector& v) +{ + v.print(os); + return os; +} + +/** + * Output operator writing a vector to a LogStream. + */ +template +inline +LogStream& +operator << (LogStream& os, const Vector& v) +{ + v.print(os); + return os; +} + /*@}*/ DEAL_II_NAMESPACE_CLOSE diff --git a/deal.II/include/deal.II/lac/vector.templates.h b/deal.II/include/deal.II/lac/vector.templates.h index 858b78cdbd..7d0985e74d 100644 --- a/deal.II/include/deal.II/lac/vector.templates.h +++ b/deal.II/include/deal.II/lac/vector.templates.h @@ -32,6 +32,7 @@ #include #include #include +#include DEAL_II_NAMESPACE_OPEN @@ -1143,6 +1144,22 @@ void Vector::print (std::ostream &out, +template +void +Vector::print (LogStream& out, const unsigned int width, const bool across) const +{ + Assert (vec_size!=0, ExcEmptyObject()); + + if (across) + for (unsigned int i=0; i void Vector::block_write (std::ostream &out) const {