MRPT  2.0.4
List of all members | Public Member Functions | Protected Attributes | Private Member Functions
CMyRedirector Class Reference

Detailed Description

This auxiliary class redirects the output sent to a streambuf to a wxTextCtrl object.

Uses code from http://www.devmaster.net/forums/showthread.php?t=7037 Jose Luis Blanco - Dec 2007 NOTE (10-Aug-2009): Added thread-safe support: We cannot write in a wxTextCtrl from a thread different than the main wx one, so if this object will be used by several threads, set "m_threadSafe" to true. In this mode, the object will NEVER write the text to the text control, unless the method "dumpNow()" is explicitly called FROM THE MAIN THREAD.

Definition at line 36 of file CMyRedirector.h.

#include <mrpt/gui/CMyRedirector.h>

Inheritance diagram for CMyRedirector:

Public Member Functions

 CMyRedirector (wxTextCtrl *obj, bool yieldApplication=false, int bufferSize=3000, bool also_cerr=false, bool threadSafe=false, bool also_to_cout_cerr=false)
 
 ~CMyRedirector () override
 
void flush ()
 
virtual void writeString (const std::string &str)
 
void dumpNow ()
 Writes all the stored strings to the text control (only for threadSafe mode). More...
 

Protected Attributes

wxTextCtrl * m_txt
 
std::streambuf * sbOld
 
std::streambuf * sbOldErr
 
const bool m_yieldApplication
 
const bool m_also_cerr
 
const bool m_threadSafe
 
const bool m_also_to_cout_cerr
 
wxCriticalSection m_cs
 
std::string m_strbuf
 
std::vector< char > m_buf
 

Private Member Functions

int overflow (int c) override
 
int sync () override
 

Constructor & Destructor Documentation

◆ CMyRedirector()

CMyRedirector::CMyRedirector ( wxTextCtrl *  obj,
bool  yieldApplication = false,
int  bufferSize = 3000,
bool  also_cerr = false,
bool  threadSafe = false,
bool  also_to_cout_cerr = false 
)
inline

Definition at line 52 of file CMyRedirector.h.

References m_also_cerr, m_buf, sbOld, and sbOldErr.

◆ ~CMyRedirector()

CMyRedirector::~CMyRedirector ( )
inlineoverride

Definition at line 80 of file CMyRedirector.h.

References m_also_cerr, sbOld, sbOldErr, and sync().

Here is the call graph for this function:

Member Function Documentation

◆ dumpNow()

void CMyRedirector::dumpNow ( )
inline

Writes all the stored strings to the text control (only for threadSafe mode).

CALL THIS METHOD FROM THE MAIN THREAD!

Definition at line 118 of file CMyRedirector.h.

References m_also_to_cout_cerr, m_cs, m_strbuf, and m_txt.

◆ flush()

void CMyRedirector::flush ( )
inline

Definition at line 90 of file CMyRedirector.h.

References sync().

Here is the call graph for this function:

◆ overflow()

int CMyRedirector::overflow ( int  c)
inlineoverrideprivate

Definition at line 135 of file CMyRedirector.h.

References m_cs, sync(), and writeString().

Here is the call graph for this function:

◆ sync()

int CMyRedirector::sync ( )
inlineoverrideprivate

Definition at line 155 of file CMyRedirector.h.

References m_cs, and writeString().

Referenced by flush(), overflow(), and ~CMyRedirector().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeString()

virtual void CMyRedirector::writeString ( const std::string &  str)
inlinevirtual

Definition at line 91 of file CMyRedirector.h.

References m_also_to_cout_cerr, m_strbuf, m_threadSafe, m_txt, and m_yieldApplication.

Referenced by overflow(), and sync().

Here is the caller graph for this function:

Member Data Documentation

◆ m_also_cerr

const bool CMyRedirector::m_also_cerr
protected

Definition at line 43 of file CMyRedirector.h.

Referenced by CMyRedirector(), and ~CMyRedirector().

◆ m_also_to_cout_cerr

const bool CMyRedirector::m_also_to_cout_cerr
protected

Definition at line 45 of file CMyRedirector.h.

Referenced by dumpNow(), and writeString().

◆ m_buf

std::vector<char> CMyRedirector::m_buf
protected

Definition at line 49 of file CMyRedirector.h.

Referenced by CMyRedirector().

◆ m_cs

wxCriticalSection CMyRedirector::m_cs
protected

Definition at line 47 of file CMyRedirector.h.

Referenced by dumpNow(), overflow(), and sync().

◆ m_strbuf

std::string CMyRedirector::m_strbuf
protected

Definition at line 48 of file CMyRedirector.h.

Referenced by dumpNow(), and writeString().

◆ m_threadSafe

const bool CMyRedirector::m_threadSafe
protected

Definition at line 44 of file CMyRedirector.h.

Referenced by writeString().

◆ m_txt

wxTextCtrl* CMyRedirector::m_txt
protected

Definition at line 39 of file CMyRedirector.h.

Referenced by dumpNow(), and writeString().

◆ m_yieldApplication

const bool CMyRedirector::m_yieldApplication
protected

Definition at line 42 of file CMyRedirector.h.

Referenced by writeString().

◆ sbOld

std::streambuf* CMyRedirector::sbOld
protected

Definition at line 40 of file CMyRedirector.h.

Referenced by CMyRedirector(), and ~CMyRedirector().

◆ sbOldErr

std::streambuf* CMyRedirector::sbOldErr
protected

Definition at line 41 of file CMyRedirector.h.

Referenced by CMyRedirector(), and ~CMyRedirector().




Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020