vil_stream_section.h
Go to the documentation of this file.
1 // This is core/vil/vil_stream_section.h
2 #ifndef vil_stream_section_h_
3 #define vil_stream_section_h_
4 //:
5 // \file
6 // \brief make a section of a vil_stream behave like a vil_stream
7 // \author fsm
8 
9 #include <vil/vil_stream.h>
10 
11 //: make a section of a vil_stream behave like a vil_stream.
12 //
13 // It is possible to have multiple vil_stream_sections using the same
14 // underlying stream simultaneously. This is accomplished by keeping
15 // a note of the current position and seeking a lot.
16 //
17 // Note however that this is \e not threadsafe.
19 {
20  //:
21  // skip to position 'begin' in underlying stream and translate seeks,
22  // reads and writes relative to that position into seeks, reads and
23  // writes in the underlying stream.
24  vil_stream_section(vil_stream *underlying, int begin);
25 
26  //:
27  // as above, but will not allow seeks, reads or writes past 'end'.
28  vil_stream_section(vil_stream *underlying, int begin, int end);
29 
30  // implement virtual vil_stream interface:
31  bool ok() const override { return underlying_->ok(); }
32  vil_streampos write(void const* buf, vil_streampos n) override;
33  vil_streampos read(void* buf, vil_streampos n) override;
34  vil_streampos tell() const override { return current_; } // regardless of what the underlying stream is doing.
35  void seek(vil_streampos position) override;
36 
37  vil_streampos file_size() const override;
38 
39  protected:
40  ~vil_stream_section() override;
41 
42  private:
47 };
48 
49 #endif // vil_stream_section_h_
vil_streampos current_
Stream interface for VIL image loaders.
vil_streampos read(void *buf, vil_streampos n) override
Read n bytes into buf. Returns number of bytes read.
vil_streampos tell() const override
Return file pointer.
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.
Stream interface for VIL image loaders.
Definition: vil_stream.h:21
make a section of a vil_stream behave like a vil_stream.
vil_stream * underlying_
vil_stream_section(vil_stream *underlying, int begin)
skip to position 'begin' in underlying stream and translate seeks, reads and writes relative to that ...
virtual bool ok() const =0
Return false if the stream is broken.
vxl_int_32 vil_streampos
Definition: vil_stream.h:16
bool ok() const override
Return false if the stream is broken.
void seek(vil_streampos position) override
Goto file pointer.