X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fdebug%2Flogstream.hxx;h=c2a5edc5b6d7110b5fc68462ae75f602c8384e78;hb=2e71b64de1d937e2b7c34dd4a2365be455d0b82a;hp=cb712ae4341a6563585abe49d422d995166d10b7;hpb=2d37c0aa426c3d2807f43e78777c21445282ba3a;p=simgear.git diff --git a/simgear/debug/logstream.hxx b/simgear/debug/logstream.hxx index cb712ae4..c2a5edc5 100644 --- a/simgear/debug/logstream.hxx +++ b/simgear/debug/logstream.hxx @@ -31,22 +31,14 @@ # 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 @@ -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,10 +294,12 @@ 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_ORIGIN __FILE__ ":" SG_STRINGIZE(__LINE__)