]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Use compiler capabilities better than before on the LogStream class. We can now use...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 19 Apr 1999 19:53:41 +0000 (19:53 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 19 Apr 1999 19:53:41 +0000 (19:53 +0000)
git-svn-id: https://svn.dealii.org/trunk@1181 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 338f8617c26486e55722ae5d5e8eaa22d6064e58..90e94dd4cd91175f551f5d5ec191f10584fd9f47 100644 (file)
@@ -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 <typename T>
+    LogStream & operator << (const T &t);
     
                                     /**
                                      * Output a function. This really is not
@@ -211,39 +211,32 @@ LogStream::push (const string& text)
 
 
 
-template <class T>
-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 <class T>
 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.
index e8ecafae514de026fb6063dc0aa071290380c608..ce3d0d1ce5685ae0bb8efd17c8a6dc210e2377c0 100644 (file)
@@ -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 &))
 {

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.