X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4ffdb64018ac4e4d76c57914d02f8547bf445683..4706252347b3a729552753c07ea41cc9ba9cd19d:/include/wx/log.h diff --git a/include/wx/log.h b/include/wx/log.h index 5d5f547e75..be0a245a49 100644 --- a/include/wx/log.h +++ b/include/wx/log.h @@ -4,7 +4,6 @@ // Author: Vadim Zeitlin // Modified by: // Created: 29/01/98 -// RCS-ID: $Id$ // Copyright: (c) 1998 Vadim Zeitlin // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -13,6 +12,7 @@ #define _WX_LOG_H_ #include "wx/defs.h" +#include "wx/cpp.h" // ---------------------------------------------------------------------------- // types @@ -29,7 +29,7 @@ typedef unsigned long wxLogLevel; #define wxTraceResAlloc 0x0004 // trace GDI resource allocation #define wxTraceRefCount 0x0008 // trace various ref counting operations - #ifdef __WXMSW__ + #ifdef __WINDOWS__ #define wxTraceOleCalls 0x0100 // OLE interface calls #endif @@ -57,11 +57,9 @@ class WXDLLIMPEXP_FWD_BASE wxObject; #include "wx/arrstr.h" -#ifndef __WXPALMOS5__ #ifndef __WXWINCE__ #include // for time_t #endif -#endif // ! __WXPALMOS5__ #include "wx/dynarray.h" #include "wx/hashmap.h" @@ -130,7 +128,7 @@ enum wxLogLevelValues #define wxTRACE_ResAlloc wxT("resalloc") // trace GDI resource allocation #define wxTRACE_RefCount wxT("refcount") // trace various ref counting operations -#ifdef __WXMSW__ +#ifdef __WINDOWS__ #define wxTRACE_OleCalls wxT("ole") // OLE interface calls #endif @@ -1332,28 +1330,42 @@ WXDLLIMPEXP_BASE const wxChar* wxSysErrorMsg(unsigned long nErrCode = 0); // following arguments are not even evaluated which is good as it avoids // unnecessary overhead) // -// Note: the strange if/else construct is needed to make the following code +// Note: the strange (because executing at most once) for() loop because we +// must arrange for wxDO_LOG() to be at the end of the macro and using a +// more natural "if (IsLevelEnabled()) wxDO_LOG()" would result in wrong +// behaviour for the following code ("else" would bind to the wrong "if"): // // if ( cond ) // wxLogError("!!!"); // else // ... // -// work as expected, without it the second "else" would match the "if" -// inside wxLogError(). Unfortunately code like +// See also #11829 for the problems with other simpler approaches, +// notably the need for two macros due to buggy __LINE__ in MSVC. // -// if ( cond ) -// wxLogError("!!!"); -// -// now provokes "suggest explicit braces to avoid ambiguous 'else'" -// warnings from g++ 4.3 and later with -Wparentheses on but they can be -// easily fixed by adding curly braces around wxLogError() and at least -// the code still does do the right thing. +// Note 2: Unfortunately we can't use the same solution for all compilers +// because the loop-based one results in problems with MSVC6 due to its +// wrong (pre-C++98) rules for the scope of the variables declared +// inside the loop, as this prevents us from using wxLogXXX() in switch +// statement clauses ("initialization of loopvar skipped by case"). So +// for now, i.e. while we still support VC6, use the previous solution +// for it (FIXME-VC6). +#ifdef __VISUALC6__ #define wxDO_LOG_IF_ENABLED(level) \ if ( !wxLog::IsLevelEnabled(wxLOG_##level, wxLOG_COMPONENT) ) \ {} \ else \ wxDO_LOG(level) +#else +#define wxDO_LOG_IF_ENABLED_HELPER(level, loopvar) \ + for ( bool loopvar = false; \ + !loopvar && wxLog::IsLevelEnabled(wxLOG_##level, wxLOG_COMPONENT); \ + loopvar = true ) \ + wxDO_LOG(level) + +#define wxDO_LOG_IF_ENABLED(level) \ + wxDO_LOG_IF_ENABLED_HELPER(level, wxMAKE_UNIQUE_NAME(wxlogcheck)) +#endif // wxLogFatalError() is special as it can't be disabled #define wxLogFatalError wxDO_LOG(FatalError) @@ -1439,7 +1451,7 @@ WXDLLIMPEXP_BASE const wxChar* wxSysErrorMsg(unsigned long nErrCode = 0); else \ wxMAKE_LOGGER(Status).MaybeStore(wxLOG_KEY_FRAME).Log - #define wxVLogStatus(format, argptr) \ + #define wxVLogStatus \ wxMAKE_LOGGER(Status).MaybeStore(wxLOG_KEY_FRAME).LogV #endif // wxUSE_GUI