From be772b23250e8f37cd355b9174fa2a5e19852d6a Mon Sep 17 00:00:00 2001 From: Rene Milk <koshi@springlobby.info> Date: Sat, 17 Oct 2009 18:50:54 +0200 Subject: [PATCH] derive logger from std::ostream --- stuff/logging.hh | 2 +- stuff/misc.hh | 11 ++++------- stuff/printing.hh | 38 +++++++++++++++++++------------------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/stuff/logging.hh b/stuff/logging.hh index 3f6f80f18..4ebe22bae 100644 --- a/stuff/logging.hh +++ b/stuff/logging.hh @@ -108,7 +108,7 @@ public: bool is_suspended_; }; - class LogStream //: virtual public std::ostream + class LogStream : virtual public std::ostream { protected: LogFlags loglevel_; diff --git a/stuff/misc.hh b/stuff/misc.hh index 9be68201f..5ebfc5de4 100644 --- a/stuff/misc.hh +++ b/stuff/misc.hh @@ -753,8 +753,7 @@ public: } } - template <class Stream> - void output(Stream& stream) + void output(std::ostream& stream) { stream << "min: " << min_ << " max: " << max_ << " avg: " << avg_ << std::endl; } @@ -766,8 +765,7 @@ protected: MinMaxAvg(const ThisType& other); }; -template <class Stream> -void fileToStreamFiltered(Stream& stream, std::string filename, std::string filter) +void fileToStreamFiltered(std::ostream& stream, std::string filename, std::string filter) { std::ifstream file(filename.c_str(), std::ifstream::in); ASSERT_EXCEPTION(file.good(), filename.c_str()) @@ -780,11 +778,10 @@ void fileToStreamFiltered(Stream& stream, std::string filename, std::string filt file.close(); } -template <class Stream> -void meminfo(Stream& stream) +void meminfo(std::ostream& stream) { stream << "Memory info: \n"; - stream.Resume(); + // stream.Resume(); pid_t pid = getpid(); std::stringstream filename; filename << "/proc/" << pid << "/status"; diff --git a/stuff/printing.hh b/stuff/printing.hh index f1f9896ef..f7fc909a1 100644 --- a/stuff/printing.hh +++ b/stuff/printing.hh @@ -26,8 +26,8 @@ namespace Stuff { * \param[opt] prefix * prefix to be printed before every line **/ -template <class T, class stream> -void printFieldVector(T& arg, std::string name, stream& out, std::string prefix = "") +template <class T> +void printFieldVector(T& arg, std::string name, std::ostream& out, std::string prefix = "") { out << "\n" << prefix << "printing " << name << " (Dune::FieldVector)" << std::endl; typedef typename T::ConstIterator IteratorType; @@ -55,8 +55,8 @@ void printFieldVector(T& arg, std::string name, stream& out, std::string prefix * \param[opt] prefix * prefix to be printed before every line **/ -template <class T, class stream> -void printFieldMatrix(T& arg, std::string name, stream& out, std::string prefix = "") +template <class T> +void printFieldMatrix(T& arg, std::string name, std::ostream& out, std::string prefix = "") { out << "\n" << prefix << "printing " << name << " (Dune::FieldMatrix)"; typedef typename T::ConstRowIterator RowIteratorType; @@ -73,8 +73,8 @@ void printFieldMatrix(T& arg, std::string name, stream& out, std::string prefix } } -template <class T, class stream> -void printSparseRowMatrixMatlabStyle(const T& arg, const std::string name, stream& out) +template <class T> +void printSparseRowMatrixMatlabStyle(const T& arg, const std::string name, std::ostream& out) { out << "\n" << name << " = [ " << std::endl; for (int row = 0; row < arg.rows(); row++) { @@ -86,8 +86,8 @@ void printSparseRowMatrixMatlabStyle(const T& arg, const std::string name, strea out << "];" << std::endl; } -template <class T, class stream> -void printDiscreteFunctionMatlabStyle(const T& arg, const std::string name, stream& out) +template <class T> +void printDiscreteFunctionMatlabStyle(const T& arg, const std::string name, std::ostream& out) { out << "\n" << name << " = [ " << std::endl; typedef typename T::ConstDofIteratorType ConstDofIteratorType; @@ -99,8 +99,8 @@ void printDiscreteFunctionMatlabStyle(const T& arg, const std::string name, stre out << "];" << std::endl; } -template <class T, class stream> -void printDoubleVectorMatlabStyle(const T* arg, const int size, const std::string name, stream& out) +template <class T> +void printDoubleVectorMatlabStyle(const T* arg, const int size, const std::string name, std::ostream& out) { out << "\n" << name << " = [ " << std::endl; for (unsigned int i = 0; i < size; i++) { @@ -111,8 +111,8 @@ void printDoubleVectorMatlabStyle(const T* arg, const int size, const std::strin } -template <class Stream, class Type> -void printDoubleVec(Stream& stream, const Type* vec, const unsigned int N) +template <class Type> +void printDoubleVec(std::ostream& stream, const Type* vec, const unsigned int N) { stream << "\n [ " << std::setw(5); for (unsigned int i = 0; i < N; ++i) @@ -121,8 +121,8 @@ void printDoubleVec(Stream& stream, const Type* vec, const unsigned int N) stream << " ] " << std::endl; } -template <class Stream, class DiscFunc> -void oneLinePrint(Stream& stream, const DiscFunc& func) +template <class DiscFunc> +void oneLinePrint(std::ostream& stream, const DiscFunc& func) { typedef typename DiscFunc::ConstDofIteratorType DofIteratorType; DofIteratorType it = func.dbegin(); @@ -136,11 +136,11 @@ void oneLinePrint(Stream& stream, const DiscFunc& func) } -template <class GlobalMatrix, class Stream> +template <class GlobalMatrix> class LocalMatrixPrintFunctor { public: - LocalMatrixPrintFunctor(const GlobalMatrix& m, Stream& stream, const std::string name) + LocalMatrixPrintFunctor(const GlobalMatrix& m, std::ostream& stream, const std::string name) : matrix_(m) , stream_(stream) , name_(name) @@ -175,12 +175,12 @@ public: private: const GlobalMatrix& matrix_; - Stream& stream_; + std::ostream& stream_; const std::string name_; }; -template <class Stream, class Function> -void printFunctionMinMax(Stream& stream, const Function& func) +template <class Function> +void printFunctionMinMax(std::ostream& stream, const Function& func) { double min = 0.0; double max = 0.0; -- GitLab