virtualseeker.h
Go to the documentation of this file.00001 #ifndef VIRTUALSEEKER_H
00002 #define VIRTUALSEEKER_H
00003
00004 #include "zipios-config.h"
00005
00006 #include "meta-iostreams.h"
00007
00008
00009 namespace zipios {
00010
00011 using std::ios ;
00012 using std::cerr ;
00013 using std::endl ;
00014
00020 class VirtualSeeker {
00021 public:
00022 inline VirtualSeeker( int start_offset = 0, int end_offset = 0) ;
00023 inline void setOffsets( int start_offset, int end_offset ) ;
00024 inline void getOffsets( int &start_offset, int &end_offset ) const ;
00025 inline int startOffset() const ;
00026 inline int endOffset() const ;
00027 inline void vseekg( istream &is, int offset, ios::seekdir sd ) const ;
00028 inline int vtellg( istream &is ) const ;
00029 private:
00030
00031 int _s_off, _e_off ;
00032 };
00033
00034
00035
00036 VirtualSeeker::VirtualSeeker( int start_offset, int end_offset )
00037 : _s_off( start_offset ),
00038 _e_off( end_offset )
00039 {}
00040
00041
00042 void VirtualSeeker::setOffsets( int start_offset, int end_offset ) {
00043 _s_off = start_offset ;
00044 _e_off = end_offset ;
00045 }
00046
00047
00048 void VirtualSeeker::getOffsets( int &start_offset, int &end_offset ) const {
00049 start_offset = _s_off ;
00050 end_offset = _e_off ;
00051 }
00052
00053
00054 int VirtualSeeker::startOffset() const {
00055 return _s_off ;
00056 }
00057
00058
00059 int VirtualSeeker::endOffset() const {
00060 return _e_off ;
00061 }
00062
00063 void VirtualSeeker::vseekg( istream &is, int offset, ios::seekdir sd ) const {
00064 if ( sd == ios::cur )
00065 is.seekg( offset, sd ) ;
00066 else if ( sd == ios::beg )
00067 is.seekg( offset + _s_off, sd ) ;
00068 else if ( sd == ios::end )
00069 is.seekg( offset - _e_off, sd ) ;
00070 else
00071 cerr << "VirtualSeekManager::seekg: error - not supposed to happen!" << endl ;
00072 }
00073
00074
00075 int VirtualSeeker::vtellg( istream &is ) const {
00076 return static_cast< int >( is.tellg() ) - _s_off ;
00077 }
00078
00079
00080 }
00081
00082 #endif
00083
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105