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   // start and end offsets
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 } // namespace
00081 
00082 #endif
00083 
00088 /*
00089   Zipios++ - a small C++ library that provides easy access to .zip files.
00090   Copyright (C) 2000  Thomas Søndergaard
00091   
00092   This library is free software; you can redistribute it and/or
00093   modify it under the terms of the GNU Lesser General Public
00094   License as published by the Free Software Foundation; either
00095   version 2 of the License, or (at your option) any later version.
00096   
00097   This library is distributed in the hope that it will be useful,
00098   but WITHOUT ANY WARRANTY; without even the implied warranty of
00099   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00100   Lesser General Public License for more details.
00101   
00102   You should have received a copy of the GNU Lesser General Public
00103   License along with this library; if not, write to the Free Software
00104   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00105 */

Generated on Wed Nov 23 19:01:02 2011 for FreeCAD by  doxygen 1.6.1