]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Introduce LogStream::Prefix
authorkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 9 Dec 2011 20:00:35 +0000 (20:00 +0000)
committerkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 9 Dec 2011 20:00:35 +0000 (20:00 +0000)
git-svn-id: https://svn.dealii.org/trunk@24812 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/include/deal.II/base/logstream.h

index fdcc0f7543c3bf45e1117b7c9527763766fff2ce..942679a5601aa5b4efc0406e74ba4595a70ac78c 100644 (file)
@@ -74,6 +74,12 @@ enabled due to a missing include file in file
 
 <ol>
 
+<li> Improved: Objects of the type LogStream::Prefix can now be used
+as a safe implementation of the push and pop mechanism for log
+prefices.
+<br>
+(Guido Kanschat, 2011/12/09)
+
 <li> New: IndexSet::add_indices(IndexSet).
 <br>
 (Timo Heister, 2011/12/09)
index ae631d08b79909ae8d950706b3d6e2a90ed0d9ee..78ddcf06200f1adc76f928bf0d08d5e592b26712 100644 (file)
@@ -13,6 +13,7 @@
 #define __deal2__logstream_h
 
 #include <deal.II/base/config.h>
+#include <deal.II/base/smartpointer.h>
 #include <deal.II/base/exceptions.h>
 #include <deal.II/base/std_cxx1x/shared_ptr.h>
 
@@ -48,10 +49,10 @@ DEAL_II_NAMESPACE_OPEN
  * <li> <tt>deallog.attach(std::ostream)</tt>: write logging information into a file.
  * <li> <tt>deallog.depth_console(n)</tt>: restrict output on screen to outer loops.
  * <li> Before entering a new phase of your program, e.g. a new loop,
- *       <tt>deallog.push("loopname")</tt>.
+ *       <tt>LogStream::Prefix p("loopname")</tt>.
  * <li> <tt>deallog << anything << std::endl;</tt> to write logging information
  *       (Usage of <tt>std::endl</tt> is mandatory!).
- * <li> <tt>deallog.pop()</tt> when leaving that stage entered with <tt>push</tt>.
+ * <li> Destructor of the prefix will pop the prefix text from the stack.
  * </ul>
  *
  * <h3>LogStream and reproducible regression test output</h3>
@@ -82,9 +83,53 @@ DEAL_II_NAMESPACE_OPEN
  * @ingroup textoutput
  * @author Guido Kanschat, Wolfgang Bangerth, 1999, 2003, 2011
  */
-class LogStream
+class LogStream : public Subscriptor
 {
   public:
+                                    /**
+                                     * A subclass allowing for the
+                                     * safe generation and removal of
+                                     * prefices.
+                                     *
+                                     * Somewhere at the beginning of
+                                     * a block, create one of these
+                                     * objects, and it will appear as
+                                     * a prefix in LogStream output
+                                     * like #deallog. At the end of
+                                     * the block, the prefix will
+                                     * automatically be removed, when
+                                     * this object is destroyed.
+                                     */
+    class Prefix
+    {
+      public:
+                                        /**
+                                         * Set a new prefix for
+                                         * #deallog, which will be
+                                         * removed when the variable
+                                         * is destroyed .
+                                         */
+       Prefix(const std::string& text);
+       
+                                        /**
+                                         * Set a new prefix for the
+                                         * given stream, which will
+                                         * be removed when the
+                                         * variable is destroyed .
+                                         */
+       Prefix(const std::string& text, LogStream& stream);
+
+                                        /**
+                                         * Remove the prefix
+                                         * associated with this
+                                         * variable.
+                                         */
+       ~Prefix ();
+       
+      private:
+       SmartPointer<LogStream,LogStream::Prefix> stream;
+    };
+    
                                     /**
                                      * Standard constructor, since we
                                      * intend to provide an object
@@ -163,6 +208,8 @@ class LogStream
     const std::string& get_prefix () const;
     
                                     /**
+                                     * @deprecated Use Prefix instead
+                                     *
                                      * Push another prefix on the
                                      * stack. Prefixes are
                                      * automatically separated by a
@@ -172,6 +219,8 @@ class LogStream
     void push (const std::string& text);
         
                                     /**
+                                     * @deprecated Use Prefix instead
+                                     *
                                      * Remove the last prefix.
                                      */
     void pop ();
@@ -649,6 +698,22 @@ LogStream::operator<< (const float t)
 }
 
 
+inline
+LogStream::Prefix::Prefix(const std::string& text, LogStream& s)
+               :
+               stream(&s)
+{
+  stream->push(text);
+}
+
+
+inline
+LogStream::Prefix::~Prefix()
+{
+  stream->pop();
+}
+
+
 
 /**
  * The standard log object of DEAL.
@@ -657,6 +722,17 @@ LogStream::operator<< (const float t)
  */
 extern LogStream deallog;
 
+
+inline
+LogStream::Prefix::Prefix(const std::string& text)
+               :
+               stream(&deallog)
+{
+  stream->push(text);
+}
+
+
+
 DEAL_II_NAMESPACE_CLOSE
 
 #endif

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.