bbtk::WxStreamRedirector Class Reference

Redirects std::cout to a wxTextCtrl and optionally to printf also. More...

#include <bbtkWxStreamRedirector.h>

List of all members.

Public Member Functions

 WxStreamRedirector (std::ostream &redirect, wxTextCtrl *text, const wxColour &colour=*wxBLACK, bool doprintf=true, int bufferSize=1000)
 ~WxStreamRedirector ()
virtual void writeString (const std::string &str)

Private Member Functions

int overflow (int c)
int sync ()

Private Attributes

wxTextCtrl * mText
bool mPrintf
std::ostream & m_ostr
std::streambuf * m_sbufOld
wxColour mColour


Detailed Description

Redirects std::cout to a wxTextCtrl and optionally to printf also.

Definition at line 80 of file bbtkWxStreamRedirector.h.


Constructor & Destructor Documentation

bbtk::WxStreamRedirector::WxStreamRedirector ( std::ostream &  redirect,
wxTextCtrl *  text,
const wxColour &  colour = *wxBLACK,
bool  doprintf = true,
int  bufferSize = 1000 
) [inline]

Definition at line 86 of file bbtkWxStreamRedirector.h.

References m_ostr, m_sbufOld, mColour, mPrintf, and mText.

00091       : mText(text),
00092         mPrintf(doprintf),
00093         m_ostr(redirect),
00094         mColour(colour)
00095     {
00096       if (bufferSize)
00097         {
00098           char *ptr = new char[bufferSize];
00099           setp(ptr, ptr + bufferSize);
00100         }
00101       else
00102         setp(0, 0);
00103       
00104       m_sbufOld = m_ostr.rdbuf();
00105       m_ostr.rdbuf(this);
00106     }

bbtk::WxStreamRedirector::~WxStreamRedirector (  )  [inline]

Definition at line 108 of file bbtkWxStreamRedirector.h.

References m_ostr, m_sbufOld, and sync().

00109     {
00110       sync();
00111       delete[] pbase();
00112       m_ostr.rdbuf(m_sbufOld);
00113     }

Here is the call graph for this function:


Member Function Documentation

virtual void bbtk::WxStreamRedirector::writeString ( const std::string &  str  )  [inline, virtual]

Definition at line 115 of file bbtkWxStreamRedirector.h.

References mColour, mPrintf, mText, bbtk::std2wx(), and writeString().

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

00116     {
00117       const wxTextAttr& style = mText->GetDefaultStyle();
00118       mText->SetDefaultStyle(mColour);
00119       mText->AppendText(std2wx(str));
00120       mText->SetDefaultStyle(style);
00121      
00122       if (mPrintf) 
00123         {
00124           printf("%s",str.c_str());
00125         }
00126     }

Here is the call graph for this function:

Here is the caller graph for this function:

int bbtk::WxStreamRedirector::overflow ( int  c  )  [inline, private]

Definition at line 141 of file bbtkWxStreamRedirector.h.

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

Referenced by overflow().

00142     {
00143       sync();
00144       
00145       if (c != EOF)
00146         {
00147           if (pbase() == epptr())
00148             {
00149               std::string temp;
00150               temp += char(c);
00151               writeString(temp);
00152             }
00153           else
00154             sputc(c);
00155         }
00156       
00157       return 0;
00158     }

Here is the call graph for this function:

Here is the caller graph for this function:

int bbtk::WxStreamRedirector::sync (  )  [inline, private]

Definition at line 160 of file bbtkWxStreamRedirector.h.

References sync(), and writeString().

Referenced by overflow(), sync(), and ~WxStreamRedirector().

00161     {
00162       if (pbase() != pptr())
00163         {
00164           int len = int(pptr() - pbase());
00165           std::string temp(pbase(), len);
00166           writeString(temp);
00167           setp(pbase(), epptr());
00168         }
00169       return 0;
00170     }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

wxTextCtrl* bbtk::WxStreamRedirector::mText [private]

Definition at line 130 of file bbtkWxStreamRedirector.h.

Referenced by writeString(), and WxStreamRedirector().

bool bbtk::WxStreamRedirector::mPrintf [private]

Definition at line 132 of file bbtkWxStreamRedirector.h.

Referenced by writeString(), and WxStreamRedirector().

std::ostream& bbtk::WxStreamRedirector::m_ostr [private]

Definition at line 134 of file bbtkWxStreamRedirector.h.

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

std::streambuf* bbtk::WxStreamRedirector::m_sbufOld [private]

Definition at line 136 of file bbtkWxStreamRedirector.h.

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

wxColour bbtk::WxStreamRedirector::mColour [private]

Definition at line 138 of file bbtkWxStreamRedirector.h.

Referenced by writeString(), and WxStreamRedirector().


The documentation for this class was generated from the following file:

Generated on Wed Nov 12 11:39:08 2008 for BBTK by  doxygen 1.5.6