Main MRPT website > C++ reference
MRPT logo
Public Member Functions | Protected Attributes | Private Member Functions
mrpt::utils::CConsoleRedirector Class Reference

Detailed Description

By creating an object of this class, all the output to std::cout (and std::cerr) will be redirected to a text file, and optionally also shown on the console.

Based on code from http://www.devmaster.net/forums/showthread.php?t=7037

#include <mrpt/utils/CConsoleRedirector.h>

List of all members.

Public Member Functions

 CConsoleRedirector (const std::string &out_file, bool also_to_console=true, bool also_cerr=true, bool append_file=false, int bufferSize=1000)
 Constructor.
virtual ~CConsoleRedirector ()
void flush ()
virtual void writeString (const std::string &str)

Protected Attributes

std::ofstream m_of
 The text output file stream.
std::streambuf * sbOld
 The "old" std::cout.
std::streambuf * sbOld_cerr
 The "old" std::cout.
bool m_also_to_console
mrpt::synch::CCriticalSection m_cs

Private Member Functions

int overflow (int c)
int sync ()

Constructor & Destructor Documentation

mrpt::utils::CConsoleRedirector::CConsoleRedirector ( const std::string out_file,
bool  also_to_console = true,
bool  also_cerr = true,
bool  append_file = false,
int  bufferSize = 1000 
) [inline]

Constructor.

Parameters:
out_fileThe file to create / append
also_to_consoleWhether to redirect data to file *and* also dump data to the console as usual.
append_fileIf set to false the file will be truncated on open
bufferSizeIt's recommended to buffer the data instead of writing characters one by one.
also_cerrWhether to redirect the output to std::cerr in addition to std::cout.
Exceptions:
std::exceptionIf the file cannot be opened.

Definition at line 61 of file CConsoleRedirector.h.

References m_of, THROW_EXCEPTION_CUSTOM_MSG1, sbOld, and sbOld_cerr.

virtual mrpt::utils::CConsoleRedirector::~CConsoleRedirector ( ) [inline, virtual]

Definition at line 93 of file CConsoleRedirector.h.

References sync(), sbOld, and sbOld_cerr.


Member Function Documentation

void mrpt::utils::CConsoleRedirector::flush ( ) [inline]

Definition at line 102 of file CConsoleRedirector.h.

References sync().

int mrpt::utils::CConsoleRedirector::overflow ( int  c) [inline, private]
int mrpt::utils::CConsoleRedirector::sync ( ) [inline, private]
virtual void mrpt::utils::CConsoleRedirector::writeString ( const std::string str) [inline, virtual]

Definition at line 107 of file CConsoleRedirector.h.

References m_also_to_console, sbOld, and m_of.

Referenced by overflow(), and sync().


Member Data Documentation

Definition at line 49 of file CConsoleRedirector.h.

Referenced by writeString().

Definition at line 50 of file CConsoleRedirector.h.

Referenced by overflow(), and sync().

The text output file stream.

Definition at line 46 of file CConsoleRedirector.h.

Referenced by CConsoleRedirector(), and writeString().

std::streambuf* mrpt::utils::CConsoleRedirector::sbOld [protected]

The "old" std::cout.

Definition at line 47 of file CConsoleRedirector.h.

Referenced by CConsoleRedirector(), ~CConsoleRedirector(), and writeString().

std::streambuf* mrpt::utils::CConsoleRedirector::sbOld_cerr [protected]

The "old" std::cout.

Definition at line 48 of file CConsoleRedirector.h.

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




Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011