File indexing completed on 2026-04-09 07:49:34
0001 #pragma once
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 #include <iostream>
0031 #include <iomanip>
0032 #include <streambuf>
0033 #include <sstream>
0034 #include <string>
0035
0036 namespace sdirect
0037 {
0038 struct cout_
0039 {
0040 std::streambuf* old;
0041
0042 cout_( std::streambuf* newbuf )
0043 :
0044 old( std::cout.rdbuf(newbuf) )
0045 {}
0046
0047 ~cout_()
0048 {
0049 std::cout.rdbuf( old );
0050 }
0051
0052 };
0053
0054 struct cerr_
0055 {
0056 std::streambuf* old;
0057
0058 cerr_( std::streambuf* newbuf )
0059 :
0060 old( std::cerr.rdbuf(newbuf) )
0061 {}
0062
0063 ~cerr_()
0064 {
0065 std::cerr.rdbuf( old );
0066 }
0067 };
0068
0069
0070
0071 struct ostream_
0072 {
0073 std::ostream& src;
0074 std::streambuf * const sbuf;
0075
0076 ostream_(std::ostream& dst, std::ostream& src)
0077 :
0078 src(src),
0079 sbuf(src.rdbuf(dst.rdbuf()))
0080 {
0081 }
0082
0083 ~ostream_()
0084 {
0085 src.rdbuf(sbuf);
0086 }
0087 };
0088
0089
0090 inline std::string OutputMessage(const char* msg, const std::string& out, const std::string& err, bool verbose )
0091 {
0092 std::stringstream ss ;
0093
0094 ss << std::left << std::setw(30) << msg << std::right
0095 << " yielded chars : "
0096 << " cout " << std::setw(6) << out.size()
0097 << " cerr " << std::setw(6) << err.size()
0098 << " : set VERBOSE to see them "
0099 << std::endl
0100 ;
0101
0102 if(verbose)
0103 {
0104 ss << "cout[" << std::endl << out << "]" << std::endl ;
0105 ss << "cerr[" << std::endl << err << "]" << std::endl ;
0106 }
0107 std::string s = ss.str();
0108 return s ;
0109 }
0110 }
0111
0112