<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>mrpt::utils::CConsoleRedirector Class Reference</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <div align="left"><a href="http://www.mrpt.org/">Main MRPT website</a> > <b>C++ reference</b> </div> <div align="right"> <a href="index.html"><img border="0" src="mrpt_logo.png" alt="MRPT logo"></a> </div> <!-- Generated by Doxygen 1.7.5 --> <script type="text/javascript"> var searchBox = new SearchBox("searchBox", "search",false,'Search'); </script> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li class="current"><a href="annotated.html"><span>Classes</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li> <div id="MSearchBox" class="MSearchBoxInactive"> <div class="left"> <form id="FSearchBox" action="search.php" method="get"> <img id="MSearchSelect" src="search/mag.png" alt=""/> <input type="text" id="MSearchField" name="query" value="Search" size="20" accesskey="S" onfocus="searchBox.OnSearchFieldFocus(true)" onblur="searchBox.OnSearchFieldFocus(false)"/> </form> </div><div class="right"></div> </div> </li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="annotated.html"><span>Class List</span></a></li> <li><a href="classes.html"><span>Class Index</span></a></li> <li><a href="inherits.html"><span>Class Hierarchy</span></a></li> <li><a href="functions.html"><span>Class Members</span></a></li> </ul> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="namespacemrpt.html">mrpt</a> </li> <li class="navelem"><a class="el" href="namespacemrpt_1_1utils.html">utils</a> </li> <li class="navelem"><a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html">CConsoleRedirector</a> </li> </ul> </div> </div> <div class="header"> <div class="summary"> <a href="#pub-methods">Public Member Functions</a> | <a href="#pro-attribs">Protected Attributes</a> | <a href="#pri-methods">Private Member Functions</a> </div> <div class="headertitle"> <div class="title">mrpt::utils::CConsoleRedirector Class Reference<div class="ingroups"><a class="el" href="group__mrpt__base__grp.html">[mrpt-base]</a></div></div> </div> </div> <div class="contents"> <!-- doxytag: class="mrpt::utils::CConsoleRedirector" --><hr/><a name="details" id="details"></a><h2>Detailed Description</h2> <div class="textblock"><p>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. </p> <p>Based on code from <a href="http://www.devmaster.net/forums/showthread.php?t=7037">http://www.devmaster.net/forums/showthread.php?t=7037</a> </p> </div> <p><code>#include <<a class="el" href="_c_console_redirector_8h_source.html">mrpt/utils/CConsoleRedirector.h</a>></code></p> <p><a href="classmrpt_1_1utils_1_1_c_console_redirector-members.html">List of all members.</a></p> <table class="memberdecls"> <tr><td colspan="2"><h2><a name="pub-methods"></a> Public Member Functions</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html#a0ea7f0e66f47428b797f4e8dbb879ecf">CConsoleRedirector</a> (const <a class="el" href="classstd_1_1string.html">std::string</a> &out_file, bool also_to_console=true, bool also_cerr=true, bool append_file=false, int bufferSize=1000)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Constructor. <a href="#a0ea7f0e66f47428b797f4e8dbb879ecf"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">virtual </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html#a8e4bfe99160b1e8f22599f5dd8a64229">~CConsoleRedirector</a> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html#a27f023fa7abcbc01efed26e61ceb6341">flush</a> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">virtual void </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html#ab82eb4c464bb4f5a0b5a56e7fdf612ae">writeString</a> (const <a class="el" href="classstd_1_1string.html">std::string</a> &str)</td></tr> <tr><td colspan="2"><h2><a name="pro-attribs"></a> Protected Attributes</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="classstd_1_1ofstream.html">std::ofstream</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html#abeec24cb7c80b08c3a31fa6bb480a57c">m_of</a></td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">The text output file stream. <a href="#abeec24cb7c80b08c3a31fa6bb480a57c"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">std::streambuf * </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html#ab901214f164c140a63794abc63590de0">sbOld</a></td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">The "old" std::cout. <a href="#ab901214f164c140a63794abc63590de0"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">std::streambuf * </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html#a819c9dd7955c9737694b29600a775d96">sbOld_cerr</a></td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">The "old" std::cout. <a href="#a819c9dd7955c9737694b29600a775d96"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html#aacca1978aa7bea9441222d85820faf09">m_also_to_console</a></td></tr> <tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="classmrpt_1_1synch_1_1_c_critical_section.html">mrpt::synch::CCriticalSection</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html#a9614804f8c794377a0463bb28616dd67">m_cs</a></td></tr> <tr><td colspan="2"><h2><a name="pri-methods"></a> Private Member Functions</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html#ae1b5aa1eb6aa8527862dbd419e24e8e6">overflow</a> (int c)</td></tr> <tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html#ab9134e1f2be54deef662d6e85257bfbb">sync</a> ()</td></tr> </table> <hr/><h2>Constructor & Destructor Documentation</h2> <a class="anchor" id="a0ea7f0e66f47428b797f4e8dbb879ecf"></a><!-- doxytag: member="mrpt::utils::CConsoleRedirector::CConsoleRedirector" ref="a0ea7f0e66f47428b797f4e8dbb879ecf" args="(const std::string &out_file, bool also_to_console=true, bool also_cerr=true, bool append_file=false, int bufferSize=1000)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">mrpt::utils::CConsoleRedirector::CConsoleRedirector </td> <td>(</td> <td class="paramtype">const <a class="el" href="classstd_1_1string.html">std::string</a> & </td> <td class="paramname"><em>out_file</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">bool </td> <td class="paramname"><em>also_to_console</em> = <code>true</code>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">bool </td> <td class="paramname"><em>also_cerr</em> = <code>true</code>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">bool </td> <td class="paramname"><em>append_file</em> = <code>false</code>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">int </td> <td class="paramname"><em>bufferSize</em> = <code>1000</code> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td><code> [inline]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Constructor. </p> <dl><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramname">out_file</td><td>The file to create / append </td></tr> <tr><td class="paramname">also_to_console</td><td>Whether to redirect data to file *and* also dump data to the console as usual. </td></tr> <tr><td class="paramname">append_file</td><td>If set to false the file will be truncated on open </td></tr> <tr><td class="paramname">bufferSize</td><td>It's recommended to buffer the data instead of writing characters one by one. </td></tr> <tr><td class="paramname">also_cerr</td><td>Whether to redirect the output to std::cerr in addition to std::cout. </td></tr> </table> </dd> </dl> <dl><dt><b>Exceptions:</b></dt><dd> <table class="exception"> <tr><td class="paramname"><a class="el" href="classstd_1_1exception.html" title="STL class.">std::exception</a></td><td>If the file cannot be opened. </td></tr> </table> </dd> </dl> <p>Definition at line <a class="el" href="_c_console_redirector_8h_source.html#l00061">61</a> of file <a class="el" href="_c_console_redirector_8h_source.html">CConsoleRedirector.h</a>.</p> <p>References <a class="el" href="_c_console_redirector_8h_source.html#l00046">m_of</a>, <a class="el" href="mrpt__macros_8h.html#a61a8d46146210ee20fa1ff423257a5ec">THROW_EXCEPTION_CUSTOM_MSG1</a>, <a class="el" href="_c_console_redirector_8h_source.html#l00047">sbOld</a>, and <a class="el" href="_c_console_redirector_8h_source.html#l00048">sbOld_cerr</a>.</p> </div> </div> <a class="anchor" id="a8e4bfe99160b1e8f22599f5dd8a64229"></a><!-- doxytag: member="mrpt::utils::CConsoleRedirector::~CConsoleRedirector" ref="a8e4bfe99160b1e8f22599f5dd8a64229" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">virtual mrpt::utils::CConsoleRedirector::~CConsoleRedirector </td> <td>(</td> <td class="paramname"></td><td>)</td> <td><code> [inline, virtual]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="_c_console_redirector_8h_source.html#l00093">93</a> of file <a class="el" href="_c_console_redirector_8h_source.html">CConsoleRedirector.h</a>.</p> <p>References <a class="el" href="_c_console_redirector_8h_source.html#l00135">sync()</a>, <a class="el" href="_c_console_redirector_8h_source.html#l00047">sbOld</a>, and <a class="el" href="_c_console_redirector_8h_source.html#l00048">sbOld_cerr</a>.</p> </div> </div> <hr/><h2>Member Function Documentation</h2> <a class="anchor" id="a27f023fa7abcbc01efed26e61ceb6341"></a><!-- doxytag: member="mrpt::utils::CConsoleRedirector::flush" ref="a27f023fa7abcbc01efed26e61ceb6341" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void mrpt::utils::CConsoleRedirector::flush </td> <td>(</td> <td class="paramname"></td><td>)</td> <td><code> [inline]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="_c_console_redirector_8h_source.html#l00102">102</a> of file <a class="el" href="_c_console_redirector_8h_source.html">CConsoleRedirector.h</a>.</p> <p>References <a class="el" href="_c_console_redirector_8h_source.html#l00135">sync()</a>.</p> </div> </div> <a class="anchor" id="ae1b5aa1eb6aa8527862dbd419e24e8e6"></a><!-- doxytag: member="mrpt::utils::CConsoleRedirector::overflow" ref="ae1b5aa1eb6aa8527862dbd419e24e8e6" args="(int c)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">int mrpt::utils::CConsoleRedirector::overflow </td> <td>(</td> <td class="paramtype">int </td> <td class="paramname"><em>c</em></td><td>)</td> <td><code> [inline, private]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="_c_console_redirector_8h_source.html#l00114">114</a> of file <a class="el" href="_c_console_redirector_8h_source.html">CConsoleRedirector.h</a>.</p> <p>References <a class="el" href="_c_console_redirector_8h_source.html#l00135">sync()</a>, <a class="el" href="_c_console_redirector_8h_source.html#l00050">m_cs</a>, <a class="el" href="classmrpt_1_1synch_1_1_c_critical_section.html#a10c531e3bd482d9b54ddb83d8a95566c">mrpt::synch::CCriticalSection::enter()</a>, <a class="el" href="_c_console_redirector_8h_source.html#l00107">writeString()</a>, and <a class="el" href="classmrpt_1_1synch_1_1_c_critical_section.html#a933e6e22808e8e311cd980837547ef68">mrpt::synch::CCriticalSection::leave()</a>.</p> </div> </div> <a class="anchor" id="ab9134e1f2be54deef662d6e85257bfbb"></a><!-- doxytag: member="mrpt::utils::CConsoleRedirector::sync" ref="ab9134e1f2be54deef662d6e85257bfbb" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">int mrpt::utils::CConsoleRedirector::sync </td> <td>(</td> <td class="paramname"></td><td>)</td> <td><code> [inline, private]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="_c_console_redirector_8h_source.html#l00135">135</a> of file <a class="el" href="_c_console_redirector_8h_source.html">CConsoleRedirector.h</a>.</p> <p>References <a class="el" href="_c_console_redirector_8h_source.html#l00050">m_cs</a>, <a class="el" href="classmrpt_1_1synch_1_1_c_critical_section.html#a10c531e3bd482d9b54ddb83d8a95566c">mrpt::synch::CCriticalSection::enter()</a>, <a class="el" href="_c_console_redirector_8h_source.html#l00107">writeString()</a>, and <a class="el" href="classmrpt_1_1synch_1_1_c_critical_section.html#a933e6e22808e8e311cd980837547ef68">mrpt::synch::CCriticalSection::leave()</a>.</p> <p>Referenced by <a class="el" href="_c_console_redirector_8h_source.html#l00093">~CConsoleRedirector()</a>, <a class="el" href="_c_console_redirector_8h_source.html#l00102">flush()</a>, and <a class="el" href="_c_console_redirector_8h_source.html#l00114">overflow()</a>.</p> </div> </div> <a class="anchor" id="ab82eb4c464bb4f5a0b5a56e7fdf612ae"></a><!-- doxytag: member="mrpt::utils::CConsoleRedirector::writeString" ref="ab82eb4c464bb4f5a0b5a56e7fdf612ae" args="(const std::string &str)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">virtual void mrpt::utils::CConsoleRedirector::writeString </td> <td>(</td> <td class="paramtype">const <a class="el" href="classstd_1_1string.html">std::string</a> & </td> <td class="paramname"><em>str</em></td><td>)</td> <td><code> [inline, virtual]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="_c_console_redirector_8h_source.html#l00107">107</a> of file <a class="el" href="_c_console_redirector_8h_source.html">CConsoleRedirector.h</a>.</p> <p>References <a class="el" href="_c_console_redirector_8h_source.html#l00049">m_also_to_console</a>, <a class="el" href="_c_console_redirector_8h_source.html#l00047">sbOld</a>, and <a class="el" href="_c_console_redirector_8h_source.html#l00046">m_of</a>.</p> <p>Referenced by <a class="el" href="_c_console_redirector_8h_source.html#l00114">overflow()</a>, and <a class="el" href="_c_console_redirector_8h_source.html#l00135">sync()</a>.</p> </div> </div> <hr/><h2>Member Data Documentation</h2> <a class="anchor" id="aacca1978aa7bea9441222d85820faf09"></a><!-- doxytag: member="mrpt::utils::CConsoleRedirector::m_also_to_console" ref="aacca1978aa7bea9441222d85820faf09" args="" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">bool <a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html#aacca1978aa7bea9441222d85820faf09">mrpt::utils::CConsoleRedirector::m_also_to_console</a><code> [protected]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="_c_console_redirector_8h_source.html#l00049">49</a> of file <a class="el" href="_c_console_redirector_8h_source.html">CConsoleRedirector.h</a>.</p> <p>Referenced by <a class="el" href="_c_console_redirector_8h_source.html#l00107">writeString()</a>.</p> </div> </div> <a class="anchor" id="a9614804f8c794377a0463bb28616dd67"></a><!-- doxytag: member="mrpt::utils::CConsoleRedirector::m_cs" ref="a9614804f8c794377a0463bb28616dd67" args="" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname"><a class="el" href="classmrpt_1_1synch_1_1_c_critical_section.html">mrpt::synch::CCriticalSection</a> <a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html#a9614804f8c794377a0463bb28616dd67">mrpt::utils::CConsoleRedirector::m_cs</a><code> [protected]</code></td> </tr> </table> </div> <div class="memdoc"> <p>Definition at line <a class="el" href="_c_console_redirector_8h_source.html#l00050">50</a> of file <a class="el" href="_c_console_redirector_8h_source.html">CConsoleRedirector.h</a>.</p> <p>Referenced by <a class="el" href="_c_console_redirector_8h_source.html#l00114">overflow()</a>, and <a class="el" href="_c_console_redirector_8h_source.html#l00135">sync()</a>.</p> </div> </div> <a class="anchor" id="abeec24cb7c80b08c3a31fa6bb480a57c"></a><!-- doxytag: member="mrpt::utils::CConsoleRedirector::m_of" ref="abeec24cb7c80b08c3a31fa6bb480a57c" args="" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname"><a class="el" href="classstd_1_1ofstream.html">std::ofstream</a> <a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html#abeec24cb7c80b08c3a31fa6bb480a57c">mrpt::utils::CConsoleRedirector::m_of</a><code> [protected]</code></td> </tr> </table> </div> <div class="memdoc"> <p>The text output file stream. </p> <p>Definition at line <a class="el" href="_c_console_redirector_8h_source.html#l00046">46</a> of file <a class="el" href="_c_console_redirector_8h_source.html">CConsoleRedirector.h</a>.</p> <p>Referenced by <a class="el" href="_c_console_redirector_8h_source.html#l00061">CConsoleRedirector()</a>, and <a class="el" href="_c_console_redirector_8h_source.html#l00107">writeString()</a>.</p> </div> </div> <a class="anchor" id="ab901214f164c140a63794abc63590de0"></a><!-- doxytag: member="mrpt::utils::CConsoleRedirector::sbOld" ref="ab901214f164c140a63794abc63590de0" args="" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">std::streambuf* <a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html#ab901214f164c140a63794abc63590de0">mrpt::utils::CConsoleRedirector::sbOld</a><code> [protected]</code></td> </tr> </table> </div> <div class="memdoc"> <p>The "old" std::cout. </p> <p>Definition at line <a class="el" href="_c_console_redirector_8h_source.html#l00047">47</a> of file <a class="el" href="_c_console_redirector_8h_source.html">CConsoleRedirector.h</a>.</p> <p>Referenced by <a class="el" href="_c_console_redirector_8h_source.html#l00061">CConsoleRedirector()</a>, <a class="el" href="_c_console_redirector_8h_source.html#l00093">~CConsoleRedirector()</a>, and <a class="el" href="_c_console_redirector_8h_source.html#l00107">writeString()</a>.</p> </div> </div> <a class="anchor" id="a819c9dd7955c9737694b29600a775d96"></a><!-- doxytag: member="mrpt::utils::CConsoleRedirector::sbOld_cerr" ref="a819c9dd7955c9737694b29600a775d96" args="" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">std::streambuf* <a class="el" href="classmrpt_1_1utils_1_1_c_console_redirector.html#a819c9dd7955c9737694b29600a775d96">mrpt::utils::CConsoleRedirector::sbOld_cerr</a><code> [protected]</code></td> </tr> </table> </div> <div class="memdoc"> <p>The "old" std::cout. </p> <p>Definition at line <a class="el" href="_c_console_redirector_8h_source.html#l00048">48</a> of file <a class="el" href="_c_console_redirector_8h_source.html">CConsoleRedirector.h</a>.</p> <p>Referenced by <a class="el" href="_c_console_redirector_8h_source.html#l00061">CConsoleRedirector()</a>, and <a class="el" href="_c_console_redirector_8h_source.html#l00093">~CConsoleRedirector()</a>.</p> </div> </div> </div> <br><hr><br> <table border="0" width="100%"> <tr> <td> Page generated by <a href="http://www.doxygen.org" target="_blank">Doxygen 1.7.5</a> for MRPT 0.9.5 SVN: at Sun Sep 25 17:20:18 UTC 2011</td><td></td> <td width="100"> </td> <td width="150"> </td></tr> </table> </body></html>