Loading...
Searching...
No Matches
null_file.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 NULL_FILE_HPP
#define NULL_FILE_HPP
#include "../my_config.h"
#include "generic_file.hpp"
#include "thread_cancellation.hpp"
namespace libdar
{
class null_file : public generic_file, public thread_cancellation
{
public :
null_file(gf_mode m) : generic_file(m) { set_offset(0); };
null_file(const null_file & ref) = default;
null_file(null_file && ref) noexcept = default;
null_file & operator = (const null_file & ref) = default;
null_file & operator = (null_file && ref) noexcept = default;
~null_file() = default;
virtual bool skippable(skippability direction, const infinint & amount) override { return true; };
virtual bool skip(const infinint &pos) override { set_offset(pos); return true; };
virtual bool skip_to_eof() override { offset = max_offset; return true; };
virtual bool skip_relative(signed int x) override { return set_rel_offset(x); };
virtual bool truncatable(const infinint & pos) const override { return true; };
virtual infinint get_position() const override { return offset; };
protected :
virtual void inherited_read_ahead(const infinint & amount) override {};
virtual U_I inherited_read(char *a, U_I size) override
{
#ifdef MUTEX_WORKS
check_self_cancellation();
#endif
return 0;
};
virtual void inherited_write(const char *a, U_I siz) override
{
#ifdef MUTEX_WORKS
check_self_cancellation();
#endif
set_offset(offset + siz);
};
virtual void inherited_truncate(const infinint & pos) override { if(pos < offset) offset = pos; };
virtual void inherited_sync_write() override {};
virtual void inherited_flush_read() override {};
virtual void inherited_terminate() override {};
private:
infinint offset;
infinint max_offset;
void set_offset(const infinint & x)
{
if(x > max_offset)
max_offset = x;
offset = x;
}
bool set_rel_offset(signed int x)
{
if(x >= 0)
{
set_offset(offset + x);
return true;
}
else // x < 0
{
infinint tmp = -x;
if(tmp > offset)
{
offset = 0;
return false;
}
else
{
offset -= tmp;
return true;
}
}
}
};
} // 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::null_file::inherited_truncate
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
Definition null_file.hpp:85
libdar::null_file::inherited_read_ahead
virtual void inherited_read_ahead(const infinint &amount) override
tells the object that several calls to read() will follow to probably obtain at least the given amoun...
Definition null_file.hpp:67
libdar::null_file::truncatable
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
Definition null_file.hpp:63
libdar::null_file::skip
virtual bool skip(const infinint &pos) override
skip at the absolute position
Definition null_file.hpp:60
libdar::null_file::inherited_write
virtual void inherited_write(const char *a, U_I siz) override
implementation of the write() operation
Definition null_file.hpp:77
libdar::null_file::inherited_flush_read
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
Definition null_file.hpp:87
libdar::null_file::get_position
virtual infinint get_position() const override
get the current read/write position
Definition null_file.hpp:64
libdar::null_file::inherited_read
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
Definition null_file.hpp:69
libdar::null_file::skip_to_eof
virtual bool skip_to_eof() override
skip to the end of file
Definition null_file.hpp:61
libdar::null_file::inherited_sync_write
virtual void inherited_sync_write() override
write down any pending data
Definition null_file.hpp:86
libdar::null_file::inherited_terminate
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
Definition null_file.hpp:88
libdar::null_file::skippable
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
Definition null_file.hpp:59
libdar::thread_cancellation::thread_cancellation
thread_cancellation()
the constructor
libdar::thread_cancellation::check_self_cancellation
void check_self_cancellation() const
Checkpoint test : whether the current libdar call must abort or not.
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
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
thread_cancellation.hpp
to be able to cancel libdar operation while running in a given thread.