core/vil/vil_stream_core.h
Go to the documentation of this file.
00001 // This is core/vil/vil_stream_core.h
00002 #ifndef vil_stream_core_h_
00003 #define vil_stream_core_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief An in-core vil_stream implementation
00010 // \author  fsm
00011 
00012 #include <vcl_vector.h>
00013 #include <vil/vil_stream.h>
00014 
00015 //: An in-core vil_stream implementation.
00016 // This is an infinite stream - reads past the last point
00017 // written will succeed but will return garbage data.
00018 class vil_stream_core : public vil_stream
00019 {
00020   vil_streampos curpos_;       // current file pointer.
00021   unsigned blocksize_;
00022   vcl_vector<char*> block_;
00023   vil_streampos tailpos_; // size of file so far
00024 
00025  public:
00026   vil_stream_core(unsigned block_size = 16384);
00027 
00028   //: get current file size
00029   vil_streampos size() const { return tailpos_; }
00030 
00031   //: Read or write n bytes at position pos.
00032   // This does not change the current position.
00033   // When read=false, buf is actually a "char const *".
00034   vil_streampos m_transfer(char *buf, vil_streampos pos, vil_streampos n, bool read);
00035 
00036   // implement virtual vil_stream interface:
00037   bool ok() const { return true; }
00038   vil_streampos read (void       *buf, vil_streampos n);
00039   vil_streampos write(void const *buf, vil_streampos n);
00040   vil_streampos tell()     const    { return curpos_; }
00041   void seek(vil_streampos position) { curpos_ = position; }
00042 
00043   vil_streampos file_size() const { return tailpos_; }
00044 
00045  protected:
00046   ~vil_stream_core();
00047 };
00048 
00049 #endif // vil_stream_core_h_