X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fdebug%2Flogstream.hxx;h=d3649a4a21b3cf5912dd20778d9daf39abb37b5b;hb=9f88b077ee5294c4ad898016b7d66682466bbafb;hp=a9dafa6d6d323b87e841be3c035c1a4b56e1413e;hpb=d219c5c4c613e4f36d8ff1ce8af674fc96dcb543;p=simgear.git diff --git a/simgear/debug/logstream.hxx b/simgear/debug/logstream.hxx index a9dafa6d..d3649a4a 100644 --- a/simgear/debug/logstream.hxx +++ b/simgear/debug/logstream.hxx @@ -27,26 +27,18 @@ #include -#ifdef _MSC_VER +#ifdef _WIN32 # include #endif -#ifdef SG_HAVE_STD_INCLUDES -# include -# include -#else -# include -# include -#endif +#include +#include +#include #include -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 traits_type; - typedef char_traits::int_type int_type; - // typedef char_traits::pos_type pos_type; - // typedef char_traits::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 @@ -136,7 +123,7 @@ public: */ void set_sb( std::streambuf* sb ); -#ifdef _MSC_VER +#ifdef _WIN32 static void has_no_console() { has_console = false; } #endif @@ -155,7 +142,7 @@ private: static std::streambuf* sbuf; static bool logging_enabled; -#ifdef _MSC_VER +#ifdef _WIN32 static bool has_console; #endif static sgDebugClass logClass; @@ -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,10 +167,16 @@ 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 ) { -#ifdef _MSC_VER +#ifdef _WIN32 if ( logging_enabled ) { if ( !has_console ) { AllocConsole(); @@ -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