Refactor wxLog and wxMessageOutput classes to avoid duplication

Add wxMessageOutputWithConv mix-in class to avoid duplicating the same
code in wxLogStream and wxMessageOutputStderr.

Also derive wxLogStderr from wxMessageOutputStderr to reuse its code
without having to create a temporary object of this type (which will be
more expensive now that doing it involves creating a heap-allocated
conversion object copy).
This commit is contained in:
Vadim Zeitlin
2017-10-21 22:06:08 +02:00
parent 6b73bd9136
commit a7dddd9f3b
4 changed files with 72 additions and 74 deletions

View File

@@ -61,6 +61,7 @@ class WXDLLIMPEXP_FWD_BASE wxObject;
#include "wx/dynarray.h"
#include "wx/hashmap.h"
#include "wx/msgout.h"
#if wxUSE_THREADS
#include "wx/thread.h"
@@ -716,34 +717,31 @@ private:
// log everything to a "FILE *", stderr by default
class WXDLLIMPEXP_BASE wxLogStderr : public wxLog
class WXDLLIMPEXP_BASE wxLogStderr : public wxLog,
private wxMessageOutputStderr
{
public:
// redirect log output to a FILE
wxLogStderr(FILE *fp = NULL,
const wxMBConv &conv = wxConvWhateverWorks);
virtual ~wxLogStderr();
protected:
// implement sink function
virtual void DoLogText(const wxString& msg) wxOVERRIDE;
FILE *m_fp;
const wxMBConv *m_conv;
wxDECLARE_NO_COPY_CLASS(wxLogStderr);
};
#if wxUSE_STD_IOSTREAM
// log everything to an "ostream", cerr by default
class WXDLLIMPEXP_BASE wxLogStream : public wxLog
class WXDLLIMPEXP_BASE wxLogStream : public wxLog,
private wxMessageOutputWithConv
{
public:
// redirect log output to an ostream
wxLogStream(wxSTD ostream *ostr = (wxSTD ostream *) NULL,
const wxMBConv &conv = wxConvWhateverWorks);
virtual ~wxLogStream();
const wxMBConv& conv = wxConvWhateverWorks);
protected:
// implement sink function
@@ -751,7 +749,8 @@ protected:
// using ptr here to avoid including <iostream.h> from this file
wxSTD ostream *m_ostr;
const wxMBConv *m_conv;
wxDECLARE_NO_COPY_CLASS(wxLogStream);
};
#endif // wxUSE_STD_IOSTREAM