Disk ARchive  2.7.15
Full featured and portable backup and archiving tool
generic_to_global_file.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 
30 
31 #ifndef GENERIC_TO_GLOBAL_FILE_HPP
32 #define GENERIC_TO_GLOBAL_FILE_HPP
33 
34 #include "fichier_global.hpp"
35 
36 namespace libdar
37 {
38 
41 
43 
45  {
46  public:
47 
49 
54  generic_to_global_file(const std::shared_ptr<user_interaction> & dialog,
55  generic_file *d,
56  gf_mode mode):
57  fichier_global(dialog, mode)
58  { if(d == nullptr) throw SRC_BUG; if(d->get_mode() != gf_read_write && d->get_mode() != mode) throw SRC_BUG; data = d; };
59 
60  generic_to_global_file(const generic_to_global_file & ref) = default;
61  generic_to_global_file(generic_to_global_file && ref) noexcept = default;
62  generic_to_global_file & operator = (const generic_to_global_file & ref) = default;
63  generic_to_global_file & operator = (generic_to_global_file && ref) noexcept = default;
64  ~generic_to_global_file() = default;
65 
66  // virtual method inherited from generic_file
67  virtual bool skippable(skippability direction, const infinint & amount) override { return data->skippable(direction, amount); }
68  virtual bool skip(const infinint & pos) override { return data->skip(pos); };
69  virtual bool skip_to_eof() override { return data->skip_to_eof(); };
70  virtual bool skip_relative(S_I x) override { return data->skip_relative(x); };
71  virtual bool truncatable(const infinint & pos) const override { return data->truncatable(pos); };
72  virtual infinint get_position() const override { return data->get_position(); };
73 
74 
75  // virtual method inherited from fichier_global
76  virtual void change_ownership(const std::string & user, const std::string & group) override {};
77  virtual void change_permission(U_I perm) override {};
78  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
79  virtual void fadvise(advise adv) const override {};
80 
81 
82  protected:
83 
84  // virtual method inherited from generic_file
85 
86  virtual void inherited_truncate(const infinint & pos) override { data->truncate(pos); };
87  virtual void inherited_read_ahead(const infinint & amount) override {}; // no optimization can be done here, we rely on the OS here
88  virtual void inherited_sync_write() override {};
89  virtual void inherited_flush_read() override {};
90  virtual void inherited_terminate() override {};
91 
92  // inherited from fichier_global
93  virtual U_I fichier_global_inherited_write(const char *a, U_I size) override { data->write(a, size); return size; };
94  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; };
95 
96  private:
97  generic_file *data;
98  };
99 
101 
102 } // end of namespace
103 
104 #endif
abstraction of filesystem files for entrepot
this is the interface class from which all other data transfer classes inherit
virtual void write(const char *a, U_I size) override
write data to the generic_file inherited from proto_generic_file
virtual bool truncatable(const infinint &pos) const =0
whether the implementation is able to truncate to the given position
virtual bool skip(const infinint &pos)=0
skip at the absolute position
virtual void truncate(const infinint &pos)
truncate file at the given offset
virtual bool skippable(skippability direction, const infinint &amount)=0
whether the implementation is able to skip
virtual infinint get_position() const =0
get the current read/write position
virtual bool skip_relative(S_I x)=0
skip relatively to the current position
virtual bool skip_to_eof()=0
skip to the end of file
gf_mode get_mode() const
retreive the openning mode for this object
virtual U_I read(char *a, U_I size) override
read data from the generic_file inherited from proto_generic_file
provides a fichier_global interface for any type of generic_file
virtual void change_ownership(const std::string &user, const std::string &group) override
set the ownership of the file
virtual bool skip_relative(S_I x) override
skip relatively to the current position
virtual infinint get_position() const override
get the current read/write position
virtual void fadvise(advise adv) const override
set posix_fadvise for the whole file
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
virtual void inherited_sync_write() override
write down any pending data
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
virtual void change_permission(U_I perm) override
change the permission of the file
generic_to_global_file(const std::shared_ptr< user_interaction > &dialog, generic_file *d, gf_mode mode)
Constructors & Destructor.
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
virtual infinint get_size() const override
return the size of the file
virtual bool skip_to_eof() override
skip to the end of file
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...
virtual bool skip(const infinint &pos) override
skip at the absolute position
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
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
the arbitrary large positive integer class
class fichier_global definition. This class is a pure virtual class class fichier_global is an abstra...
gf_mode
generic_file openning modes
Definition: gf_mode.hpp:44
@ gf_read_write
read and write access
Definition: gf_mode.hpp:47
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47