LRAUV  revA
FileIOStream.h
Go to the documentation of this file.
1 
10 #ifndef FILEIOSTREAM_H_
11 #define FILEIOSTREAM_H_
12 
13 #include "IOStream.h"
14 #include "utils/Mutex.h"
15 
16 #include <cstdio>
17 #include <sys/stat.h>
18 
27 class FileIOStream : public IOStream
28 {
29 public:
30 
32  FileIOStream( FILE* file = NULL, bool autoClose = false );
33 
35  FileIOStream( const char* filename, bool clobber );
36 
37  virtual ~FileIOStream();
38 
39  void close();
40 
42  virtual IOStream& read( char* buffer, size_t num );
43 
45  void setFile( FILE* file, const char* filename )
46  {
47  file_ = file;
48  filename_ = filename;
49  }
50 
51  bool seek( unsigned int location );
52 
53  virtual bool eof();
54 
55  virtual void clearErr();
56 
57  bool isReadable()
58  {
59  return NULL != file_;
60  }
61 
62  const char* getName()
63  {
64  return filename_.cStr();
65  }
66 
67  const Str& getFilename()
68  {
69  return filename_;
70  }
71 
72  const struct stat getStat();
73 
75  IOStream& write( const char* buffer, size_t num );
76 
78  virtual IOStream& write( const char* buffer )
79  {
80  return write( buffer, strlen( buffer ) );
81  }
82 
84  void setFile( FILE* file )
85  {
86  file_ = file;
87  }
88 
89  int tell();
90 
91  void flush();
92 
93  bool open( const char* filename, bool clobber );
94 
95  bool isWritable()
96  {
97  return NULL != file_;
98  }
99 
100 protected:
101  FILE* file_;
104 
105 private:
106  // Note that the copy constructor below is private and not given a body.
107  // Any attempt to call it will return a compiler error.
108  FileIOStream( const FileIOStream& old ); // disallow copy constructor
110 };
111 
112 #endif /*FILEIOSTREAM_H_*/
bool autoClose_
Definition: FileIOStream.h:102
virtual bool eof()
Indicates if the end of file has been reached.
Definition: FileIOStream.cpp:57
void setFile(FILE *file)
Change the assoicated file.
Definition: FileIOStream.h:84
FILE * file_
Definition: FileIOStream.h:101
void setFile(FILE *file, const char *filename)
Change the assoicated file.
Definition: FileIOStream.h:45
This is a rather abstract class that can be implemented by classes that want to send and receive stre...
Definition: IOStream.h:30
virtual ~FileIOStream()
Definition: FileIOStream.cpp:28
const struct stat getStat()
Definition: FileIOStream.cpp:76
const char * getName()
returns name of the stream
Definition: FileIOStream.h:62
Wraps a c FILE* handle with an IOStream class.
Definition: FileIOStream.h:27
Mutex fileMutex_
Definition: FileIOStream.h:103
A simple pthread Mutex abstraction.
Definition: Mutex.h:20
void close()
Definition: FileIOStream.cpp:105
Contains the IOStream and NullIOStream class declarations.
void flush()
Definition: FileIOStream.cpp:115
virtual IOStream & read(char *buffer, size_t num)
reads num bytes from buffer to the output buffer/stream
Definition: FileIOStream.cpp:37
FileIOStream(FILE *file=NULL, bool autoClose=false)
Constructor.
Definition: FileIOStream.cpp:13
Replacement for standard template class string.
Definition: Str.h:12
virtual IOStream & write(const char *buffer)
writes zero-terminated buffer to the output buffer/stream
Definition: FileIOStream.h:78
int tell()
Definition: FileIOStream.cpp:95
const char * cStr() const
Definition: Str.h:188
const Str & getFilename()
Definition: FileIOStream.h:67
Contains the Mutex, ThreadCondition, and MutexLocker class declarations.
IOStream & write(const char *buffer, size_t num)
writes num bytes from buffer to the output buffer/stream
Definition: FileIOStream.cpp:85
bool open(const char *filename, bool clobber)
Definition: FileIOStream.cpp:124
bool isWritable()
indicates whether the stream can actually be written to.
Definition: FileIOStream.h:95
bool seek(unsigned int location)
Definition: FileIOStream.cpp:47
virtual void clearErr()
Definition: FileIOStream.cpp:67
Str filename_
Definition: FileIOStream.h:109
bool isReadable()
indicates whether the stream can actually be read from.
Definition: FileIOStream.h:57