]> git.mxchange.org Git - simgear.git/blobdiff - simgear/debug/logstream.hxx
remove CopyPolicy from ModelRegistry
[simgear.git] / simgear / debug / logstream.hxx
index a9dafa6d6d323b87e841be3c035c1a4b56e1413e..c2a5edc5b6d7110b5fc68462ae75f602c8384e78 100644 (file)
 #  include <windows.h>
 #endif
 
-#ifdef SG_HAVE_STD_INCLUDES
-# include <streambuf>
-# include <ostream>
-#else
-# include <iostream.h>
-# include <simgear/sg_traits.hxx>
-#endif
+#include <streambuf>
+#include <ostream>
+#include <cstdio>
 
 #include <simgear/debug/debug_types.h>
 
-SG_USING_STD(streambuf);
-SG_USING_STD(ostream);
-
-#ifdef __MWERKS__
-SG_USING_STD(iostream);
-#endif
+using std::streambuf;
+using std::ostream;
 
 //
 // TODO:
@@ -68,13 +60,6 @@ class logbuf : public std::streambuf
 #endif
 {
 public:
-
-#ifndef SG_HAVE_STD_INCLUDES
-    typedef char_traits<char>           traits_type;
-    typedef char_traits<char>::int_type int_type;
-    // typedef char_traits<char>::pos_type pos_type;
-    // typedef char_traits<char>::off_type off_type;
-#endif
     // logbuf( streambuf* sb ) : sbuf(sb) {}
     /** Constructor */
     logbuf();
@@ -94,6 +79,8 @@ public:
      */
     void set_log_state( sgDebugClass c, sgDebugPriority p );
 
+    bool would_log( sgDebugClass c, sgDebugPriority p ) const;
+
     /**
      * Set the global logging level.
      * @param c debug class
@@ -171,11 +158,7 @@ private:
 inline int
 logbuf::sync()
 {
-#ifdef SG_HAVE_STD_INCLUDES
        return sbuf->pubsync();
-#else
-       return sbuf->sync();
-#endif
 }
 
 inline void
@@ -184,6 +167,12 @@ logbuf::set_log_state( sgDebugClass c, sgDebugPriority p )
     logging_enabled = ((c & logClass) != 0 && p >= logPriority);
 }
 
+inline bool
+logbuf::would_log( sgDebugClass c, sgDebugPriority p ) const
+{
+    return ((c & logClass) != 0 && p >= logPriority);
+}
+
 inline logbuf::int_type
 logbuf::overflow( int c )
 {
@@ -260,15 +249,20 @@ public:
      */
     void setLogLevels( sgDebugClass c, sgDebugPriority p );
 
+    bool would_log(  sgDebugClass c, sgDebugPriority p ) const
+    {
+        return lbuf.would_log( c, p );
+    };
+
     /**
      * Output operator to capture the debug level and priority of a message.
      * @param l log level
      */
     inline std::ostream& operator<< ( const loglevel& l );
     friend logstream& sglog();
+    static logstream *initGlobalLogstream();
 protected:
     static logstream *global_logstream;
-    static void initGlobalLogstream();
 };
 
 inline std::ostream&
@@ -288,10 +282,7 @@ logstream::operator<< ( const loglevel& l )
 inline logstream&
 sglog()
 {
-  if (logstream::global_logstream == NULL) {
-      logstream::initGlobalLogstream();
-  }
-  return *logstream::global_logstream;
+    return *logstream::initGlobalLogstream();
 }
 
 
@@ -303,15 +294,15 @@ sglog()
  */
 #ifdef FG_NDEBUG
 # define SG_LOG(C,P,M)
-#elif defined( __MWERKS__ )
-# define SG_LOG(C,P,M) ::sglog() << ::loglevel(C,P) << M << std::endl
 #else
-# define SG_LOG(C,P,M) sglog() << loglevel(C,P) << M << std::endl
+# define SG_LOG(C,P,M) do {                     \
+       logstream& __tmplogstreamref(sglog());                      \
+       if(__tmplogstreamref.would_log(C,P)) {                      \
+        __tmplogstreamref << loglevel(C,P) << M << std::endl; } \
+       } while(0)
 #endif
 
-#define SG_STRINGIFY(x) #x
-#define SG_TOSTRING(x) SG_STRINGIFY(x)
-#define SG_ORIGIN __FILE__ ":" SG_TOSTRING(__LINE__)
+#define SG_ORIGIN __FILE__ ":" SG_STRINGIZE(__LINE__)
 
 #endif // _LOGSTREAM_H