9 #ifndef CMyRedirector_H
10 #define CMyRedirector_H
12 #include <wx/string.h>
13 #include <wx/textctrl.h>
15 #include <wx/thread.h>
50 bool yieldApplication =
false,
51 int bufferSize = 3000,
52 bool also_cerr =
false,
53 bool threadSafe =
false,
58 char *ptr =
new char[bufferSize];
59 setp(ptr, ptr + bufferSize);
65 sbOld = std::cout.rdbuf();
66 std::cout.rdbuf(
this );
71 std::cerr.rdbuf(
this );
79 std::cout.rdbuf(
sbOld);
98 s = wxString(str.c_str(), wxConvUTF8);
103 #if wxCHECK_VERSION(3,0,0)
104 m_txt->GetEventHandler()->CallAfter(&wxTextCtrl::WriteText,
s);
122 wxCriticalSectionLocker lock(
m_cs);
143 wxCriticalSectionLocker lock(
m_cs);
144 if (pbase() == epptr())
159 wxCriticalSectionLocker lock(
m_cs);
161 if (pbase() != pptr())
163 int len = int(pptr() - pbase());
166 setp(pbase(), epptr());
This auxiliary class redirects the output sent to a streambuf to a wxTextCtrl object.
void dumpNow()
Writes all the stored strings to the text control (only for threadSafe mode).
std::streambuf * sbOldErr
CMyRedirector(wxTextCtrl *obj, bool yieldApplication=false, int bufferSize=3000, bool also_cerr=false, bool threadSafe=false, bool also_to_cout_cerr=false)
const bool m_also_to_cout_cerr
const bool m_yieldApplication
virtual void writeString(const std::string &str)
GLsizei GLsizei GLuint * obj
GLsizei const GLchar ** string