Main MRPT website > C++ reference for MRPT 1.5.6
List of all members | 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 27 of file CConsoleRedirector.h.

#include <mrpt/utils/CConsoleRedirector.h>

Inheritance diagram for mrpt::utils::CConsoleRedirector:
Inheritance graph

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. More...
 
virtual ~CConsoleRedirector ()
 
void flush ()
 
virtual void writeString (const std::string &str)
 

Protected Attributes

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

Private Member Functions

int overflow (int c) MRPT_OVERRIDE
 
int sync () MRPT_OVERRIDE
 

Constructor & Destructor Documentation

◆ CConsoleRedirector()

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

References THROW_EXCEPTION_FMT.

◆ ~CConsoleRedirector()

virtual mrpt::utils::CConsoleRedirector::~CConsoleRedirector ( )
inlinevirtual

Definition at line 77 of file CConsoleRedirector.h.

Member Function Documentation

◆ flush()

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

Definition at line 86 of file CConsoleRedirector.h.

◆ overflow()

int mrpt::utils::CConsoleRedirector::overflow ( int  c)
inlineprivate

◆ sync()

int mrpt::utils::CConsoleRedirector::sync ( )
inlineprivate

◆ writeString()

virtual void mrpt::utils::CConsoleRedirector::writeString ( const std::string str)
inlinevirtual

Definition at line 91 of file CConsoleRedirector.h.

Member Data Documentation

◆ m_also_to_console

bool mrpt::utils::CConsoleRedirector::m_also_to_console
protected

Definition at line 33 of file CConsoleRedirector.h.

◆ m_cs

mrpt::synch::CCriticalSection mrpt::utils::CConsoleRedirector::m_cs
protected

Definition at line 34 of file CConsoleRedirector.h.

◆ m_of

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

The text output file stream.

Definition at line 30 of file CConsoleRedirector.h.

◆ sbOld

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

The "old" std::cout.

Definition at line 31 of file CConsoleRedirector.h.

◆ sbOld_cerr

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

The "old" std::cout.

Definition at line 32 of file CConsoleRedirector.h.




Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019