Main MRPT website > C++ reference for MRPT 1.9.9
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 28 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
 
std::mutex m_cs
 

Private Member Functions

int overflow (int c) override
 
int sync () 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 52 of file CConsoleRedirector.h.

References m_of, sbOld, sbOld_cerr, and THROW_EXCEPTION_FMT.

◆ ~CConsoleRedirector()

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

Definition at line 88 of file CConsoleRedirector.h.

References sbOld, sbOld_cerr, and sync().

Here is the call graph for this function:

Member Function Documentation

◆ flush()

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

Definition at line 97 of file CConsoleRedirector.h.

References sync().

Here is the call graph for this function:

◆ overflow()

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

Definition at line 105 of file CConsoleRedirector.h.

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

Here is the call graph for this function:

◆ sync()

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

Definition at line 126 of file CConsoleRedirector.h.

References m_cs, and writeString().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeString()

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

Definition at line 98 of file CConsoleRedirector.h.

References m_also_to_console, m_of, and sbOld.

Referenced by overflow(), and sync().

Here is the caller graph for this function:

Member Data Documentation

◆ m_also_to_console

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

Definition at line 37 of file CConsoleRedirector.h.

Referenced by writeString().

◆ m_cs

std::mutex mrpt::utils::CConsoleRedirector::m_cs
protected

Definition at line 38 of file CConsoleRedirector.h.

Referenced by overflow(), and sync().

◆ m_of

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

The text output file stream.

Definition at line 32 of file CConsoleRedirector.h.

Referenced by CConsoleRedirector(), and writeString().

◆ sbOld

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

The "old" std::cout.

Definition at line 34 of file CConsoleRedirector.h.

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

◆ sbOld_cerr

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

The "old" std::cout.

Definition at line 36 of file CConsoleRedirector.h.

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




Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019