Computer Assited Medical Intervention Tool Kit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
camitk::ConsoleStream Class Reference

Directly inspired by this place. More...

#include <ConsoleStream.h>

+ Inheritance diagram for camitk::ConsoleStream:

Public Member Functions

 ConsoleStream (std::ostream *stream, QTextEdit *textEdit)
 constructor to use when you are sure about both paramaters More...
 
 ConsoleStream ()
 default constructor, init(..) have to be called later, before first use More...
 
void free ()
 reset the state as it was before (stream use the old buffer again) More...
 
void init (std::ostream *stream, QTextEdit *textEdit)
 initialize ConsoleStream using both input stream and output text edit More...
 
void setStream (std::ostream *stream)
 set the value for the buffer to be replaced by the ConsoleStream More...
 
void setTextEdit (QTextEdit *text_edit)
 set the log QTextEdit More...
 
 ~ConsoleStream ()
 destructor: use free() to restore previous stream output buffer More...
 

Protected Member Functions

virtual int_type overflow (int_type v)
 rewriting of the inherited method overflow More...
 
virtual std::streamsize xsputn (const char *p, std::streamsize n)
 rewriting of the inherited method xsputn More...
 

Private Attributes

QTextEdit * logTextEdit
 
std::ostream * myStream
 
std::string myString
 
std::streambuf * previousBuffer
 

Detailed Description

Directly inspired by this place.

(see also this follow-up)

Usage:

#include <ConsoleStream.h>
...
// create your application
QApplication app(argc, argv);
// these redirect both cout/cerr
ConsoleStream cout(std::cout);
ConsoleStream cerr(std::cerr);
// now start using cout and cerr normally
std::cerr << "Oops"; // this goes to your debugger output

Potential problem on windows (see thread)

Constructor & Destructor Documentation

camitk::ConsoleStream::ConsoleStream ( std::ostream *  stream,
QTextEdit *  textEdit 
)
inline

constructor to use when you are sure about both paramaters

References init().

camitk::ConsoleStream::ConsoleStream ( )
inline

default constructor, init(..) have to be called later, before first use

References logTextEdit, myStream, and previousBuffer.

camitk::ConsoleStream::~ConsoleStream ( )
inline

destructor: use free() to restore previous stream output buffer

References free(), logTextEdit, and myString.

Member Function Documentation

void camitk::ConsoleStream::free ( )
inline

reset the state as it was before (stream use the old buffer again)

References myStream, and previousBuffer.

Referenced by camitk::MainWindow::redirectToConsole(), setStream(), and ~ConsoleStream().

void camitk::ConsoleStream::init ( std::ostream *  stream,
QTextEdit *  textEdit 
)
inline

initialize ConsoleStream using both input stream and output text edit

References setStream(), and setTextEdit().

Referenced by ConsoleStream(), and camitk::MainWindow::redirectToConsole().

virtual int_type camitk::ConsoleStream::overflow ( int_type  v)
inlineprotectedvirtual

rewriting of the inherited method overflow

References logTextEdit, and myString.

void camitk::ConsoleStream::setStream ( std::ostream *  stream)
inline

set the value for the buffer to be replaced by the ConsoleStream

References free(), myStream, and previousBuffer.

Referenced by init().

void camitk::ConsoleStream::setTextEdit ( QTextEdit *  text_edit)
inline

set the log QTextEdit

References logTextEdit.

Referenced by init().

virtual std::streamsize camitk::ConsoleStream::xsputn ( const char *  p,
std::streamsize  n 
)
inlineprotectedvirtual

rewriting of the inherited method xsputn

References logTextEdit, and myString.

Member Data Documentation

QTextEdit* camitk::ConsoleStream::logTextEdit
private
std::ostream* camitk::ConsoleStream::myStream
private

Referenced by ConsoleStream(), free(), and setStream().

std::string camitk::ConsoleStream::myString
private

Referenced by overflow(), xsputn(), and ~ConsoleStream().

std::streambuf* camitk::ConsoleStream::previousBuffer
private

Referenced by ConsoleStream(), free(), and setStream().


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