Loading...
Searching...
No Matches
tronc.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2026 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef TRONC_HPP
#define TRONC_HPP
#include "../my_config.h"
#include "infinint.hpp"
#include "generic_file.hpp"
namespace libdar
{
class tronc : public generic_file
{
public :
tronc(generic_file *f, const infinint &offset, const infinint &size, bool own_f = false);
tronc(generic_file *f, const infinint &offset, const infinint &size, gf_mode mode, bool own_f = false);
tronc(generic_file *f, const infinint &offset, bool own_f = false);
tronc(generic_file *f, const infinint &offset, gf_mode mode, bool own_f = false);
tronc(const tronc & ref) = delete;
tronc(tronc && ref) noexcept = delete;
tronc & operator = (const tronc & ref) = delete;
tronc & operator = (tronc && ref) = delete;
~tronc() { detruit(); };
void modify(const infinint & new_offset, const infinint & new_size);
void modify(const infinint & new_offset);
void modify() { modify(0); };
virtual bool skippable(skippability direction, const infinint & amount) override;
virtual bool skip(const infinint & pos) override;
virtual bool skip_to_eof() override;
virtual bool skip_relative(S_I x) override;
virtual bool truncatable(const infinint & pos) const override { return ref->truncatable(start + pos); };
virtual infinint get_position() const override { return current; };
void check_underlying_position_while_reading_or_writing(bool mode) { check_pos = mode ; };
protected :
virtual void inherited_read_ahead(const infinint & amount) override;
virtual U_I inherited_read(char *a, U_I size) override;
virtual void inherited_write(const char *a, U_I size) override;
virtual void inherited_truncate(const infinint & pos) override;
virtual void inherited_sync_write() override { ref->sync_write(); }
virtual void inherited_flush_read() override {};
virtual void inherited_terminate() override {if(own_ref) ref->terminate(); };
private :
infinint start;
infinint sz;
generic_file *ref;
infinint current;
bool own_ref;
bool limited;
bool check_pos;
void set_back_current_position();
void detruit() noexcept { if(own_ref && ref != nullptr) delete ref; };
};
} // end of namespace
#endif
libdar::generic_file::generic_file
generic_file(gf_mode m)
main constructor
Definition generic_file.hpp:80
libdar::infinint
the arbitrary large positive integer class
Definition real_infinint.hpp:62
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