Disk ARchive  2.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
tronc.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 // $Id: tronc.hpp,v 1.22 2011/04/17 13:12:30 edrusb Rel $
22 //
23 /*********************************************************************/
24 
31 
32 #ifndef TRONC_HPP
33 #define TRONC_HPP
34 
35 #include "../my_config.h"
36 #include "infinint.hpp"
37 #include "generic_file.hpp"
38 
39 namespace libdar
40 {
43 
45 
46  class tronc : public generic_file
47  {
48  public :
50 
55  tronc(generic_file *f, const infinint &offset, const infinint &size, bool own_f = false);
56  tronc(generic_file *f, const infinint &offset, const infinint &size, gf_mode mode, bool own_f = false);
57 
60  tronc(generic_file *f, const infinint &offset, bool own_f = false);
61  tronc(generic_file *f, const infinint &offset, gf_mode mode, bool own_f = false);
62 
65  {
66  if(own_ref)
67  delete ref;
68  };
69 
71  bool skip(const infinint & pos);
73  bool skip_to_eof();
75  bool skip_relative(S_I x);
77  infinint get_position() { return current; };
78 
79  protected :
81  U_I inherited_read(char *a, U_I size);
83  void inherited_write(const char *a, U_I size);
84  void inherited_sync_write() { ref->sync_write(); }
85  void inherited_terminate() {if(own_ref) ref->terminate(); };
86 
87  private :
88  infinint start; //< offset in the global generic file to start at
89  infinint sz; //< length of the portion to consider
90  generic_file *ref; //< global generic file of which to take a piece
91  infinint current; //< inside position of the next read or write
92  bool own_ref; //< whether we own ref (and must destroy it when no more needed)
93  bool limited; //< whether the sz argument is to be considered
94 
95  void set_back_current_position();
96  };
97 
99 
100 } // end of namespace
101 
102 #endif