| Disk ARchive 2.7.19 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-2025 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
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 bool truncatable(const infinint & pos) const override { return ref->truncatable(start + pos); };
85 virtual infinint get_position() const override { return current; };
86
94 void check_underlying_position_while_reading_or_writing(bool mode) { check_pos = mode ; };
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 :
110 infinint start;
111 infinint sz;
112 generic_file *ref;
113 infinint current;
114 bool own_ref;
115 bool limited;
116 bool check_pos;
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
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition generic_file.hpp:77
libdar::generic_file::truncatable
virtual bool truncatable(const infinint &pos) const =0
whether the implementation is able to truncate to the given position
libdar::generic_file::terminate
void terminate()
destructor-like call, except that it is allowed to throw exceptions
libdar::generic_file::sync_write
void sync_write()
write any pending data
libdar::infinint
the arbitrary large positive integer class
Definition real_infinint.hpp:62
libdar::tronc
makes a segment of a generic_file appear like a real generic_file
Definition tronc.hpp:44
libdar::tronc::inherited_write
virtual void inherited_write(const char *a, U_I size) override
inherited from generic_file
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:116
libdar::tronc::modify
void modify(const infinint &new_offset)
modify the tronc object to zoom on another (size unlimited) portion of the underlying object
libdar::tronc::inherited_read
virtual U_I inherited_read(char *a, U_I size) override
inherited from generic_file
libdar::tronc::~tronc
~tronc()
destructor
Definition tronc.hpp:66
libdar::tronc::inherited_terminate
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
Definition tronc.hpp:107
libdar::tronc::truncatable
virtual bool truncatable(const infinint &pos) const override
inherited from generic_file
Definition tronc.hpp:84
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::tronc::tronc
tronc(generic_file *f, const infinint &offset, const infinint &size, bool own_f=false)
constructor
libdar::tronc::current
infinint current
inside position of the next read or write
Definition tronc.hpp:113
libdar::tronc::get_position
virtual infinint get_position() const override
get the current read/write position
Definition tronc.hpp:85
libdar::tronc::inherited_read_ahead
virtual void inherited_read_ahead(const infinint &amount) override
inherited from generic_file
libdar::tronc::own_ref
bool own_ref
whether we own ref (and must destroy it when no more needed)
Definition tronc.hpp:114
libdar::tronc::ref
generic_file * ref
global generic file of which to take a piece
Definition tronc.hpp:112
libdar::tronc::start
infinint start
offset in the global generic file to start at
Definition tronc.hpp:110
libdar::tronc::modify
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
libdar::tronc::skip
virtual bool skip(const infinint &pos) override
inherited from generic_file
libdar::tronc::sz
infinint sz
length of the portion to consider
Definition tronc.hpp:111
libdar::tronc::check_underlying_position_while_reading_or_writing
void check_underlying_position_while_reading_or_writing(bool mode)
Definition tronc.hpp:94
libdar::tronc::inherited_truncate
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
libdar::tronc::skip_to_eof
virtual bool skip_to_eof() override
inherited from generic_file
libdar::tronc::skip_relative
virtual bool skip_relative(S_I x) override
inherited from generic_file
libdar::tronc::inherited_sync_write
virtual void inherited_sync_write() override
write down any pending data
Definition tronc.hpp:105
libdar::tronc::limited
bool limited
whether the sz argument is to be considered
Definition tronc.hpp:115
libdar::tronc::skippable
virtual bool skippable(skippability direction, const infinint &amount) override
inherited from generic_file
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:106
libdar::tronc::tronc
tronc(generic_file *f, const infinint &offset, bool own_f=false)
generic_file.hpp
class generic_file is defined here as well as class fichier
libdar::gf_mode
gf_mode
generic_file openning modes
Definition gf_mode.hpp:44
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
my_config.h
include macro defined by the configure script and some specific additional ones
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47