OpendTect-6_4  6.4
safefileio.h
Go to the documentation of this file.
1 #ifndef safefileio_h
2 #define safefileio_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A.H. Bril
9  Date: Nov 2004
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "basicmod.h"
16 #include "od_iostream.h"
17 
18 
45 {
46 public:
47 
48  SafeFileIO(const char*,bool locked=false);
49  ~SafeFileIO();
50 
51  bool open(bool forread,bool ignorelock=false);
52  const char* errMsg() const { return errmsg_.str(); }
53  od_istream& istrm();
54  od_ostream& ostrm();
55 
56  void closeFail( bool keeplock=false )
57  { doClose( keeplock, false ); }
58  bool closeSuccess( bool keeplock=false )
59  { return doClose( keeplock, true ); }
60 
61  const char* fileName() const { return filenm_.buf(); }
62 
63  // Some setup variables
67  double lockwaitincr_;
69 
73  bool remove();
74 
75 protected:
76 
77  const bool locked_;
84 
85  bool openRead(bool);
86  bool openWrite(bool);
87  bool commitWrite();
88  bool doClose(bool, bool);
89 
90  bool haveLock() const;
91  bool waitForLock() const;
92  void mkLock(bool);
93  void rmLock();
94 };
95 
96 
97 #endif
#define mExpClass(module)
Definition: commondefs.h:160
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:26
const char * str() const
Definition: odstring.h:48
bool removebakonsuccess_
default=false
Definition: safefileio.h:65
const BufferString newfnm_
Definition: safefileio.h:81
od_stream * strm_
Definition: safefileio.h:83
OD base class for stream read/write.
Definition: od_stream.h:53
BufferString errmsg_
Definition: safefileio.h:82
bool closeSuccess(bool keeplock=false)
Definition: safefileio.h:58
double lockwaitincr_
default=0.5 (seconds)
Definition: safefileio.h:67
OD class for stream read.
Definition: od_istream.h:24
const bool locked_
Definition: safefileio.h:77
bool usebakwhenmissing_
default=true
Definition: safefileio.h:64
bool allowlockremove_
Definition: safefileio.h:68
const char * fileName() const
Definition: safefileio.h:61
const char * errMsg() const
Definition: safefileio.h:52
Protects file IO when you can't afford to have partly written things after write errors or have a fil...
Definition: safefileio.h:44
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
const BufferString lockfnm_
Definition: safefileio.h:79
BufferString errmsg_
Definition: horizontracker.h:119
int lockretries_
default=10
Definition: safefileio.h:66
void closeFail(bool keeplock=false)
Definition: safefileio.h:56
const BufferString filenm_
Definition: safefileio.h:78
const BufferString bakfnm_
Definition: safefileio.h:80

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019