LRAUV  revA
FileInStream.h
Go to the documentation of this file.
1 
10 #ifndef FILEINSTREAM_H_
11 #define FILEINSTREAM_H_
12 
13 #include <cstdio>
14 
15 #include "InStream.h"
16 #include "utils/Mutex.h"
17 
26 class FileInStream : public InStream
27 {
28 public:
29 
31  FileInStream( FILE* file = NULL, bool autoClose = false );
32 
34  FileInStream( const char* filename );
35 
36  virtual ~FileInStream();
37 
38  void close();
39 
41  virtual InStream& read( char* buffer, size_t num );
42 
44  void setFile( FILE* file, const char* filename )
45  {
46  file_ = file;
47  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 
68 protected:
69  FILE* file_;
70  bool autoClose_;
72 
73 private:
74  // Note that the copy constructor below is private and not given a body.
75  // Any attempt to call it will return a compiler error.
76  FileInStream( const FileInStream& old ); // disallow copy constructor
78 };
79 
80 #endif /*FILEINSTREAM_H_*/
const char * getName()
returns name of the stream
Definition: FileInStream.h:62
bool isReadable()
indicates whether the stream can actually be read from.
Definition: FileInStream.h:57
FILE * file_
Definition: FileInStream.h:69
Wraps a c FILE* handle with an InStream class.
Definition: FileInStream.h:26
A simple pthread Mutex abstraction.
Definition: Mutex.h:20
virtual InStream & read(char *buffer, size_t num)
reads num bytes from buffer to the output buffer/stream
Definition: FileInStream.cpp:45
Str filename_
Definition: FileInStream.h:77
bool seek(unsigned int location)
Definition: FileInStream.cpp:55
This is a very abstract class that can be implemented by classes that want to receive stream input...
Definition: InStream.h:29
void setFile(FILE *file, const char *filename)
Change the assoicated file.
Definition: FileInStream.h:44
Mutex fileMutex_
Definition: FileInStream.h:71
Replacement for standard template class string.
Definition: Str.h:12
Contains the InStream and NullInStream class declarations.
const char * cStr() const
Definition: Str.h:188
void zeroTotalBytesRead()
Definition: InStream.h:211
Contains the Mutex, ThreadCondition, and MutexLocker class declarations.
FileInStream(FILE *file=NULL, bool autoClose=false)
Constructor.
Definition: FileInStream.cpp:12
virtual ~FileInStream()
Definition: FileInStream.cpp:26
virtual void clearErr()
Definition: FileInStream.cpp:75
bool autoClose_
Definition: FileInStream.h:70
void close()
Definition: FileInStream.cpp:34
virtual bool eof()
Indicates if the end of file has been reached.
Definition: FileInStream.cpp:65