9 #ifndef CConsoleRedirector_H 10 #define CConsoleRedirector_H 53 const std::string& out_file,
bool also_to_console =
true,
54 bool also_cerr =
true,
bool append_file =
false,
int bufferSize = 1000)
62 std::ios_base::openmode openMode =
63 std::ios_base::binary | std::ios_base::out;
64 if (append_file) openMode |= std::ios_base::app;
65 m_of.open(out_file.c_str(), openMode);
71 char* ptr =
new char[bufferSize];
72 setp(ptr, ptr + bufferSize);
78 sbOld = std::cout.rdbuf();
79 std::cout.rdbuf(
this);
84 std::cerr.rdbuf(
this);
92 std::cout.rdbuf(
sbOld);
94 if (pbase())
delete[] pbase();
112 if (pbase() == epptr())
129 if (pbase() != pptr())
131 int len = int(pptr() - pbase());
134 setp(pbase(), epptr());
CConsoleRedirector(const std::string &out_file, bool also_to_console=true, bool also_cerr=true, bool append_file=false, int bufferSize=1000)
Constructor.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
By creating an object of this class, all the output to std::cout (and std::cerr) will be redirected t...
std::streambuf * sbOld_cerr
The "old" std::cout.
GLsizei const GLchar ** string
std::ofstream m_of
The text output file stream.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
virtual ~CConsoleRedirector()
virtual void writeString(const std::string &str)
std::streambuf * sbOld
The "old" std::cout.
int overflow(int c) override