Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4ios.cc
이 파일의 문서화 페이지로 가기
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 //
27 // $Id: G4ios.cc 110251 2018-05-17 14:09:28Z gcosmo $
28 //
29 //
30 // --------------------------------------------------------------
31 // GEANT 4 class implementation file
32 //
33 // G4ios.cc
34 //
35 // History 1998 Nov. 3 Masayasu Nagamatu
36 
37 #include "G4ios.hh"
38 #include "G4strstreambuf.hh"
39 #include <iostream>
40 
41 #ifdef G4MULTITHREADED
42 
43 G4strstreambuf*& _G4coutbuf_p()
44 {
46  return _instance;
47 }
48 
49 G4strstreambuf*& _G4cerrbuf_p()
50 {
52  return _instance;
53 }
54 
55 std::ostream*& _G4cout_p()
56 {
57  G4ThreadLocalStatic std::ostream* _instance = new std::ostream(_G4coutbuf_p());
58  return _instance;
59 }
60 
61 std::ostream*& _G4cerr_p()
62 {
63  G4ThreadLocalStatic std::ostream* _instance = new std::ostream(_G4cerrbuf_p());
64  return _instance;
65 }
66 
67 #define G4coutbuf (*_G4coutbuf_p())
68 #define G4cerrbuf (*_G4cerrbuf_p())
69 #define G4cout (*_G4cout_p())
70 #define G4cerr (*_G4cerr_p())
71 
73 {
74  if (_G4coutbuf_p() == 0) _G4coutbuf_p() = new G4strstreambuf;
75  if (_G4cerrbuf_p() == 0) _G4cerrbuf_p() = new G4strstreambuf;
76  if (_G4cout_p() == &std::cout || _G4cout_p() == 0) _G4cout_p() = new std::ostream(_G4coutbuf_p());
77  if (_G4cerr_p() == &std::cerr || _G4cerr_p() == 0) _G4cerr_p() = new std::ostream(_G4cerrbuf_p());
78 }
79 
80 void G4iosFinalization()
81 {
82  delete _G4cout_p(); _G4cout_p() = &std::cout;
83  delete _G4cerr_p(); _G4cerr_p() = &std::cerr;
84  delete _G4coutbuf_p(); _G4coutbuf_p() = nullptr;
85  delete _G4cerrbuf_p(); _G4cerrbuf_p() = nullptr;
86 }
87 
88 // These two functions are guaranteed to be called at load and
89 // unload of the library containing this code.
90 namespace
91 {
92 #ifndef WIN32
93  void setupG4ioSystem(void) __attribute__ ((constructor));
94  void cleanupG4ioSystem(void) __attribute__((destructor));
95 #endif
96  void setupG4ioSystem(void) { G4iosInitialization(); }
97  void cleanupG4ioSystem(void) { G4iosFinalization(); }
98 }
99 
100 #else // Sequential
101 
104 std::ostream G4cout(&G4coutbuf);
105 std::ostream G4cerr(&G4cerrbuf);
106 
109 
110 #endif
void G4iosInitialization()
Definition: G4ios.cc:107
#define G4ThreadLocalStatic
Definition: tls.hh:68
void G4iosFinalization()
Definition: G4ios.cc:108
G4strstreambuf G4coutbuf
Definition: G4ios.cc:104
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
G4strstreambuf G4cerrbuf
Definition: G4ios.cc:105