Disk ARchive 2.7.16
Full featured and portable backup and archiving tool
Loading...
Searching...
No Matches
tronc.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2024 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, see the AUTHOR file
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
36namespace 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 bool truncatable(const infinint & pos) const override { return ref->truncatable(start + pos); };
85 virtual infinint get_position() const override { return current; };
86
95
96
97 protected :
99 virtual void inherited_read_ahead(const infinint & amount) override;
101 virtual U_I inherited_read(char *a, U_I size) override;
103 virtual void inherited_write(const char *a, U_I size) override;
104 virtual void inherited_truncate(const infinint & pos) override;
105 virtual void inherited_sync_write() override { ref->sync_write(); }
106 virtual void inherited_flush_read() override {};
107 virtual void inherited_terminate() override {if(own_ref) ref->terminate(); };
108
109 private :
114 bool own_ref;
115 bool limited;
117
118 void set_back_current_position();
119 void detruit() noexcept { if(own_ref && ref != nullptr) delete ref; };
120 };
121
123
124} // end of namespace
125
126#endif
this is the interface class from which all other data transfer classes inherit
virtual bool truncatable(const infinint &pos) const =0
whether the implementation is able to truncate to the given position
void terminate()
destructor-like call, except that it is allowed to throw exceptions
void sync_write()
write any pending data
the arbitrary large positive integer class
makes a segment of a generic_file appear like a real generic_file
Definition tronc.hpp:44
virtual void inherited_write(const char *a, U_I size) override
inherited from generic_file
bool check_pos
whether to check and eventually adjust (seek) the position of the underlying layer at each read or wr...
Definition tronc.hpp:116
void modify(const infinint &new_offset)
modify the tronc object to zoom on another (size unlimited) portion of the underlying object
virtual U_I inherited_read(char *a, U_I size) override
inherited from generic_file
~tronc()
destructor
Definition tronc.hpp:66
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
Definition tronc.hpp:107
virtual bool truncatable(const infinint &pos) const override
inherited from generic_file
Definition tronc.hpp:84
void modify()
modify the tronc object to become transparent and allow unrestricted access to the underlyuing object
Definition tronc.hpp:73
tronc(generic_file *f, const infinint &offset, const infinint &size, bool own_f=false)
constructor
infinint current
inside position of the next read or write
Definition tronc.hpp:113
virtual infinint get_position() const override
get the current read/write position
Definition tronc.hpp:85
virtual void inherited_read_ahead(const infinint &amount) override
inherited from generic_file
bool own_ref
whether we own ref (and must destroy it when no more needed)
Definition tronc.hpp:114
generic_file * ref
global generic file of which to take a piece
Definition tronc.hpp:112
infinint start
offset in the global generic file to start at
Definition tronc.hpp:110
void modify(const infinint &new_offset, const infinint &new_size)
modify the tronc object to zoom on another (size limited) portion of the underlying object
virtual bool skip(const infinint &pos) override
inherited from generic_file
infinint sz
length of the portion to consider
Definition tronc.hpp:111
void check_underlying_position_while_reading_or_writing(bool mode)
Definition tronc.hpp:94
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
virtual bool skip_to_eof() override
inherited from generic_file
virtual bool skip_relative(S_I x) override
inherited from generic_file
virtual void inherited_sync_write() override
write down any pending data
Definition tronc.hpp:105
bool limited
whether the sz argument is to be considered
Definition tronc.hpp:115
virtual bool skippable(skippability direction, const infinint &amount) override
inherited from generic_file
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
Definition tronc.hpp:106
tronc(generic_file *f, const infinint &offset, bool own_f=false)
class generic_file is defined here as well as class fichier
gf_mode
generic_file openning modes
Definition gf_mode.hpp:44
switch module to limitint (32 ou 64 bits integers) or infinint
include macro defined by the configure script and some specific additional ones
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47