00001 // This is core/vil1/vil1_stream_section.h 00002 #ifndef vil1_stream_section_h_ 00003 #define vil1_stream_section_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief make a section of a vil1_stream behave like a vil1_stream 00010 // \author fsm 00011 00012 #include <vil1/vil1_stream.h> 00013 00014 //: make a section of a vil1_stream behave like a vil1_stream. 00015 // 00016 // It is possible to have multiple vil1_stream_sections using the same 00017 // underlying stream simultaneously. This is accomplished by keeping 00018 // a note of the current position and seeking a lot. 00019 // 00020 // Note however that this is *not* threadsafe. 00021 struct vil1_stream_section : public vil1_stream 00022 { 00023 //: 00024 // skip to position 'begin' in underlying stream and translate seeks, 00025 // reads and writes relative to that position into seeks, reads and 00026 // writes in the underlying stream. 00027 vil1_stream_section(vil1_stream *underlying, int begin); 00028 00029 //: 00030 // as above, but will not allow seeks, reads or writes past 'end'. 00031 vil1_stream_section(vil1_stream *underlying, int begin, int end); 00032 00033 // implement virtual vil1_stream interface: 00034 bool ok() const { return underlying_->ok(); } 00035 vil1_streampos write(void const* buf, vil1_streampos n); 00036 vil1_streampos read(void* buf, vil1_streampos n); 00037 vil1_streampos tell() const { return current_; } // regardless of what the underlying stream is doing. 00038 void seek(vil1_streampos position); 00039 00040 protected: 00041 ~vil1_stream_section(); 00042 00043 private: 00044 vil1_stream *underlying_; 00045 vil1_streampos begin_; 00046 vil1_streampos end_; 00047 vil1_streampos current_; 00048 }; 00049 00050 #endif // vil1_stream_section_h_
1.5.1