MOAB: Mesh Oriented datABase  (version 5.2.1)
StreamRedirector Class Reference

Public Member Functions

 StreamRedirector ()
 ~StreamRedirector ()
void redirect ()
void restore ()
void clear ()
void print_stream_bytes (const char *prefix, string bytes)
void check_stream (const char *name, ostringstream &str, bool &result)
bool have_data ()

Public Attributes

ostringstream outstr
ostringstream errstr
ostringstream logstr

Private Attributes

streambuf * outbuf
streambuf * errbuf
streambuf * logbuf

Detailed Description

Definition at line 680 of file QualityAssessorTest.cpp.


Constructor & Destructor Documentation

Definition at line 687 of file QualityAssessorTest.cpp.

    {
        outbuf = cout.rdbuf();
        errbuf = cerr.rdbuf();
        logbuf = clog.rdbuf();
    }

Definition at line 694 of file QualityAssessorTest.cpp.

    {
        restore();
    }

Member Function Documentation

void StreamRedirector::check_stream ( const char *  name,
ostringstream &  str,
bool &  result 
) [inline]

Definition at line 767 of file QualityAssessorTest.cpp.

    {
        string s = str.str();
        if( s.empty() ) return;
        result = true;
        print_stream_bytes( name, s );
    }
void StreamRedirector::clear ( ) [inline]

Definition at line 714 of file QualityAssessorTest.cpp.

    {
        string empty;
        outstr.str( empty );
        errstr.str( empty );
        logstr.str( empty );
    }
bool StreamRedirector::have_data ( ) [inline]

Definition at line 776 of file QualityAssessorTest.cpp.

Referenced by QualityAssessorTest::test_output_control().

    {
        bool result = false;
        check_stream( "std::cout", outstr, result );
        check_stream( "std::cerr", errstr, result );
        check_stream( "std::clog", logstr, result );
        return result;
    }
void StreamRedirector::print_stream_bytes ( const char *  prefix,
string  bytes 
) [inline]

Definition at line 722 of file QualityAssessorTest.cpp.

    {
        // fix output stream so we can use it to print results
        streambuf* sbuf = cout.rdbuf();
        cout.rdbuf( outbuf );
        cout << prefix << ": " << bytes.size() << " characters: ";
        for( string::iterator i = bytes.begin(); i != bytes.end(); ++i )
            if( isprint( *i ) || *i == ' ' )
                cout << *i;
            else
                switch( *i )
                {
                    case '\a':
                        cout << "\\a";
                        break;
                    case '\b':
                        cout << "\\b";
                        break;
                    case '\t':
                        cout << "\\t";
                        break;
                    case '\n':
                        cout << "\\n";
                        break;
                    case '\v':
                        cout << "\\v";
                        break;
                    case '\f':
                        cout << "\\f";
                        break;
                    case '\r':
                        cout << "\\r";
                        break;
                    case '\0':
                        cout << "\\0";
                        break;
                    default:
                        cout << '\\' << setw( 3 ) << setfill( '0' ) << oct << *i;
                        break;
                }
        cout << endl;
        // restore cout to incomming state
        cout.rdbuf( sbuf );
    }
void StreamRedirector::redirect ( ) [inline]

Definition at line 699 of file QualityAssessorTest.cpp.

Referenced by QualityAssessorTest::test_output_control().

    {
        clear();
        cout.rdbuf( outstr.rdbuf() );
        cerr.rdbuf( errstr.rdbuf() );
        clog.rdbuf( logstr.rdbuf() );
    }
void StreamRedirector::restore ( ) [inline]

Definition at line 707 of file QualityAssessorTest.cpp.

Referenced by QualityAssessorTest::test_output_control().

    {
        cout.rdbuf( outbuf );
        cerr.rdbuf( errbuf );
        clog.rdbuf( logbuf );
    }

Member Data Documentation

streambuf * StreamRedirector::errbuf [private]

Definition at line 683 of file QualityAssessorTest.cpp.

ostringstream StreamRedirector::errstr

Definition at line 686 of file QualityAssessorTest.cpp.

streambuf * StreamRedirector::logbuf [private]

Definition at line 683 of file QualityAssessorTest.cpp.

ostringstream StreamRedirector::logstr

Definition at line 686 of file QualityAssessorTest.cpp.

streambuf* StreamRedirector::outbuf [private]

Definition at line 683 of file QualityAssessorTest.cpp.

ostringstream StreamRedirector::outstr

Definition at line 686 of file QualityAssessorTest.cpp.

List of all members.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines