]> git.donarmstrong.com Git - flightcrew.git/blob - src/zipios/zipios++/virtualseeker.h
Imported Upstream version 0.7.2+dfsg
[flightcrew.git] / src / zipios / zipios++ / virtualseeker.h
1 #ifndef VIRTUALSEEKER_H
2 #define VIRTUALSEEKER_H
3
4 #include "zipios++/zipios-config.h"
5
6 #include "zipios++/meta-iostreams.h"
7
8
9 namespace zipios {
10
11 using std::ios  ;
12 using std::cerr ;
13 using std::endl ;
14
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
19     file. */
20 class VirtualSeeker {
21 public:
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 ;
29 private:
30   // start and end offsets
31   int _s_off, _e_off ;
32 };
33
34
35
36 VirtualSeeker::VirtualSeeker( int start_offset, int end_offset ) 
37   : _s_off( start_offset ),
38     _e_off( end_offset   )
39 {}
40
41
42 void VirtualSeeker::setOffsets( int start_offset, int end_offset ) {
43   _s_off = start_offset ;
44   _e_off = end_offset   ;
45 }
46
47
48 void VirtualSeeker::getOffsets( int &start_offset, int &end_offset ) const {
49   start_offset = _s_off ;
50   end_offset   = _e_off ;
51 }
52
53
54 int VirtualSeeker::startOffset() const {
55   return _s_off ;
56 }
57
58
59 int VirtualSeeker::endOffset() const {
60   return _e_off ;
61 }
62
63 void VirtualSeeker::vseekg( istream &is, int offset, ios::seekdir sd ) const {
64   if ( sd == ios::cur )
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 ) ;
70   else 
71     cerr << "VirtualSeekManager::seekg: error - not supposed to happen!" << endl ;
72 }
73
74
75 int  VirtualSeeker::vtellg( istream &is ) const {
76   return static_cast< int >( is.tellg() ) - _s_off ;
77 }
78
79
80 } // namespace
81
82 #endif
83
84 /** \file 
85     Header file that defines VirtualSeeker.
86 */
87
88 /*
89   Zipios++ - a small C++ library that provides easy access to .zip files.
90   Copyright (C) 2000  Thomas Søndergaard
91   
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.
96   
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.
101   
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
105 */