]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
release cerr on destruction
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 4 Feb 2004 13:01:04 +0000 (13:01 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 4 Feb 2004 13:01:04 +0000 (13:01 +0000)
git-svn-id: https://svn.dealii.org/trunk@8393 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/logstream.h
deal.II/base/source/log.cc

index aa7b22f155d5678522e17205f01b0e12963fc406..630524541683d20496fa9e26768462c7dc54b8c5 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -62,6 +62,11 @@ class LogStream
                                      * standard output stream to <tt>std::cerr</tt>.
                                      */
     LogStream ();
+
+                                    /**
+                                     * Destructor.
+                                     */
+    ~LogStream();
     
                                     /**
                                      * Enable output to a second
@@ -89,6 +94,10 @@ class LogStream
 
                                     /**
                                      * Reroutes cerr to LogStream.
+                                     * Works as a switch, turning
+                                     * logging of <tt>cerr</tt> on
+                                     * and of alternatingly with
+                                     * every call.
                                      */
     void log_cerr ();
     
@@ -308,6 +317,12 @@ class LogStream
                                      */
     template <typename T>
     void print (const T &t);
+                                    /**
+                                     * Original buffer of
+                                     * <tt>cerr</tt> in order to
+                                     * leave this class properly.
+                                     */
+    std::ostream::__streambuf_type* old_cerr;
 };
 
 
index 41b0ca5fb8173e7ad8ab6ef2e9eb7c81575555a0..6e5e135dd555f4af018d3f806a8679b124c35208 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -50,13 +50,20 @@ LogStream::LogStream()
                std_out(&std::cerr), file(0), was_endl(true),
                std_depth(10000), file_depth(10000),
                print_utime(false), diff_utime(false),
-               last_time (0.)
+               last_time (0.), old_cerr(0)
 {
   prefixes.push("DEAL:");
   std_out->setf(std::ios::showpoint | std::ios::left);
 }
 
 
+LogStream::~LogStream()
+{
+  if (old_cerr)
+    std::cerr.rdbuf(old_cerr);
+}
+
+
 void
 LogStream::attach(std::ostream& o)
 {
@@ -74,7 +81,13 @@ void LogStream::detach ()
 
 void LogStream::log_cerr ()
 {
-  std::cerr.rdbuf(file->rdbuf());
+  if (old_cerr == 0)
+    {
+      old_cerr = std::cerr.rdbuf(file->rdbuf());
+    } else {
+      std::cerr.rdbuf(old_cerr);
+      old_cerr = 0;
+    }
 }
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.