Loading...
Searching...
No Matches
generic_to_global_file.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2024 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 GENERIC_TO_GLOBAL_FILE_HPP
#define GENERIC_TO_GLOBAL_FILE_HPP
#include "fichier_global.hpp"
namespace libdar
{
class generic_to_global_file : public fichier_global
{
public:
generic_to_global_file(const std::shared_ptr<user_interaction> & dialog,
generic_file *d,
gf_mode mode):
fichier_global(dialog, mode)
{ if(d == nullptr) throw SRC_BUG; if(d->get_mode() != gf_read_write && d->get_mode() != mode) throw SRC_BUG; data = d; };
generic_to_global_file(const generic_to_global_file & ref) = default;
generic_to_global_file(generic_to_global_file && ref) noexcept = default;
generic_to_global_file & operator = (const generic_to_global_file & ref) = default;
generic_to_global_file & operator = (generic_to_global_file && ref) noexcept = default;
~generic_to_global_file() = default;
// virtual method inherited from generic_file
virtual bool skippable(skippability direction, const infinint & amount) override { return data->skippable(direction, amount); }
virtual bool skip(const infinint & pos) override { return data->skip(pos); };
virtual bool skip_to_eof() override { return data->skip_to_eof(); };
virtual bool skip_relative(S_I x) override { return data->skip_relative(x); };
virtual bool truncatable(const infinint & pos) const override { return data->truncatable(pos); };
virtual infinint get_position() const override { return data->get_position(); };
// virtual method inherited from fichier_global
virtual void change_ownership(const std::string & user, const std::string & group) override {};
virtual void change_permission(U_I perm) override {};
virtual infinint get_size() const override { return data->get_position(); }; //< yes, this is the drawback of this template class convertion, get_size() does not return the real size of the object
virtual void fadvise(advise adv) const override {};
protected:
// virtual method inherited from generic_file
virtual void inherited_truncate(const infinint & pos) override { data->truncate(pos); };
virtual void inherited_read_ahead(const infinint & amount) override {}; // no optimization can be done here, we rely on the OS here
virtual void inherited_sync_write() override {};
virtual void inherited_flush_read() override {};
virtual void inherited_terminate() override {};
// inherited from fichier_global
virtual U_I fichier_global_inherited_write(const char *a, U_I size) override { data->write(a, size); return size; };
virtual bool fichier_global_inherited_read(char *a, U_I size, U_I & read, std::string & message) override { read = data->read(a, size); message = "THIS IS A BUG IN GENERIC_TO_GLOBAL_FILE, PLEASE REPORT TO THE MAINTAINER!"; return true; };
private:
generic_file *data;
};
} // end of namespace
#endif
libdar::fichier_global
abstraction of filesystem files for entrepot
Definition fichier_global.hpp:59
libdar::fichier_global::advise
advise
Definition fichier_global.hpp:62
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition generic_file.hpp:77
libdar::generic_file::write
virtual void write(const char *a, U_I size) override
write data to the generic_file inherited from proto_generic_file
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::skip
virtual bool skip(const infinint &pos)=0
skip at the absolute position
libdar::generic_file::truncate
virtual void truncate(const infinint &pos)
truncate file at the given offset
libdar::generic_file::skippable
virtual bool skippable(skippability direction, const infinint &amount)=0
whether the implementation is able to skip
libdar::generic_file::get_position
virtual infinint get_position() const =0
get the current read/write position
libdar::generic_file::skip_relative
virtual bool skip_relative(S_I x)=0
skip relatively to the current position
libdar::generic_file::skip_to_eof
virtual bool skip_to_eof()=0
skip to the end of file
libdar::generic_file::get_mode
gf_mode get_mode() const
retreive the openning mode for this object
Definition generic_file.hpp:109
libdar::generic_file::read
virtual U_I read(char *a, U_I size) override
read data from the generic_file inherited from proto_generic_file
libdar::generic_to_global_file
provides a fichier_global interface for any type of generic_file
Definition generic_to_global_file.hpp:45
libdar::generic_to_global_file::change_ownership
virtual void change_ownership(const std::string &user, const std::string &group) override
set the ownership of the file
Definition generic_to_global_file.hpp:76
libdar::generic_to_global_file::skip_relative
virtual bool skip_relative(S_I x) override
skip relatively to the current position
Definition generic_to_global_file.hpp:70
libdar::generic_to_global_file::get_position
virtual infinint get_position() const override
get the current read/write position
Definition generic_to_global_file.hpp:72
libdar::generic_to_global_file::fadvise
virtual void fadvise(advise adv) const override
set posix_fadvise for the whole file
Definition generic_to_global_file.hpp:79
libdar::generic_to_global_file::skippable
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
Definition generic_to_global_file.hpp:67
libdar::generic_to_global_file::inherited_sync_write
virtual void inherited_sync_write() override
write down any pending data
Definition generic_to_global_file.hpp:88
libdar::generic_to_global_file::inherited_truncate
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
Definition generic_to_global_file.hpp:86
libdar::generic_to_global_file::inherited_terminate
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
Definition generic_to_global_file.hpp:90
libdar::generic_to_global_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 generic_to_global_file.hpp:89
libdar::generic_to_global_file::change_permission
virtual void change_permission(U_I perm) override
change the permission of the file
Definition generic_to_global_file.hpp:77
libdar::generic_to_global_file::generic_to_global_file
generic_to_global_file(const std::shared_ptr< user_interaction > &dialog, generic_file *d, gf_mode mode)
Constructors & Destructor.
Definition generic_to_global_file.hpp:54
libdar::generic_to_global_file::truncatable
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
Definition generic_to_global_file.hpp:71
libdar::generic_to_global_file::get_size
virtual infinint get_size() const override
return the size of the file
Definition generic_to_global_file.hpp:78
libdar::generic_to_global_file::skip_to_eof
virtual bool skip_to_eof() override
skip to the end of file
Definition generic_to_global_file.hpp:69
libdar::generic_to_global_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 generic_to_global_file.hpp:87
libdar::generic_to_global_file::skip
virtual bool skip(const infinint &pos) override
skip at the absolute position
Definition generic_to_global_file.hpp:68
libdar::generic_to_global_file::fichier_global_inherited_read
virtual bool fichier_global_inherited_read(char *a, U_I size, U_I &read, std::string &message) override
replaces generic_file::inherited_read() method, to allow the return of partial reading
Definition generic_to_global_file.hpp:94
libdar::generic_to_global_file::fichier_global_inherited_write
virtual U_I fichier_global_inherited_write(const char *a, U_I size) override
replaces generic_file::inherited_write() method, to allow the return of partial writings
Definition generic_to_global_file.hpp:93
libdar::infinint
the arbitrary large positive integer class
Definition real_infinint.hpp:62
fichier_global.hpp
class fichier_global definition. This class is a pure virtual class class fichier_global is an abstra...
libdar::gf_mode
gf_mode
generic_file openning modes
Definition gf_mode.hpp:44
libdar::gf_read_write
@ gf_read_write
read and write access
Definition gf_mode.hpp:47
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47