Disk ARchive  2.6.8
Full featured and portable backup and archiving tool
tronc.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2020 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 
28 
29 #ifndef TRONC_HPP
30 #define TRONC_HPP
31 
32 #include "../my_config.h"
33 #include "infinint.hpp"
34 #include "generic_file.hpp"
35 
36 namespace libdar
37 {
40 
42 
43  class tronc : public generic_file
44  {
45  public :
47 
52  tronc(generic_file *f, const infinint &offset, const infinint &size, bool own_f = false);
53  tronc(generic_file *f, const infinint &offset, const infinint &size, gf_mode mode, bool own_f = false);
54 
57  tronc(generic_file *f, const infinint &offset, bool own_f = false);
58  tronc(generic_file *f, const infinint &offset, gf_mode mode, bool own_f = false);
59 
60  tronc(const tronc & ref) = delete;
61  tronc(tronc && ref) noexcept = delete;
62  tronc & operator = (const tronc & ref) = delete;
63  tronc & operator = (tronc && ref) = delete;
64 
66  ~tronc() { detruit(); };
67 
69  void modify(const infinint & new_offset, const infinint & new_size);
71  void modify(const infinint & new_offset);
73  void modify() { modify(0); };
74 
76  virtual bool skippable(skippability direction, const infinint & amount) override;
78  virtual bool skip(const infinint & pos) override;
80  virtual bool skip_to_eof() override;
82  virtual bool skip_relative(S_I x) override;
84  virtual infinint get_position() const override { return current; };
85 
94 
95 
96  protected :
98  virtual void inherited_read_ahead(const infinint & amount) override;
100  virtual U_I inherited_read(char *a, U_I size) override;
102  virtual void inherited_write(const char *a, U_I size) override;
103  virtual void inherited_sync_write() override { ref->sync_write(); }
104  virtual void inherited_flush_read() override {};
105  virtual void inherited_terminate() override {if(own_ref) ref->terminate(); };
106 
107  private :
108  infinint start;
112  bool own_ref;
113  bool limited;
114  bool check_pos;
115 
116  void set_back_current_position();
117  void detruit() noexcept { if(own_ref && ref != nullptr) delete ref; };
118  };
119 
121 
122 } // end of namespace
123 
124 #endif
libdar::tronc::skip
virtual bool skip(const infinint &pos) override
inherited from generic_file
libdar::tronc::skippable
virtual bool skippable(skippability direction, const infinint &amount) override
inherited from generic_file
libdar::gf_mode
gf_mode
generic_file openning modes
Definition: gf_mode.hpp:43
libdar::tronc
makes a segment of a generic_file appear like a real generic_file
Definition: tronc.hpp:43
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:61
libdar::tronc::modify
void modify()
modify the tronc object to become transparent and allow unrestricted access to the underlyuing object
Definition: tronc.hpp:73
libdar::generic_file::sync_write
void sync_write()
write any pending data
libdar::tronc::get_position
virtual infinint get_position() const override
inherited from generic_file
Definition: tronc.hpp:84
libdar::tronc::tronc
tronc(generic_file *f, const infinint &offset, const infinint &size, bool own_f=false)
constructor
libdar::tronc::inherited_flush_read
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
Definition: tronc.hpp:104
libdar::tronc::start
infinint start
offset in the global generic file to start at
Definition: tronc.hpp:105
libdar::tronc::skip_relative
virtual bool skip_relative(S_I x) override
inherited from generic_file
generic_file.hpp
class generic_file is defined here as well as class fichier
libdar::tronc::check_pos
bool check_pos
whether to check and eventually adjust (seek) the position of the underlying layer at each read or wr...
Definition: tronc.hpp:114
libdar::tronc::own_ref
bool own_ref
whether we own ref (and must destroy it when no more needed)
Definition: tronc.hpp:112
libdar::tronc::current
infinint current
inside position of the next read or write
Definition: tronc.hpp:111
libdar::generic_file::terminate
void terminate()
destructor-like call, except that it is allowed to throw exceptions
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition: generic_file.hpp:76
libdar::tronc::check_underlying_position_while_reading_or_writing
void check_underlying_position_while_reading_or_writing(bool mode)
Definition: tronc.hpp:93
libdar::tronc::sz
infinint sz
length of the portion to consider
Definition: tronc.hpp:109
libdar::tronc::inherited_read_ahead
virtual void inherited_read_ahead(const infinint &amount) override
inherited from generic_file
libdar::tronc::~tronc
~tronc()
destructor
Definition: tronc.hpp:66
libdar::tronc::ref
generic_file * ref
global generic file of which to take a piece
Definition: tronc.hpp:110
libdar::tronc::inherited_terminate
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
Definition: tronc.hpp:105
libdar::tronc::skip_to_eof
virtual bool skip_to_eof() override
inherited from generic_file
libdar::tronc::inherited_read
virtual U_I inherited_read(char *a, U_I size) override
inherited from generic_file
libdar::tronc::inherited_write
virtual void inherited_write(const char *a, U_I size) override
inherited from generic_file
libdar::tronc::limited
bool limited
whether the sz argument is to be considered
Definition: tronc.hpp:113
libdar::tronc::inherited_sync_write
virtual void inherited_sync_write() override
write down any pending data
Definition: tronc.hpp:103
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:46