メインページ   モジュール   名前空間一覧   クラス階層   アルファベット順一覧   構成   ファイル一覧   構成メンバ   ファイルメンバ   関連ページ    

TStringStreamBuffer.cc

解説を見る。
00001 // =====================================================================
00002 //  $Id: TStringStreamBuffer.cc,v 1.2 2004/06/28 07:17:37 goiwai Exp $
00003 //  $Name: CLDAQ-1-14-03 $
00004 //  $Log: TStringStreamBuffer.cc,v $
00005 //  Revision 1.2  2004/06/28 07:17:37  goiwai
00006 //  TclogのデフォルトのログレベルをINFOレベルにしました。
00007 //
00008 //  Revision 1.1  2004/06/24 15:17:51  goiwai
00009 //  std::cout等をやめて、TOutputStreamのオブジェクトTcoutを使うことにした。理由は、出力前に皮をかぶせてやりたかったから。
00010 //  SystemActionのCatch〜で設定できる。
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     // Fix to overcome a bug on GNU gcc-3.0.X compilers. The return value
00070     // for cout, cerr overflow() function has to be c instead of 0 when
00071     // buffer is flushed for carriage-return.
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


CLDAQ - a Class Library for DataAcQuisition (Version 1.14.3)
Go IWAI -- goiwai at users.sourceforge.jp