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