File indexing completed on 2026-04-09 07:49:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #include <iostream>
0037 #include <iomanip>
0038 #include <streambuf>
0039 #include <sstream>
0040 #include <string>
0041
0042 struct cout_redirect {
0043 cout_redirect( std::streambuf * new_buffer )
0044 : old( std::cout.rdbuf( new_buffer ) )
0045 { }
0046
0047 ~cout_redirect( ) {
0048 std::cout.rdbuf( old );
0049 }
0050
0051 private:
0052 std::streambuf * old;
0053 };
0054
0055
0056 struct cerr_redirect {
0057 cerr_redirect( std::streambuf * new_buffer )
0058 : old( std::cerr.rdbuf( new_buffer ) )
0059 { }
0060
0061 ~cerr_redirect( ) {
0062 std::cerr.rdbuf( old );
0063 }
0064
0065 private:
0066 std::streambuf * old;
0067 };
0068
0069
0070
0071 struct stream_redirect
0072 {
0073
0074 stream_redirect(std::ostream & dst, std::ostream & src)
0075 :
0076 src(src),
0077 sbuf(src.rdbuf(dst.rdbuf()))
0078 {
0079 }
0080
0081 ~stream_redirect()
0082 {
0083 src.rdbuf(sbuf);
0084 }
0085
0086 private:
0087 std::ostream & src;
0088 std::streambuf * const sbuf;
0089 };
0090
0091
0092 inline std::string OutputMessage(const char* msg, const std::string& out, const std::string& err, bool verbose )
0093 {
0094 std::stringstream ss ;
0095
0096 ss << std::left << std::setw(30) << msg << std::right
0097 << " yielded chars : "
0098 << " cout " << std::setw(6) << out.size()
0099 << " cerr " << std::setw(6) << err.size()
0100 << " : set VERBOSE to see them "
0101 << std::endl
0102 ;
0103
0104 if(verbose)
0105 {
0106 ss << "cout[" << std::endl << out << "]" << std::endl ;
0107 ss << "cerr[" << std::endl << err << "]" << std::endl ;
0108 }
0109 std::string s = ss.str();
0110 return s ;
0111 }
0112
0113
0114
0115
0116
0117
0118