00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00034 inline G4strstreambuf::G4strstreambuf()
00035 : std::basic_streambuf<char>(),
00036 count(0), destination(0)
00038 {
00039 size= 4095;
00040 buffer= new char[size+1];
00041 }
00042
00043
00045 inline G4strstreambuf::~G4strstreambuf()
00047 {
00048
00049
00050 if(count !=0) std::cout << buffer;
00051
00052 delete [] buffer;
00053 }
00054
00055
00057 inline G4strstreambuf::G4strstreambuf(const G4strstreambuf& right)
00058 : std::basic_streambuf<char>(),
00059 buffer(right.buffer),
00060 count(right.count), size(right.size),
00061 destination(right.destination)
00063 {
00064 }
00065
00066
00068 inline G4strstreambuf& G4strstreambuf::operator=(const G4strstreambuf& right)
00070 {
00071 if(&right==this) return *this;
00072
00073 destination= right.destination;
00074 buffer= right.buffer;
00075 count= right.count;
00076 size= right.size;
00077
00078 return *this;
00079 }
00080
00081
00083 inline G4int G4strstreambuf::overflow(G4int c)
00085 {
00086 G4int result= 0;
00087 if(count>=size) result= sync();
00088
00089 buffer[count]= c;
00090 count++;
00091
00092 return result;
00093 }
00094
00096 inline G4int G4strstreambuf::sync()
00098 {
00099 buffer[count] = '\0';
00100 count= 0;
00101 return ReceiveString();
00102 }
00103
00104
00105 #ifdef WIN32
00107 inline G4int G4strstreambuf::underflow()
00109 {
00110 return 0;
00111 }
00112 #endif
00113
00114
00116 inline void G4strstreambuf::SetDestination(G4coutDestination* dest)
00118 {
00119 destination= dest;
00120 }
00121
00122
00124 inline G4int G4strstreambuf::ReceiveString ()
00126 {
00127 G4String stringToSend(buffer);
00128 G4int result= 0;
00129
00130 if(this == &G4coutbuf && destination != 0) {
00131 result= destination-> ReceiveG4cout(stringToSend);
00132
00133 } else if(this == &G4cerrbuf && destination != 0) {
00134 result= destination-> ReceiveG4cerr(stringToSend);
00135
00136 } else if(this == &G4coutbuf && destination == 0) {
00137 std::cout << stringToSend << std::flush;
00138 result= 0;
00139
00140 } else if(this == &G4cerrbuf && destination == 0) {
00141 std::cerr << stringToSend << std::flush;
00142 result= 0;
00143 }
00144
00145 return result;
00146 }
00147