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_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.
18 class vil_stream_core : public vil_stream
19 {
20   vil_streampos curpos_{0}; // current file pointer.
21   unsigned blocksize_;
22   std::vector<char*> block_;
23   vil_streampos tailpos_{0}; // size of file so far
24 
25 public:
26   vil_stream_core(unsigned block_size = 16384);
27 
28   //: get current file size
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:
ok()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;
tell()40   vil_streampos tell()     const override    { return curpos_; }
seek(vil_streampos position)41   void seek(vil_streampos position) override { curpos_ = position; }
42 
file_size()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_
50