Disk ARchive  2.7.15
Full featured and portable backup and archiving tool
null_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 
27 
28 #ifndef NULL_FILE_HPP
29 #define NULL_FILE_HPP
30 
31 #include "../my_config.h"
32 #include "generic_file.hpp"
33 #include "thread_cancellation.hpp"
34 
35 namespace libdar
36 {
37 
40 
42 
48 
50  {
51  public :
52  null_file(gf_mode m) : generic_file(m) { set_offset(0); };
53  null_file(const null_file & ref) = default;
54  null_file(null_file && ref) noexcept = default;
55  null_file & operator = (const null_file & ref) = default;
56  null_file & operator = (null_file && ref) noexcept = default;
57  ~null_file() = default;
58 
59  virtual bool skippable(skippability direction, const infinint & amount) override { return true; };
60  virtual bool skip(const infinint &pos) override { set_offset(pos); return true; };
61  virtual bool skip_to_eof() override { offset = max_offset; return true; };
62  virtual bool skip_relative(signed int x) override { return set_rel_offset(x); };
63  virtual bool truncatable(const infinint & pos) const override { return true; };
64  virtual infinint get_position() const override { return offset; };
65 
66  protected :
67  virtual void inherited_read_ahead(const infinint & amount) override {};
68 
69  virtual U_I inherited_read(char *a, U_I size) override
70  {
71 #ifdef MUTEX_WORKS
73 #endif
74  return 0;
75  };
76 
77  virtual void inherited_write(const char *a, U_I siz) override
78  {
79 #ifdef MUTEX_WORKS
81 #endif
82  set_offset(offset + siz);
83  };
84 
85  virtual void inherited_truncate(const infinint & pos) override { if(pos < offset) offset = pos; };
86  virtual void inherited_sync_write() override {};
87  virtual void inherited_flush_read() override {};
88  virtual void inherited_terminate() override {};
89 
90  private:
91  infinint offset;
92  infinint max_offset;
93 
94  void set_offset(const infinint & x)
95  {
96  if(x > max_offset)
97  max_offset = x;
98  offset = x;
99  }
100 
101  bool set_rel_offset(signed int x)
102  {
103  if(x >= 0)
104  {
105  set_offset(offset + x);
106  return true;
107  }
108  else // x < 0
109  {
110  infinint tmp = -x;
111  if(tmp > offset)
112  {
113  offset = 0;
114  return false;
115  }
116  else
117  {
118  offset -= tmp;
119  return true;
120  }
121  }
122  }
123 
124  };
125 
127 
128 } // end of namespace
129 
130 #endif
this is the interface class from which all other data transfer classes inherit
generic_file(gf_mode m)
main constructor
the arbitrary large positive integer class
the null_file class implements the /dev/null behavior
Definition: null_file.hpp:50
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
Definition: null_file.hpp:85
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
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
Definition: null_file.hpp:63
virtual bool skip(const infinint &pos) override
skip at the absolute position
Definition: null_file.hpp:60
virtual void inherited_write(const char *a, U_I siz) override
implementation of the write() operation
Definition: null_file.hpp:77
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
virtual infinint get_position() const override
get the current read/write position
Definition: null_file.hpp:64
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
Definition: null_file.hpp:69
virtual bool skip_to_eof() override
skip to the end of file
Definition: null_file.hpp:61
virtual void inherited_sync_write() override
write down any pending data
Definition: null_file.hpp:86
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
Definition: null_file.hpp:88
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
Definition: null_file.hpp:59
class to be used as parent to provide checkpoints to inherited classes
void check_self_cancellation() const
Checkpoint test : whether the current libdar call must abort or not.
class generic_file is defined here as well as class fichier
gf_mode
generic_file openning modes
Definition: gf_mode.hpp:44
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
to be able to cancel libdar operation while running in a given thread.