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

Definition at line 42 of file CConsoleRedirector.h.

#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 60 of file CConsoleRedirector.h.

References m_of, sbOld, sbOld_cerr, and THROW_EXCEPTION_CUSTOM_MSG1.

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

Definition at line 92 of file CConsoleRedirector.h.

References sbOld, sbOld_cerr, and sync().


Member Function Documentation

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

Definition at line 101 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 106 of file CConsoleRedirector.h.

References m_also_to_console, m_of, and sbOld.

Referenced by overflow(), and sync().


Member Data Documentation

Definition at line 48 of file CConsoleRedirector.h.

Referenced by writeString().

Definition at line 49 of file CConsoleRedirector.h.

Referenced by overflow(), and sync().

std::ofstream mrpt::utils::CConsoleRedirector::m_of [protected]

The text output file stream.

Definition at line 45 of file CConsoleRedirector.h.

Referenced by CConsoleRedirector(), and writeString().

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

The "old" std::cout.

Definition at line 46 of file CConsoleRedirector.h.

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

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

The "old" std::cout.

Definition at line 47 of file CConsoleRedirector.h.

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




Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:40:17 UTC 2011