00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TStringStreamBuffer.hh"
00015 #include "TSystemAction.hh"
00016 #include "TSystemLogging.hh"
00017
00018 TStringStreamBuffer::TStringStreamBuffer( Tint len )
00019 : std::streambuf(),
00020 theSystemAction( 0 ),
00021 theString( 0 ),
00022 theLength( len ),
00023 theIndex( 0 ),
00024 theLogLevel( TSystemLogging::INFO )
00025 {
00026 theString = new Tchar[ theLength + 1 ];
00027 }
00028
00029 TStringStreamBuffer::TStringStreamBuffer( const TStringStreamBuffer& right )
00030 : std::streambuf(),
00031 theSystemAction( right.theSystemAction ),
00032 theString( right.theString ),
00033 theLength( right.theLength ),
00034 theIndex( right.theIndex ),
00035 theLogLevel( right.theLogLevel )
00036 {;}
00037
00038 TStringStreamBuffer::~TStringStreamBuffer()
00039 {
00040 delete [] theString;
00041 }
00042
00043 TStringStreamBuffer& TStringStreamBuffer::operator=( const TStringStreamBuffer& right )
00044 {
00045 if ( &right == this ) {
00046 return *this;
00047 }
00048
00049 theSystemAction = right.theSystemAction;
00050 theString = right.theString;
00051 theLength = right.theLength;
00052 theIndex = right.theIndex;
00053 theLogLevel = right.theLogLevel;
00054
00055 return *this;
00056 }
00057
00058 Tint TStringStreamBuffer::overflow( Tint c )
00059 {
00060 Tint retval = 0;
00061 if ( theIndex >= theLength ) {
00062 retval = sync();
00063 }
00064 theString[ theIndex ] = c;
00065 theIndex ++;
00066
00067 if ( c == '\n' ) {
00068 retval = sync();
00069
00070
00071
00072 #if (__GNUC__==3) && (__GNUC_MINOR__==0)
00073 if ( this == &coutbuf || this == &cerrbuf || this == &clogbuf ) {
00074 retval = c;
00075 }
00076 #endif
00077 }
00078 return retval;
00079 }
00080
00081 Tint TStringStreamBuffer::sync()
00082 {
00083 theString[ theIndex ] = '\0';
00084 theIndex = 0;
00085 ReceiveString();
00086 return 0;
00087 }
00088
00089 Tvoid TStringStreamBuffer::ReceiveString()
00090 {
00091 Tstring message( theString );
00092
00093 if ( this == &coutbuf && theSystemAction != 0 ) {
00094 theSystemAction -> CatchStandardOut( message );
00095 } else if ( this == &cerrbuf && theSystemAction != 0 ) {
00096 theSystemAction -> CatchStandardError( message );
00097 } else if ( this == &clogbuf && theSystemAction != 0 ) {
00098 theSystemAction -> CatchLog( message, theLogLevel );
00099 } else if ( this == &coutbuf && theSystemAction == 0 ) {
00100 std::cout << message << std::flush;
00101 } else if ( this == &cerrbuf && theSystemAction == 0 ) {
00102 std::cerr << message << std::flush;
00103 } else if ( this == &clogbuf && theSystemAction == 0 ) {
00104 std::clog << message << std::flush;
00105 }
00106
00107 return;
00108 }
00109
00110 TStringStreamBuffer coutbuf;
00111 TStringStreamBuffer cerrbuf;
00112 TStringStreamBuffer clogbuf;
00113
00114 #ifdef __CLDAQ_ROOT_DLL
00115 ClassImp(TStringStreamBuffer)
00116 #endif