Main MRPT website > C++ reference for MRPT 1.5.7
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

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 


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.
std::exceptionIf the file cannot be opened.

Definition at line 45 of file CConsoleRedirector.h.


◆ ~CConsoleRedirector()

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

Definition at line 77 of file CConsoleRedirector.h.

Member Function Documentation

◆ flush()

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

Definition at line 86 of file CConsoleRedirector.h.

◆ overflow()

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

◆ sync()

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

◆ writeString()

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

Definition at line 91 of file CConsoleRedirector.h.

Member Data Documentation

◆ m_also_to_console

bool mrpt::utils::CConsoleRedirector::m_also_to_console

Definition at line 33 of file CConsoleRedirector.h.

◆ m_cs

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

Definition at line 34 of file CConsoleRedirector.h.

◆ m_of

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

The text output file stream.

Definition at line 30 of file CConsoleRedirector.h.

◆ sbOld

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

The "old" std::cout.

Definition at line 31 of file CConsoleRedirector.h.

◆ sbOld_cerr

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

The "old" std::cout.

Definition at line 32 of file CConsoleRedirector.h.

Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 8277875f6 Mon Jun 11 02:47:32 2018 +0200 at lun oct 28 01:50:49 CET 2019