vil_stream_fstream.h
Go to the documentation of this file.
1 // This is core/vil/vil_stream_fstream.h
2 #ifndef vil_stream_fstream_h_
3 #define vil_stream_fstream_h_
4 
5 #include <fstream>
6 #ifdef VIL_USE_FSTREAM64
8 #endif //VIL_USE_FSTREAM64
9 
10 //:
11 // \file
12 // \brief A vil_stream implementation using std::fstream
13 // \author awf@robots.ox.ac.uk
14 // \date 16 Feb 00
15 
16 #ifdef _MSC_VER
17 # include <vcl_msvc_warnings.h>
18 #endif
19 #include <vil/vil_stream.h>
20 #include <vxl_config.h>
21 
22 //: A vil_stream implementation using std::fstream
24 {
25  public:
26  vil_stream_fstream(char const* filename, char const* mode);
27 
28 #if defined(_WIN32) && VXL_USE_WIN_WCHAR_T
29  vil_stream_fstream(wchar_t const* filename, char const* mode);
30 #endif
31 
32  // implement virtual vil_stream interface:
33  bool ok() const override { return f_.good(); }
34  vil_streampos write(void const* buf, vil_streampos n) override;
35  vil_streampos read(void* buf, vil_streampos n) override;
36  vil_streampos tell() const override;
37  void seek(vil_streampos position) override;
38 
39  vil_streampos file_size() const override;
40 
41  protected:
42  ~vil_stream_fstream() override;
43 
44  // There are a (very few) occasions when access to the underlying stream is useful
45  std::fstream & underlying_stream() {return f_;}
46  private:
47  std::ios::openmode flags_;
48  mutable std::fstream f_;
49  int id_;
51 };
52 
53 #endif // vil_stream_fstream_h_
Stream interface for VIL image loaders.
std::ios::openmode flags_
vil_streampos file_size() const override
Amount of data in the stream.
vil_streampos write(void const *buf, vil_streampos n) override
Write n bytes from buf. Returns number of bytes written.
vil_streampos tell() const override
Return file pointer.
A vil_stream implementation using std::fstream.
vil_streampos read(void *buf, vil_streampos n) override
Read n bytes into buf. Returns number of bytes read.
Stream interface for VIL image loaders.
Definition: vil_stream.h:21
bool ok() const override
Return false if the stream is broken.
vxl_int_32 vil_streampos
Definition: vil_stream.h:16
void seek(vil_streampos position) override
Goto file pointer.
std::fstream & underlying_stream()
vil_stream_fstream(char const *filename, char const *mode)