00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id$ 00028 // 00029 #include <fstream> 00030 00031 #if !defined G4_FR_OFSTREAM_HH 00032 #define G4_FR_OFSTREAM_HH 00033 00034 00035 #include "globals.hh" 00036 00038 //typedef int G4bool ; 00039 //#define false 0 ; 00040 //#define true 1 ; 00042 00043 class G4FRofstream { 00044 00045 public: 00046 enum { SEND_BUFMAX = 1024 }; 00047 00048 public: 00049 00050 // constructors 00051 G4FRofstream () { flag_file_open = false ; } 00052 G4FRofstream ( const char* filename ) ; 00053 00054 // destructor 00055 virtual ~G4FRofstream (); 00056 00057 // open and close 00058 void Open ( const char* filename ); 00059 void Close() ; 00060 G4bool IsOpen() { return flag_file_open ;} 00061 00062 // utilities 00063 void SendLine( const char* string ) ; // save string with new line 00064 00065 // static functions 00066 static G4bool DoesFileExist( const char* filename ) ; 00067 00068 protected: 00069 G4bool flag_file_open ; 00070 std::ofstream fout ; 00071 } ; 00072 00073 00074 inline void G4FRofstream::Open ( const char* filename ) 00075 { 00076 if( !IsOpen() ) { 00077 fout.open( filename ) ; 00078 flag_file_open = true ; 00079 } 00080 } 00081 00082 00083 inline void G4FRofstream::Close () 00084 { 00085 if( IsOpen() ) { 00086 fout.close(); 00087 flag_file_open = false ; 00088 } 00089 } 00090 00091 inline void G4FRofstream::SendLine ( const char* message ) 00092 { 00093 if ( IsOpen() ) { 00094 fout << message << G4endl; 00095 } 00096 } 00097 00098 00099 inline G4bool G4FRofstream::DoesFileExist ( const char* filename ) 00100 { 00101 G4bool status = false ; 00102 00103 std::ifstream fout_tmp( filename ) ; 00104 if( fout_tmp ) { status = true ; } 00105 fout_tmp.close(); 00106 00107 return status ; 00108 } 00109 00110 00111 inline 00112 G4FRofstream::G4FRofstream ( const char* filename ) 00113 { 00114 flag_file_open = false ; 00115 Open( filename ); 00116 } 00117 00118 inline 00119 G4FRofstream::~G4FRofstream () 00120 { 00121 Close() ; 00122 } 00123 00124 00125 #endif