LRAUV  revA
MappedIOStream.h
Go to the documentation of this file.
1 
10 #ifndef MAPPEDIOSTREAM_H_
11 #define MAPPEDIOSTREAM_H_
12 
13 #include "IOStream.h"
14 
15 #include <cstdio>
16 #include <sys/stat.h>
17 
27 class MappedIOStream : public IOStream
28 {
29 public:
30 
32  MappedIOStream( const Str& filename, bool clobber, size_t chunkSize );
33 
34  virtual ~MappedIOStream();
35 
36  void close();
37 
39  virtual IOStream& read( char* buffer, size_t num );
40 
41  bool seek( unsigned int location );
42 
43  virtual bool eof();
44 
45  bool isReadable()
46  {
47  return NULL != ptr_;
48  }
49 
50  const char* getName()
51  {
52  return filename_.cStr();
53  }
54 
55  const Str& getFilename()
56  {
57  return filename_;
58  }
59 
60  const struct stat getStat();
61 
63  IOStream& write( const char* buffer, size_t num );
64 
66  virtual IOStream& write( const char* buffer )
67  {
68  return write( buffer, strlen( buffer ) );
69  }
70 
71  int tell();
72 
73  void flush();
74 
75  bool open( bool clobber );
76 
77  bool isWritable()
78  {
79  return NULL != ptr_;
80  }
81 
82 protected:
83 
84  bool checkSize( size_t num );
85 
86  int file_;
88  size_t chunkSize_;
89  size_t size_;
90  unsigned char* ptr_;
91  size_t pos_; // for ftell and sequential output
92 
93 private:
94  // Note that the copy constructor below is private and not given a body.
95  // Any attempt to call it will return a compiler error.
96  MappedIOStream( const MappedIOStream& old ); // disallow copy constructor
97 };
98 
99 #endif /*MAPPEDIOSTREAM_H_*/
const Str & getFilename()
Definition: MappedIOStream.h:55
virtual IOStream & write(const char *buffer)
writes zero-terminated buffer to the output buffer/stream
Definition: MappedIOStream.h:66
This is a rather abstract class that can be implemented by classes that want to send and receive stre...
Definition: IOStream.h:30
bool seek(unsigned int location)
Definition: MappedIOStream.cpp:66
const char * getName()
returns name of the stream
Definition: MappedIOStream.h:50
virtual bool eof()
Indicates if the end of file has been reached.
Definition: MappedIOStream.cpp:75
size_t chunkSize_
Definition: MappedIOStream.h:88
virtual ~MappedIOStream()
Definition: MappedIOStream.cpp:32
size_t size_
Definition: MappedIOStream.h:89
Contains the IOStream and NullIOStream class declarations.
bool isWritable()
indicates whether the stream can actually be written to.
Definition: MappedIOStream.h:77
int tell()
Definition: MappedIOStream.cpp:103
const struct stat getStat()
Definition: MappedIOStream.cpp:84
size_t pos_
Definition: MappedIOStream.h:91
void close()
Definition: MappedIOStream.cpp:112
Replacement for standard template class string.
Definition: Str.h:12
int file_
Definition: MappedIOStream.h:86
const char * cStr() const
Definition: Str.h:188
Str filename_
Definition: MappedIOStream.h:87
bool open(bool clobber)
Definition: MappedIOStream.cpp:140
unsigned char * ptr_
Definition: MappedIOStream.h:90
bool isReadable()
indicates whether the stream can actually be read from.
Definition: MappedIOStream.h:45
virtual IOStream & read(char *buffer, size_t num)
reads num bytes from buffer to the output buffer/stream
Definition: MappedIOStream.cpp:38
void flush()
Definition: MappedIOStream.cpp:132
bool checkSize(size_t num)
Definition: MappedIOStream.cpp:49
IOStream & write(const char *buffer, size_t num)
writes num bytes from buffer to the output buffer/stream
Definition: MappedIOStream.cpp:92
Wraps Memory mapped file with an IOStream class.
Definition: MappedIOStream.h:27
MappedIOStream(const Str &filename, bool clobber, size_t chunkSize)
Constructor.
Definition: MappedIOStream.cpp:21