1 #ifndef VIRTUALSEEKER_H
2 #define VIRTUALSEEKER_H
4 #include "zipios++/zipios-config.h"
6 #include "zipios++/meta-iostreams.h"
15 /** VirtualSeeker is a simple class that keeps track of a set of
16 specified 'virtual' file endings that mark a subset of a real
17 file. An example of its use (and its reason for existence) is to
18 keep track of the file endings of a Zip file embedded in another
22 inline VirtualSeeker( int start_offset = 0, int end_offset = 0) ;
23 inline void setOffsets( int start_offset, int end_offset ) ;
24 inline void getOffsets( int &start_offset, int &end_offset ) const ;
25 inline int startOffset() const ;
26 inline int endOffset() const ;
27 inline void vseekg( istream &is, int offset, ios::seekdir sd ) const ;
28 inline int vtellg( istream &is ) const ;
30 // start and end offsets
36 VirtualSeeker::VirtualSeeker( int start_offset, int end_offset )
37 : _s_off( start_offset ),
42 void VirtualSeeker::setOffsets( int start_offset, int end_offset ) {
43 _s_off = start_offset ;
48 void VirtualSeeker::getOffsets( int &start_offset, int &end_offset ) const {
49 start_offset = _s_off ;
54 int VirtualSeeker::startOffset() const {
59 int VirtualSeeker::endOffset() const {
63 void VirtualSeeker::vseekg( istream &is, int offset, ios::seekdir sd ) const {
65 is.seekg( offset, sd ) ;
66 else if ( sd == ios::beg )
67 is.seekg( offset + _s_off, sd ) ;
68 else if ( sd == ios::end )
69 is.seekg( offset - _e_off, sd ) ;
71 cerr << "VirtualSeekManager::seekg: error - not supposed to happen!" << endl ;
75 int VirtualSeeker::vtellg( istream &is ) const {
76 return static_cast< int >( is.tellg() ) - _s_off ;
85 Header file that defines VirtualSeeker.
89 Zipios++ - a small C++ library that provides easy access to .zip files.
90 Copyright (C) 2000 Thomas Søndergaard
92 This library is free software; you can redistribute it and/or
93 modify it under the terms of the GNU Lesser General Public
94 License as published by the Free Software Foundation; either
95 version 2 of the License, or (at your option) any later version.
97 This library is distributed in the hope that it will be useful,
98 but WITHOUT ANY WARRANTY; without even the implied warranty of
99 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
100 Lesser General Public License for more details.
102 You should have received a copy of the GNU Lesser General Public
103 License along with this library; if not, write to the Free Software
104 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA