43template <
typename DestinationPolicy,
typename DefaultPolicy>
44class G4strstreambuf :
public std::basic_streambuf<char>
50 buffer =
new char[size + 1];
53 ~G4strstreambuf()
override
64 G4strstreambuf(
const G4strstreambuf&) =
delete;
65 G4strstreambuf& operator=(
const G4strstreambuf&) =
delete;
70 if (count >= size) result = sync();
72 buffer[count] = (char)c;
82 return ReceiveString();
86 virtual G4int underflow() {
return 0; }
91 inline G4int ReceiveString()
94 if (destination !=
nullptr) {
95 return DestinationPolicy::PostMessage(destination, stringToSend);
97 return DefaultPolicy::PostMessage(stringToSend);
101 char* buffer =
nullptr;
136 std::cout << s << std::flush;
145 std::cerr << s << std::flush;
150using G4debugstreambuf = G4strstreambuf<PostToG4debug, DefaultToCout>;
151using G4coutstreambuf = G4strstreambuf<PostToG4cout, DefaultToCout>;
152using G4cerrstreambuf = G4strstreambuf<PostToG4cerr, DefaultToCerr>;
155#ifdef G4MULTITHREADED
157G4debugstreambuf*& _G4debugbuf_p()
163G4coutstreambuf*& _G4coutbuf_p()
169G4cerrstreambuf*& _G4cerrbuf_p()
176std::ostream*& _G4debug_p()
182std::ostream*& _G4cout_p()
188std::ostream*& _G4cerr_p()
197 if (_G4debugbuf_p() ==
nullptr) {
198 _G4debugbuf_p() =
new G4debugstreambuf;
200 if (_G4coutbuf_p() ==
nullptr) {
201 _G4coutbuf_p() =
new G4coutstreambuf;
203 if (_G4cerrbuf_p() ==
nullptr) {
204 _G4cerrbuf_p() =
new G4cerrstreambuf;
208 if (_G4debug_p() == &std::cout || _G4debug_p() ==
nullptr) {
209 _G4debug_p() =
new std::ostream(_G4debugbuf_p());
211 if (_G4cout_p() == &std::cout || _G4cout_p() ==
nullptr) {
212 _G4cout_p() =
new std::ostream(_G4coutbuf_p());
214 if (_G4cerr_p() == &std::cerr || _G4cerr_p() ==
nullptr) {
215 _G4cerr_p() =
new std::ostream(_G4cerrbuf_p());
224 _G4debug_p() = &std::cout;
226 _G4cout_p() = &std::cout;
228 _G4cerr_p() = &std::cerr;
231 delete _G4debugbuf_p();
232 _G4debugbuf_p() =
nullptr;
233 delete _G4coutbuf_p();
234 _G4coutbuf_p() =
nullptr;
235 delete _G4cerrbuf_p();
236 _G4cerrbuf_p() =
nullptr;
239# define G4debugbuf (*_G4debugbuf_p())
240# define G4coutbuf (*_G4coutbuf_p())
241# define G4cerrbuf (*_G4cerrbuf_p())
248void setupG4ioSystem() __attribute__((constructor));
249void cleanupG4ioSystem() __attribute__((destructor));
G4debugstreambuf G4debugbuf
void G4iosSetDestination(G4coutDestination *sink)
G4coutstreambuf G4coutbuf
G4cerrstreambuf G4cerrbuf
void G4iosInitialization()
G4GLOB_DLL std::ostream G4debug
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
G4int ReceiveG4cout_(const G4String &msg)
G4int ReceiveG4debug_(const G4String &msg)
G4int ReceiveG4cerr_(const G4String &msg)
#define G4ThreadLocalStatic