Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4FRofstream.hh
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//
28#include <fstream>
29
30#if !defined G4_FR_OFSTREAM_HH
31#define G4_FR_OFSTREAM_HH
32
33
34#include "globals.hh"
35
36/////////////////////
37//typedef int G4bool ;
38//#define false 0 ;
39//#define true 1 ;
40////////////////////
41
43
44 public:
45 enum { SEND_BUFMAX = 1024 };
46
47 public:
48
49 // constructors
50 G4FRofstream () { flag_file_open = false ; }
51 G4FRofstream ( const char* filename ) ;
52
53 // destructor
54 virtual ~G4FRofstream ();
55
56 // open and close
57 void Open ( const char* filename );
58 void Close() ;
60
61 // utilities
62 void SendLine( const char* string ) ; // save string with new line
63
64 // static functions
65 static G4bool DoesFileExist( const char* filename ) ;
66
67 protected:
69 std::ofstream fout ;
70} ;
71
72
73inline void G4FRofstream::Open ( const char* filename )
74{
75 if( !IsOpen() ) {
76 fout.open( filename ) ;
77 flag_file_open = true ;
78 }
79}
80
81
82inline void G4FRofstream::Close ()
83{
84 if( IsOpen() ) {
85 fout.close();
86 flag_file_open = false ;
87 }
88}
89
90inline void G4FRofstream::SendLine ( const char* message )
91{
92 if ( IsOpen() ) {
93 fout << message << G4endl;
94 }
95}
96
97
98inline G4bool G4FRofstream::DoesFileExist ( const char* filename )
99{
100 G4bool status = false ;
101
102 std::ifstream fout_tmp( filename ) ;
103 if( fout_tmp ) { status = true ; }
104 fout_tmp.close();
105
106 return status ;
107}
108
109
110inline
111G4FRofstream::G4FRofstream ( const char* filename )
112{
113 flag_file_open = false ;
114 Open( filename );
115}
116
117inline
119{
120 Close() ;
121}
122
123
124#endif
bool G4bool
Definition: G4Types.hh:86
#define G4endl
Definition: G4ios.hh:57
G4bool flag_file_open
Definition: G4FRofstream.hh:68
virtual ~G4FRofstream()
void SendLine(const char *string)
Definition: G4FRofstream.hh:90
void Open(const char *filename)
Definition: G4FRofstream.hh:73
G4bool IsOpen()
Definition: G4FRofstream.hh:59
static G4bool DoesFileExist(const char *filename)
Definition: G4FRofstream.hh:98
std::ofstream fout
Definition: G4FRofstream.hh:69