From 512a5e332f69ff3eb659d35b508876e8629277cb Mon Sep 17 00:00:00 2001 From: wolf Date: Mon, 19 Apr 1999 19:53:41 +0000 Subject: [PATCH] Use compiler capabilities better than before on the LogStream class. We can now use member templates and make the local variables of this class private, as should be, which was not possible before, however. git-svn-id: https://svn.dealii.org/trunk@1181 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/logstream.h | 66 ++++++++++++--------------- deal.II/base/source/log.cc | 14 ------ 2 files changed, 29 insertions(+), 51 deletions(-) diff --git a/deal.II/base/include/base/logstream.h b/deal.II/base/include/base/logstream.h index 338f8617c2..90e94dd4cd 100644 --- a/deal.II/base/include/base/logstream.h +++ b/deal.II/base/include/base/logstream.h @@ -37,8 +37,7 @@ */ class LogStream { -// private: - public: + private: /** * Stack of strings which are printed @@ -94,7 +93,7 @@ class LogStream * prefixes for output to a file. */ unsigned int file_depth; - + public: /** * Standard constructor, since we @@ -159,10 +158,11 @@ class LogStream void depth_file (unsigned int n); /** - * Output a character constant through + * Output a constant something through * this stream. */ - LogStream & operator << (const char *); + template + LogStream & operator << (const T &t); /** * Output a function. This really is not @@ -211,39 +211,32 @@ LogStream::push (const string& text) -template -inline void -writestuff(LogStream& s, const T& t) -{ - // print the object #t# to each of the - // two streams, if necessary - if (s.prefixes.size() <= s.std_depth) - *(s.std_out) << t; - - if (s.file && (s.prefixes.size() <= s.file_depth)) - *(s.file) << t; -}; - - - - template inline LogStream& -operator << (LogStream& s, const T& t) +LogStream::operator << (const T& t) { // if the previous command was an // #endl#, print the topmost prefix // and a colon - if (s.was_endl) + if (was_endl) { - writestuff(s, s.prefixes.top()); - writestuff(s,':'); - s.was_endl = false; + if (prefixes.size() <= std_depth) + *std_out << prefixes.top() << ':'; + + if (file && (prefixes.size() <= file_depth)) + *file << prefixes.top() << ':'; + + was_endl = false; }; // print the rest of the message - writestuff(s,t); - return s; + if (prefixes.size() <= std_depth) + *std_out << t; + + if (file && (prefixes.size() <= file_depth)) + *file << t; + + return *this; } @@ -261,16 +254,15 @@ operator << (LogStream& s, const T& t) */ inline void endl(LogStream& s) { - // there seems to be no proper way to - // pass a pointer to an overloaded - // function through a template parameter, - // since the compiler can't know which of - // the functions it is; do the overload - // resolution by hand like this: - ostream& (*p) (ostream &) = &endl; - writestuff (s, p); + if (s.prefixes.size() <= s.std_depth) + *s.std_out << endl; + + if (s.file && (s.prefixes.size() <= s.file_depth)) + *s.file << endl; + s.was_endl = true; -} +}; + /** * The standard log object of DEAL. diff --git a/deal.II/base/source/log.cc b/deal.II/base/source/log.cc index e8ecafae51..ce3d0d1ce5 100644 --- a/deal.II/base/source/log.cc +++ b/deal.II/base/source/log.cc @@ -56,20 +56,6 @@ void LogStream::depth_file(unsigned n) -LogStream& LogStream::operator << (const char* c) -{ - if (was_endl) - { - writestuff(*this, prefixes.top()); - writestuff(*this, ':'); - } - was_endl = false; - writestuff (*this, c); - return *this; -} - - - LogStream& LogStream::operator << (void (f)(LogStream &)) { -- 2.39.5