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