Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ios.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4ios implementation
27//
28// Authors: H.Yoshida, M.Nagamatu - November 1998
29// --------------------------------------------------------------------
30
31#include "G4ios.hh"
32#include "G4strstreambuf.hh"
33#include <iostream>
34
35#ifdef G4MULTITHREADED
36
37G4strstreambuf*& _G4coutbuf_p()
38{
39 G4ThreadLocalStatic auto* _instance = new G4strstreambuf();
40 return _instance;
41}
42
43G4strstreambuf*& _G4cerrbuf_p()
44{
45 G4ThreadLocalStatic auto* _instance = new G4strstreambuf();
46 return _instance;
47}
48
49std::ostream*& _G4cout_p()
50{
51 G4ThreadLocalStatic auto* _instance = new std::ostream(_G4coutbuf_p());
52 return _instance;
53}
54
55std::ostream*& _G4cerr_p()
56{
57 G4ThreadLocalStatic auto* _instance = new std::ostream(_G4cerrbuf_p());
58 return _instance;
59}
60
61# define G4coutbuf (*_G4coutbuf_p())
62# define G4cerrbuf (*_G4cerrbuf_p())
63# define G4cout (*_G4cout_p())
64# define G4cerr (*_G4cerr_p())
65
67{
68 if(_G4coutbuf_p() == nullptr)
69 {
70 _G4coutbuf_p() = new G4strstreambuf;
71 }
72 if(_G4cerrbuf_p() == nullptr)
73 {
74 _G4cerrbuf_p() = new G4strstreambuf;
75 }
76 if(_G4cout_p() == &std::cout || _G4cout_p() == nullptr)
77 {
78 _G4cout_p() = new std::ostream(_G4coutbuf_p());
79 }
80 if(_G4cerr_p() == &std::cerr || _G4cerr_p() == nullptr)
81 {
82 _G4cerr_p() = new std::ostream(_G4cerrbuf_p());
83 }
84}
85
87{
88 delete _G4cout_p();
89 _G4cout_p() = &std::cout;
90 delete _G4cerr_p();
91 _G4cerr_p() = &std::cerr;
92 delete _G4coutbuf_p();
93 _G4coutbuf_p() = nullptr;
94 delete _G4cerrbuf_p();
95 _G4cerrbuf_p() = nullptr;
96}
97
98// These two functions are guaranteed to be called at load and
99// unload of the library containing this code.
100namespace
101{
102# ifndef WIN32
103 void setupG4ioSystem() __attribute__((constructor));
104 void cleanupG4ioSystem() __attribute__((destructor));
105# endif
106 void setupG4ioSystem() { G4iosInitialization(); }
107 void cleanupG4ioSystem() { G4iosFinalization(); }
108} // namespace
109
110#else // Sequential
111
114std::ostream G4cout(&G4coutbuf);
115std::ostream G4cerr(&G4cerrbuf);
116
119
120#endif
void G4iosFinalization()
Definition: G4ios.cc:118
G4strstreambuf G4coutbuf
Definition: G4ios.cc:112
G4strstreambuf G4cerrbuf
Definition: G4ios.cc:113
void G4iosInitialization()
Definition: G4ios.cc:117
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
#define G4ThreadLocalStatic
Definition: tls.hh:76