wx3.0: extend logger to support wxString as input

Note: only enabled it on 2.8 for windows (because of UTF8 linux is fine)
This commit is contained in:
Gregory Hainaut 2014-06-29 08:57:33 +02:00
parent 91afc2079c
commit fded22e1b3
7 changed files with 128 additions and 0 deletions

View File

@ -184,6 +184,10 @@ extern pxDoAssertFnType* pxDoAssert;
extern void pxOnAssert( const DiagnosticOrigin& origin, const wxChar* msg=NULL );
extern void pxOnAssert( const DiagnosticOrigin& origin, const char* msg );
#if wxMAJOR_VERSION >= 3
extern void pxOnAssert( const DiagnosticOrigin& origin, const wxString& msg);
extern void pxOnAssert( const DiagnosticOrigin& origin, const FastFormatUnicode& msg);
#endif
// --------------------------------------------------------------------------------------
// jNO_DEFAULT -- disables the default case in a switch, which improves switch optimization

View File

@ -120,6 +120,13 @@ struct IConsoleWriter
bool WriteLn( const wxChar* fmt, ... ) const;
bool Error( const wxChar* fmt, ... ) const;
bool Warning( const wxChar* fmt, ... ) const;
#if wxMAJOR_VERSION >= 3
bool WriteLn( ConsoleColors color, const wxString& fmt, ... ) const;
bool WriteLn( const wxString& fmt, ... ) const;
bool Error( const wxString& fmt, ... ) const;
bool Warning( const wxString& fmt, ... ) const;
#endif
};
// --------------------------------------------------------------------------------------
@ -155,6 +162,13 @@ struct NullConsoleWriter
bool WriteLn( const wxChar* fmt, ... ) const { return false; }
bool Error( const wxChar* fmt, ... ) const { return false; }
bool Warning( const wxChar* fmt, ... ) const { return false; }
#if wxMAJOR_VERSION >= 3
bool WriteLn( ConsoleColors color, const wxString& fmt, ... ) const { return false; }
bool WriteLn( const wxString& fmt, ... ) const { return false; }
bool Error( const wxString& fmt, ... ) const { return false; }
bool Warning( const wxString& fmt, ... ) const { return false; }
#endif
};
// --------------------------------------------------------------------------------------

View File

@ -188,6 +188,9 @@ public:
FastFormatUnicode& Write( const char* fmt, ... );
FastFormatUnicode& Write( const wxChar* fmt, ... );
#if wxMAJOR_VERSION >= 3
FastFormatUnicode& Write( const wxString& fmt, ... );
#endif
FastFormatUnicode& WriteV( const char* fmt, va_list argptr );
FastFormatUnicode& WriteV( const wxChar* fmt, va_list argptr );

View File

@ -193,6 +193,18 @@ public:
return false;
}
#if wxMAJOR_VERSION >= 3
bool Write( const wxString& fmt, ... ) const
{
va_list list;
va_start( list, fmt );
WriteV( fmt.wx_str(), list );
va_end( list );
return false;
}
#endif
// Writes to the console using the specified color. This overrides the default color setting
// for this log.
bool Write( ConsoleColors color, const char* fmt, ... ) const
@ -227,6 +239,18 @@ public:
return false;
}
#if wxMAJOR_VERSION >= 3
bool Warn( const wxString& fmt, ... ) const
{
va_list list;
va_start( list, fmt );
WriteV( Color_StrongYellow, fmt.wx_str(), list );
va_end( list );
return false;
}
#endif
// Writes to the console using bold red text -- overrides the log source's default
// color settings.
bool Error( const wxChar* fmt, ... ) const
@ -239,6 +263,18 @@ public:
return false;
}
#if wxMAJOR_VERSION >= 3
bool Error( const wxString& fmt, ... ) const
{
va_list list;
va_start( list, fmt );
WriteV( Color_StrongRed, fmt.wx_str(), list );
va_end( list );
return false;
}
#endif
bool WriteV( const char *fmt, va_list list ) const;
bool WriteV( const wxChar *fmt, va_list list ) const;

View File

@ -468,6 +468,55 @@ bool IConsoleWriter::Warning( const wxChar* fmt, ... ) const
return false;
}
#if wxMAJOR_VERSION >= 3
// --------------------------------------------------------------------------------------
// Write Variants - Unknown style
// --------------------------------------------------------------------------------------
bool IConsoleWriter::WriteLn( const wxString& fmt, ... ) const
{
va_list args;
va_start(args,fmt);
FormatV(fmt.wx_str(),args);
va_end(args);
return false;
}
bool IConsoleWriter::WriteLn( ConsoleColors color, const wxString& fmt, ... ) const
{
va_list args;
va_start(args,fmt);
ConsoleColorScope cs( color );
FormatV(fmt.wx_str(),args);
va_end(args);
return false;
}
bool IConsoleWriter::Error( const wxString& fmt, ... ) const
{
va_list args;
va_start(args,fmt);
ConsoleColorScope cs( Color_StrongRed );
FormatV(fmt.wx_str(),args);
va_end(args);
return false;
}
bool IConsoleWriter::Warning( const wxString& fmt, ... ) const
{
va_list args;
va_start(args,fmt);
ConsoleColorScope cs( Color_StrongOrange );
FormatV(fmt.wx_str(),args);
va_end(args);
return false;
}
#endif
// --------------------------------------------------------------------------------------
// ConsoleColorScope / ConsoleIndentScope
// --------------------------------------------------------------------------------------

View File

@ -134,6 +134,17 @@ __fi void pxOnAssert( const DiagnosticOrigin& origin, const char* msg)
pxOnAssert( origin, fromUTF8(msg) );
}
#if wxMAJOR_VERSION >= 3
__fi void pxOnAssert( const DiagnosticOrigin& origin, const wxString& msg)
{
pxOnAssert( origin, msg.wx_str() ); // wc_str ???
}
__fi void pxOnAssert( const DiagnosticOrigin& origin, const FastFormatUnicode& msg)
{
pxOnAssert( origin, msg.c_str());
}
#endif
// --------------------------------------------------------------------------------------
// BaseException (implementations)

View File

@ -295,6 +295,17 @@ FastFormatUnicode& FastFormatUnicode::Write( const wxChar* fmt, ... )
return *this;
}
#if wxMAJOR_VERSION >= 3
FastFormatUnicode& FastFormatUnicode::Write( const wxString& fmt, ... )
{
va_list list;
va_start(list, fmt);
WriteV(fmt.wx_str(),list);
va_end(list);
return *this;
}
#endif
bool FastFormatUnicode::IsEmpty() const
{
return ((wxChar&)(*m_dest)[0]) == 0;