vil_stream_core.h
Go to the documentation of this file.
1 // This is core/vil/vil_stream_core.h
2 #ifndef vil_stream_core_h_
3 #define vil_stream_core_h_
4 //:
5 // \file
6 // \brief An in-core vil_stream implementation
7 // \author fsm
8 
9 #include <vector>
10 #ifdef _MSC_VER
11 # include <vcl_msvc_warnings.h>
12 #endif
13 #include <vil/vil_stream.h>
14 
15 //: An in-core vil_stream implementation.
16 // This is an infinite stream - reads past the last point
17 // written will succeed but will return garbage data.
19 {
20  vil_streampos curpos_; // current file pointer.
21  unsigned blocksize_;
22  std::vector<char*> block_;
23  vil_streampos tailpos_; // size of file so far
24 
25  public:
26  vil_stream_core(unsigned block_size = 16384);
27 
28  //: get current file size
29  vil_streampos size() const { return tailpos_; }
30 
31  //: Read or write n bytes at position pos.
32  // This does not change the current position.
33  // When read=false, buf is actually a "char const *".
34  vil_streampos m_transfer(char *buf, vil_streampos pos, vil_streampos n, bool read);
35 
36  // implement virtual vil_stream interface:
37  bool ok() const override { return true; }
38  vil_streampos read (void *buf, vil_streampos n) override;
39  vil_streampos write(void const *buf, vil_streampos n) override;
40  vil_streampos tell() const override { return curpos_; }
41  void seek(vil_streampos position) override { curpos_ = position; }
42 
43  vil_streampos file_size() const override { return tailpos_; }
44 
45  protected:
46  ~vil_stream_core() override;
47 };
48 
49 #endif // vil_stream_core_h_
Stream interface for VIL image loaders.
vil_streampos write(void const *buf, vil_streampos n) override
Write n bytes from buf. Returns number of bytes written.
vil_streampos read(void *buf, vil_streampos n) override
Read n bytes into buf. Returns number of bytes read.
void seek(vil_streampos position) override
Goto file pointer.
bool ok() const override
Return false if the stream is broken.
vil_streampos file_size() const override
Amount of data in the stream.
Stream interface for VIL image loaders.
Definition: vil_stream.h:21
vil_streampos tell() const override
Return file pointer.
vil_stream_core(unsigned block_size=16384)
vil_streampos curpos_
~vil_stream_core() override
vxl_int_32 vil_streampos
Definition: vil_stream.h:16
vil_streampos tailpos_
std::vector< char * > block_
vil_streampos size() const
get current file size.
vil_streampos m_transfer(char *buf, vil_streampos pos, vil_streampos n, bool read)
Read or write n bytes at position pos.
An in-core vil_stream implementation.