Disk ARchive  2.4.5
 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.2.1 2012/02/19 17:25:09 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 #ifdef LIBDAR_SPECIAL_ALLOC
80  USE_SPECIAL_ALLOC(tronc);
81 #endif
82  protected :
84  U_I inherited_read(char *a, U_I size);
86  void inherited_write(const char *a, U_I size);
87  void inherited_sync_write() { ref->sync_write(); }
88  void inherited_terminate() {if(own_ref) ref->terminate(); };
89 
90  private :
91  infinint start; //< offset in the global generic file to start at
92  infinint sz; //< length of the portion to consider
93  generic_file *ref; //< global generic file of which to take a piece
94  infinint current; //< inside position of the next read or write
95  bool own_ref; //< whether we own ref (and must destroy it when no more needed)
96  bool limited; //< whether the sz argument is to be considered
97 
98  void set_back_current_position();
99  };
100 
102 
103 } // end of namespace
104 
105 #endif