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