From: Wolfgang Bangerth Date: Tue, 12 Sep 2017 12:37:58 +0000 (-0600) Subject: Some minor cleanups of LogStream. X-Git-Tag: v9.0.0-rc1~1094^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d16e98d788cfbd30411ce2ed0a233f273561ff6;p=dealii.git Some minor cleanups of LogStream. In particular, move some functions into the .cc file -- surely, these functions do not need to be 'inline' in the header file. --- diff --git a/include/deal.II/base/logstream.h b/include/deal.II/base/logstream.h index 8ac934ed91..a5eb65d40f 100644 --- a/include/deal.II/base/logstream.h +++ b/include/deal.II/base/logstream.h @@ -95,8 +95,8 @@ public: * continue, break, return, * throw, or by simply reaching the closing brace. In all of * these cases, it is not necessary to remember to pop the prefix manually - * using LogStream::pop. In this, it works just like the better known - * Threads::Mutex::ScopedLock class. + * using LogStream::pop(). In this, it works just like the better known + * std::unique_ptr and Threads::Mutex::ScopedLock classes. */ class Prefix { @@ -120,6 +120,10 @@ public: ~Prefix (); private: + /** + * A pointer to the LogStream object to which the prefix is + * applied. + */ SmartPointer stream; }; @@ -367,44 +371,6 @@ LogStream &operator<< (LogStream &log, const T &t) } -inline -std::ostringstream & -LogStream::get_stream() -{ - // see if we have already created this stream. if not, do so and - // set the default flags (why we set these flags is lost to - // history, but this is what we need to keep several hundred tests - // from producing different output) - // - // note that in all of this we need not worry about thread-safety - // because we operate on a thread-local object and by definition - // there can only be one access at a time - if (outstreams.get().get() == nullptr) - { - outstreams.get().reset (new std::ostringstream); - outstreams.get()->setf(std::ios::showpoint | std::ios::left); - } - - // then return the stream - return *outstreams.get(); -} - - - -inline -LogStream::Prefix::Prefix(const std::string &text, LogStream &s) - : - stream(&s) -{ - stream->push(text); -} - - -inline -LogStream::Prefix::~Prefix() -{ - stream->pop(); -} /** @@ -415,14 +381,6 @@ LogStream::Prefix::~Prefix() extern LogStream deallog; -inline -LogStream::Prefix::Prefix(const std::string &text) - : - stream(&deallog) -{ - stream->push(text); -} - DEAL_II_NAMESPACE_CLOSE diff --git a/source/base/logstream.cc b/source/base/logstream.cc index 3684c9de76..eea5f82edd 100644 --- a/source/base/logstream.cc +++ b/source/base/logstream.cc @@ -36,6 +36,34 @@ namespace LogStream deallog; + + +LogStream::Prefix::Prefix(const std::string &text) + : + stream(&deallog) +{ + stream->push(text); +} + + + +LogStream::Prefix::Prefix(const std::string &text, + LogStream &s) + : + stream(&s) +{ + stream->push(text); +} + + + +LogStream::Prefix::~Prefix() +{ + stream->pop(); +} + + + LogStream::LogStream() : std_out(&std::cout), @@ -49,6 +77,7 @@ LogStream::LogStream() } + LogStream::~LogStream() { // if there was anything left in the stream that is current to this @@ -200,6 +229,30 @@ LogStream::get_console() } + +std::ostringstream & +LogStream::get_stream() +{ + // see if we have already created this stream. if not, do so and + // set the default flags (why we set these flags is lost to + // history, but this is what we need to keep several hundred tests + // from producing different output) + // + // note that in all of this we need not worry about thread-safety + // because we operate on a thread-local object and by definition + // there can only be one access at a time + if (outstreams.get().get() == nullptr) + { + outstreams.get().reset (new std::ostringstream); + outstreams.get()->setf(std::ios::showpoint | std::ios::left); + } + + // then return the stream + return *outstreams.get(); +} + + + std::ostream & LogStream::get_file_stream() { @@ -210,6 +263,7 @@ LogStream::get_file_stream() } + bool LogStream::has_file() const { @@ -217,6 +271,7 @@ LogStream::has_file() const } + const std::string & LogStream::get_prefix() const { @@ -229,6 +284,7 @@ LogStream::get_prefix() const } + void LogStream::push (const std::string &text) { @@ -242,6 +298,7 @@ LogStream::push (const std::string &text) } + void LogStream::pop () { if (get_prefixes().size() > 0) @@ -249,6 +306,7 @@ void LogStream::pop () } + std::ios::fmtflags LogStream::flags(const std::ios::fmtflags f) { @@ -256,6 +314,7 @@ LogStream::flags(const std::ios::fmtflags f) } + std::streamsize LogStream::precision (const std::streamsize prec) { @@ -263,6 +322,7 @@ LogStream::precision (const std::streamsize prec) } + std::streamsize LogStream::width (const std::streamsize wide) { @@ -270,6 +330,7 @@ LogStream::width (const std::streamsize wide) } + unsigned int LogStream::depth_console (const unsigned int n) { @@ -280,6 +341,7 @@ LogStream::depth_console (const unsigned int n) } + unsigned int LogStream::depth_file (const unsigned int n) { @@ -290,6 +352,7 @@ LogStream::depth_file (const unsigned int n) } + bool LogStream::log_thread_id (const bool flag) { @@ -299,6 +362,8 @@ LogStream::log_thread_id (const bool flag) return h; } + + std::stack & LogStream::get_prefixes() const { @@ -332,6 +397,7 @@ LogStream::get_prefixes() const } + void LogStream::print_line_head() {