Geant4  10.02.p01
G4ofstreamDestination.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 //
27 // $Id: G4coutDestination.hh 66241 2014-05-16 00:00:42Z adotti $
28 //
29 //
30 // ---------------------------------------------------------------
31 // GEANT 4 class cc file
32 //
33 // G4ofstreamDestination.cc
34 //
35 // ---------------------------------------------------------------
36 #include "G4strstreambuf.hh"
37 #include "G4ofstreamDestination.hh"
38 #include <ios>
39 
40 //TODO: make this that can be only cout / only cerr or both with a parameter,
41 // default is both
43  G4bool append)
45  fileName(fn),
46  appendFlag(append)
47 {
48 }
49 
51 {
52  Close();
53 }
54 
56 {
57  fileName = fn;
58  appendFlag = append;
59 }
60 
62 {
63  if ( ! g4file.is_open() )
64  {
65  std::ios::openmode mode = std::ios::out;
66  if ( appendFlag )
67  mode |= std::ios::app;
68  g4file.open(fileName,mode);
69  }
70 }
71 
73 {
74  if ( g4file.is_open() )
75  g4file.close();
76 }
77 
78 
79 //========================
80 //Concrete implementations
81 //========================
82 G4CoutToFile::G4CoutToFile(const G4String& defaultName , G4bool append) :
83  G4ofstreamDestinationBase(defaultName,append)
84 {
86 }
87 
89 {
90  if ( ! g4file.is_open() ) Open();
91  g4file<<msg<<std::flush;
92  return 0;
93 }
94 
95 G4CerrToFile::G4CerrToFile(const G4String& defaultName, G4bool append) :
96  G4ofstreamDestinationBase(defaultName,append)
97 {
99 }
100 
102 {
103  if ( !g4file.is_open() ) Open();
104  g4file<<msg<<std::flush;
105  return 0;
106 }
virtual G4int ReceiveG4cerr(const G4String &msg)
G4CerrToFile(const G4String &deafaultName="Geant4_cerr.txt", G4bool append=true)
int G4int
Definition: G4Types.hh:78
G4ofstreamDestinationBase(const G4String &defaultName, G4bool append)
G4strstreambuf G4coutbuf
Definition: G4ios.cc:82
bool G4bool
Definition: G4Types.hh:79
void SetFileName(const G4String &name, G4bool append=true)
G4CoutToFile(const G4String &deafaultName="Geant4_cout.txt", G4bool append=true)
void SetDestination(G4coutDestination *dest)
virtual G4int ReceiveG4cout(const G4String &msg)
G4strstreambuf G4cerrbuf
Definition: G4ios.cc:83