Geant4 10.7.0
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{
40 return _instance;
41}
42
43G4strstreambuf*& _G4cerrbuf_p()
44{
46 return _instance;
47}
48
49std::ostream*& _G4cout_p()
50{
51 G4ThreadLocalStatic std::ostream* _instance =
52 new std::ostream(_G4coutbuf_p());
53 return _instance;
54}
55
56std::ostream*& _G4cerr_p()
57{
58 G4ThreadLocalStatic std::ostream* _instance =
59 new std::ostream(_G4cerrbuf_p());
60 return _instance;
61}
62
63# define G4coutbuf (*_G4coutbuf_p())
64# define G4cerrbuf (*_G4cerrbuf_p())
65# define G4cout (*_G4cout_p())
66# define G4cerr (*_G4cerr_p())
67
69{
70 if(_G4coutbuf_p() == nullptr)
71 _G4coutbuf_p() = new G4strstreambuf;
72 if(_G4cerrbuf_p() == nullptr)
73 _G4cerrbuf_p() = new G4strstreambuf;
74 if(_G4cout_p() == &std::cout || _G4cout_p() == nullptr)
75 _G4cout_p() = new std::ostream(_G4coutbuf_p());
76 if(_G4cerr_p() == &std::cerr || _G4cerr_p() == nullptr)
77 _G4cerr_p() = new std::ostream(_G4cerrbuf_p());
78}
79
81{
82 delete _G4cout_p();
83 _G4cout_p() = &std::cout;
84 delete _G4cerr_p();
85 _G4cerr_p() = &std::cerr;
86 delete _G4coutbuf_p();
87 _G4coutbuf_p() = nullptr;
88 delete _G4cerrbuf_p();
89 _G4cerrbuf_p() = nullptr;
90}
91
92// These two functions are guaranteed to be called at load and
93// unload of the library containing this code.
94namespace
95{
96# ifndef WIN32
97 void setupG4ioSystem(void) __attribute__((constructor));
98 void cleanupG4ioSystem(void) __attribute__((destructor));
99# endif
100 void setupG4ioSystem(void) { G4iosInitialization(); }
101 void cleanupG4ioSystem(void) { G4iosFinalization(); }
102} // namespace
103
104#else // Sequential
105
108std::ostream G4cout(&G4coutbuf);
109std::ostream G4cerr(&G4cerrbuf);
110
113
114#endif
void G4iosFinalization()
Definition: G4ios.cc:112
G4strstreambuf G4coutbuf
Definition: G4ios.cc:106
G4strstreambuf G4cerrbuf
Definition: G4ios.cc:107
void G4iosInitialization()
Definition: G4ios.cc:111
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
#define G4ThreadLocalStatic
Definition: tls.hh:76