changed wxLog::OnLog(String) to take wxString instead of wxChar* to avoid unnecessary conversions; added compatibility code so that user code overriding these with char* or wchar_t* argument continues to work

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46318 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2007-06-04 10:04:05 +00:00
parent f8bcb37d99
commit 5a20d2ced0
5 changed files with 77 additions and 43 deletions

View File

@@ -201,7 +201,7 @@ Returns the currently allowed list of string trace masks.
\membersection{wxLog::OnLog}\label{wxlogonlog} \membersection{wxLog::OnLog}\label{wxlogonlog}
\func{static void}{OnLog}{\param{wxLogLevel }{ level}, \param{const char * }{ message}} \func{static void}{OnLog}{\param{wxLogLevel }{ level}, \param{const wxString\& }{ message}}
Forwards the message at specified level to the {\it DoLog()} function of the Forwards the message at specified level to the {\it DoLog()} function of the
active log target if there is any, does nothing otherwise. active log target if there is any, does nothing otherwise.
@@ -250,7 +250,7 @@ flushed soon.
\membersection{wxLog::DoLog}\label{wxlogdolog} \membersection{wxLog::DoLog}\label{wxlogdolog}
\func{virtual void}{DoLog}{\param{wxLogLevel }{level}, \param{const wxChar }{*msg}, \param{time\_t }{timestamp}} \func{virtual void}{DoLog}{\param{wxLogLevel }{level}, \param{const wxString\& }{msg}, \param{time\_t }{timestamp}}
Called to process the message of the specified severity. {\it msg} is the text Called to process the message of the specified severity. {\it msg} is the text
of the message as specified in the call of {\it wxLogXXX()} function which of the message as specified in the call of {\it wxLogXXX()} function which
@@ -262,7 +262,7 @@ corresponding to the log level and then calls
\membersection{wxLog::DoLogString}\label{wxlogdologstring} \membersection{wxLog::DoLogString}\label{wxlogdologstring}
\func{virtual void}{DoLogString}{\param{const wxChar }{*msg}, \param{time\_t }{timestamp}} \func{virtual void}{DoLogString}{\param{const wxString\& }{msg}, \param{time\_t }{timestamp}}
Called to log the specified string. The timestamp is already included in the Called to log the specified string. The timestamp is already included in the
string but still passed to this function. string but still passed to this function.
@@ -368,7 +368,7 @@ for details.
\membersection{wxLog::IsAllowedTraceMask}\label{wxlogisallowedtracemask} \membersection{wxLog::IsAllowedTraceMask}\label{wxlogisallowedtracemask}
\func{static bool}{IsAllowedTraceMask}{\param{const wxChar *}{mask}} \func{static bool}{IsAllowedTraceMask}{\param{const wxString\& }{mask}}
Returns true if the {\it mask} is one of allowed masks for Returns true if the {\it mask} is one of allowed masks for
\helpref{wxLogTrace}{wxlogtrace}. \helpref{wxLogTrace}{wxlogtrace}.

View File

@@ -30,7 +30,7 @@ public:
protected: protected:
// implement sink function // implement sink function
virtual void DoLogString(const wxChar *szString, time_t t); virtual void DoLogString(const wxString& szString, time_t t);
private: private:
// the control we use // the control we use
@@ -57,7 +57,7 @@ public:
virtual void Flush(); virtual void Flush();
protected: protected:
virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t); virtual void DoLog(wxLogLevel level, const wxString& szString, time_t t);
// empty everything // empty everything
void Clear(); void Clear();
@@ -112,8 +112,8 @@ public:
virtual void OnFrameDelete(wxFrame *frame); virtual void OnFrameDelete(wxFrame *frame);
protected: protected:
virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t); virtual void DoLog(wxLogLevel level, const wxString& szString, time_t t);
virtual void DoLogString(const wxChar *szString, time_t t); virtual void DoLogString(const wxString& szString, time_t t);
private: private:
wxLogFrame *m_pLogFrame; // the log frame wxLogFrame *m_pLogFrame; // the log frame

View File

@@ -133,7 +133,7 @@ public:
// static sink function - see DoLog() for function to overload in the // static sink function - see DoLog() for function to overload in the
// derived classes // derived classes
static void OnLog(wxLogLevel level, const wxChar *szString, time_t t); static void OnLog(wxLogLevel level, const wxString& szString, time_t t);
// message buffering // message buffering
@@ -223,7 +223,7 @@ public:
static wxTraceMask GetTraceMask() { return ms_ulTraceMask; } static wxTraceMask GetTraceMask() { return ms_ulTraceMask; }
// is this trace mask in the list? // is this trace mask in the list?
static bool IsAllowedTraceMask(const wxChar *mask); static bool IsAllowedTraceMask(const wxString& mask);
// return the current loglevel limit // return the current loglevel limit
static wxLogLevel GetLogLevel() { return ms_logLevel; } static wxLogLevel GetLogLevel() { return ms_logLevel; }
@@ -255,11 +255,28 @@ protected:
// default DoLog() prepends the time stamp and a prefix corresponding // default DoLog() prepends the time stamp and a prefix corresponding
// to the message to szString and then passes it to DoLogString() // to the message to szString and then passes it to DoLogString()
virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t); virtual void DoLog(wxLogLevel level, const wxString& szString, time_t t);
#if WXWIN_COMPATIBILITY_2_8
// these shouldn't be used by new code
virtual void DoLog(wxLogLevel WXUNUSED(level),
const char *WXUNUSED(szString), time_t WXUNUSED(t)) {}
virtual void DoLog(wxLogLevel WXUNUSED(level),
const wchar_t *WXUNUSED(szString), time_t WXUNUSED(t)) {}
#endif
void LogString(const wxString& szString, time_t t)
{ DoLogString(szString, t); }
// default DoLogString does nothing but is not pure virtual because if // default DoLogString does nothing but is not pure virtual because if
// you override DoLog() you might not need it at all // you override DoLog() you might not need it at all
virtual void DoLogString(const wxChar *szString, time_t t); virtual void DoLogString(const wxString& szString, time_t t);
#if WXWIN_COMPATIBILITY_2_8
// these shouldn't be used by new code
virtual void DoLogString(const char *WXUNUSED(szString),
time_t WXUNUSED(t)) {}
virtual void DoLogString(const wchar_t *WXUNUSED(szString),
time_t WXUNUSED(t)) {}
#endif
// log a line containing the number of times the previous message was // log a line containing the number of times the previous message was
// repeated // repeated
@@ -313,8 +330,8 @@ public:
virtual void Flush(); virtual void Flush();
protected: protected:
virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t); virtual void DoLog(wxLogLevel level, const wxString& szString, time_t t);
virtual void DoLogString(const wxChar *szString, time_t t); virtual void DoLogString(const wxString& szString, time_t t);
private: private:
wxString m_str; wxString m_str;
@@ -332,7 +349,7 @@ public:
protected: protected:
// implement sink function // implement sink function
virtual void DoLogString(const wxChar *szString, time_t t); virtual void DoLogString(const wxString& szString, time_t t);
FILE *m_fp; FILE *m_fp;
@@ -350,7 +367,7 @@ public:
protected: protected:
// implement sink function // implement sink function
virtual void DoLogString(const wxChar *szString, time_t t); virtual void DoLogString(const wxString& szString, time_t t);
// using ptr here to avoid including <iostream.h> from this file // using ptr here to avoid including <iostream.h> from this file
wxSTD ostream *m_ostr; wxSTD ostream *m_ostr;
@@ -421,7 +438,7 @@ public:
protected: protected:
// pass the chain to the old logger if needed // pass the chain to the old logger if needed
virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t); virtual void DoLog(wxLogLevel level, const wxString& szString, time_t t);
private: private:
// the current log target // the current log target

View File

@@ -475,7 +475,7 @@ unsigned wxLog::DoLogNumberOfRepeats()
#endif #endif
ms_prevCounter = 0; ms_prevCounter = 0;
ms_prevString.clear(); ms_prevString.clear();
pLogger->DoLog(ms_prevLevel, msg.c_str(), ms_prevTimeStamp); pLogger->DoLog(ms_prevLevel, msg, ms_prevTimeStamp);
} }
return retval; return retval;
} }
@@ -491,7 +491,7 @@ wxLog::~wxLog()
} }
/* static */ /* static */
void wxLog::OnLog(wxLogLevel level, const wxChar *szString, time_t t) void wxLog::OnLog(wxLogLevel level, const wxString& szString, time_t t)
{ {
if ( IsEnabled() && ms_logLevel >= level ) if ( IsEnabled() && ms_logLevel >= level )
{ {
@@ -611,12 +611,19 @@ void wxLog::TimeStamp(wxString *str)
#endif // wxUSE_DATETIME #endif // wxUSE_DATETIME
} }
void wxLog::DoLog(wxLogLevel level, const wxChar *szString, time_t t) void wxLog::DoLog(wxLogLevel level, const wxString& szString, time_t t)
{ {
#if WXWIN_COMPATIBILITY_2_8
// DoLog() signature changed since 2.8, so we call the old versions here
// so that existing custom log classes still work:
DoLog(level, (const char*)szString.mb_str(), t);
DoLog(level, (const wchar_t*)szString.wc_str(), t);
#endif
switch ( level ) { switch ( level ) {
case wxLOG_FatalError: case wxLOG_FatalError:
DoLogString(wxString(_("Fatal error: ")) + szString, t); LogString(_("Fatal error: ") + szString, t);
DoLogString(_("Program aborted."), t); LogString(_("Program aborted."), t);
Flush(); Flush();
#ifdef __WXWINCE__ #ifdef __WXWINCE__
ExitThread(3); ExitThread(3);
@@ -626,11 +633,11 @@ void wxLog::DoLog(wxLogLevel level, const wxChar *szString, time_t t)
break; break;
case wxLOG_Error: case wxLOG_Error:
DoLogString(wxString(_("Error: ")) + szString, t); LogString(_("Error: ") + szString, t);
break; break;
case wxLOG_Warning: case wxLOG_Warning:
DoLogString(wxString(_("Warning: ")) + szString, t); LogString(_("Warning: ") + szString, t);
break; break;
case wxLOG_Info: case wxLOG_Info:
@@ -638,7 +645,7 @@ void wxLog::DoLog(wxLogLevel level, const wxChar *szString, time_t t)
case wxLOG_Message: case wxLOG_Message:
case wxLOG_Status: case wxLOG_Status:
default: // log unknown log levels too default: // log unknown log levels too
DoLogString(szString, t); LogString(szString, t);
break; break;
case wxLOG_Trace: case wxLOG_Trace:
@@ -648,16 +655,26 @@ void wxLog::DoLog(wxLogLevel level, const wxChar *szString, time_t t)
wxString msg = level == wxLOG_Trace ? wxT("Trace: ") wxString msg = level == wxLOG_Trace ? wxT("Trace: ")
: wxT("Debug: "); : wxT("Debug: ");
msg << szString; msg << szString;
DoLogString(msg, t); LogString(msg, t);
} }
#endif // Debug #endif // Debug
break; break;
} }
} }
void wxLog::DoLogString(const wxChar *WXUNUSED(szString), time_t WXUNUSED(t)) void wxLog::DoLogString(const wxString& szString, time_t t)
{ {
#if WXWIN_COMPATIBILITY_2_8
// DoLogString() signature changed since 2.8, so we call the old versions
// here so that existing custom log classes still work; unfortunately this
// also means that we can't have the wxFAIL_MSG below in compat mode
DoLogString((const char*)szString.mb_str(), t);
DoLogString((const wchar_t*)szString.wc_str(), t);
#else
wxFAIL_MSG(wxT("DoLogString must be overriden if it's called.")); wxFAIL_MSG(wxT("DoLogString must be overriden if it's called."));
wxUnusedVar(szString);
wxUnusedVar(t);
#endif
} }
void wxLog::Flush() void wxLog::Flush()
@@ -665,7 +682,7 @@ void wxLog::Flush()
// nothing to do here // nothing to do here
} }
/*static*/ bool wxLog::IsAllowedTraceMask(const wxChar *mask) /*static*/ bool wxLog::IsAllowedTraceMask(const wxString& mask)
{ {
for ( wxArrayString::iterator it = ms_aTraceMasks.begin(), for ( wxArrayString::iterator it = ms_aTraceMasks.begin(),
en = ms_aTraceMasks.end(); en = ms_aTraceMasks.end();
@@ -689,7 +706,7 @@ void wxLogBuffer::Flush()
} }
} }
void wxLogBuffer::DoLog(wxLogLevel level, const wxChar *szString, time_t t) void wxLogBuffer::DoLog(wxLogLevel level, const wxString& szString, time_t t)
{ {
switch ( level ) switch ( level )
{ {
@@ -714,7 +731,7 @@ void wxLogBuffer::DoLog(wxLogLevel level, const wxChar *szString, time_t t)
} }
} }
void wxLogBuffer::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) void wxLogBuffer::DoLogString(const wxString& szString, time_t WXUNUSED(t))
{ {
m_str << szString << _T("\n"); m_str << szString << _T("\n");
} }
@@ -731,7 +748,7 @@ wxLogStderr::wxLogStderr(FILE *fp)
m_fp = fp; m_fp = fp;
} }
void wxLogStderr::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) void wxLogStderr::DoLogString(const wxString& szString, time_t WXUNUSED(t))
{ {
wxString str; wxString str;
TimeStamp(&str); TimeStamp(&str);
@@ -770,11 +787,11 @@ wxLogStream::wxLogStream(wxSTD ostream *ostr)
m_ostr = ostr; m_ostr = ostr;
} }
void wxLogStream::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) void wxLogStream::DoLogString(const wxString& szString, time_t WXUNUSED(t))
{ {
wxString str; wxString stamp;
TimeStamp(&str); TimeStamp(&stamp);
(*m_ostr) << wxConvertWX2MB(str) << wxConvertWX2MB(szString) << wxSTD endl; (*m_ostr) << stamp << szString << wxSTD endl;
} }
#endif // wxUSE_STD_IOSTREAM #endif // wxUSE_STD_IOSTREAM
@@ -816,7 +833,7 @@ void wxLogChain::Flush()
m_logNew->Flush(); m_logNew->Flush();
} }
void wxLogChain::DoLog(wxLogLevel level, const wxChar *szString, time_t t) void wxLogChain::DoLog(wxLogLevel level, const wxString& szString, time_t t)
{ {
// let the previous logger show it // let the previous logger show it
if ( m_logOld && IsPassingMessages() ) if ( m_logOld && IsPassingMessages() )

View File

@@ -81,7 +81,7 @@
// this function is a wrapper around strftime(3) // this function is a wrapper around strftime(3)
// allows to exclude the usage of wxDateTime // allows to exclude the usage of wxDateTime
static wxString TimeStamp(const wxChar *format, time_t t) static wxString TimeStamp(const wxString& format, time_t t)
{ {
#if wxUSE_DATETIME #if wxUSE_DATETIME
wxChar buf[4096]; wxChar buf[4096];
@@ -363,7 +363,7 @@ void wxLogGui::Flush()
} }
// log all kinds of messages // log all kinds of messages
void wxLogGui::DoLog(wxLogLevel level, const wxChar *szString, time_t t) void wxLogGui::DoLog(wxLogLevel level, const wxString& szString, time_t t)
{ {
switch ( level ) { switch ( level ) {
case wxLOG_Info: case wxLOG_Info:
@@ -638,7 +638,7 @@ void wxLogWindow::Show(bool bShow)
m_pLogFrame->Show(bShow); m_pLogFrame->Show(bShow);
} }
void wxLogWindow::DoLog(wxLogLevel level, const wxChar *szString, time_t t) void wxLogWindow::DoLog(wxLogLevel level, const wxString& szString, time_t t)
{ {
// first let the previous logger show it // first let the previous logger show it
wxLogPassThrough::DoLog(level, szString, t); wxLogPassThrough::DoLog(level, szString, t);
@@ -648,11 +648,11 @@ void wxLogWindow::DoLog(wxLogLevel level, const wxChar *szString, time_t t)
case wxLOG_Status: case wxLOG_Status:
// by default, these messages are ignored by wxLog, so process // by default, these messages are ignored by wxLog, so process
// them ourselves // them ourselves
if ( !wxIsEmpty(szString) ) if ( !szString.empty() )
{ {
wxString str; wxString str;
str << _("Status: ") << szString; str << _("Status: ") << szString;
DoLogString(str, t); LogString(str, t);
} }
break; break;
@@ -670,7 +670,7 @@ void wxLogWindow::DoLog(wxLogLevel level, const wxChar *szString, time_t t)
} }
} }
void wxLogWindow::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) void wxLogWindow::DoLogString(const wxString& szString, time_t WXUNUSED(t))
{ {
// put the text into our window // put the text into our window
wxTextCtrl *pText = m_pLogFrame->TextCtrl(); wxTextCtrl *pText = m_pLogFrame->TextCtrl();
@@ -1158,7 +1158,7 @@ wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl *pTextCtrl)
m_pTextCtrl = pTextCtrl; m_pTextCtrl = pTextCtrl;
} }
void wxLogTextCtrl::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) void wxLogTextCtrl::DoLogString(const wxString& szString, time_t WXUNUSED(t))
{ {
wxString msg; wxString msg;
TimeStamp(&msg); TimeStamp(&msg);