| Disk ARchive 2.6.12 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-2020 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 : http://dar.linux.free.fr/email.html
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
49 class null_file : public generic_file, public thread_cancellation
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 infinint get_position() const override { return offset; };
64
65 protected :
66 virtual void inherited_read_ahead(const infinint & amount) override {};
67
68 virtual U_I inherited_read(char *a, U_I size) override
69 {
70 #ifdef MUTEX_WORKS
71 check_self_cancellation();
72 #endif
73 return 0;
74 };
75
76 virtual void inherited_write(const char *a, U_I siz) override
77 {
78 #ifdef MUTEX_WORKS
79 check_self_cancellation();
80 #endif
81 set_offset(offset + siz);
82 };
83
84 virtual void inherited_sync_write() override {};
85 virtual void inherited_flush_read() override {};
86 virtual void inherited_terminate() override {};
87
88 private:
89 infinint offset;
90 infinint max_offset;
91
92 void set_offset(const infinint & x)
93 {
94 if(x > max_offset)
95 max_offset = x;
96 offset = x;
97 }
98
99 bool set_rel_offset(signed int x)
100 {
101 if(x >= 0)
102 {
103 set_offset(offset + x);
104 return true;
105 }
106 else // x < 0
107 {
108 infinint tmp = -x;
109 if(tmp > offset)
110 {
111 offset = 0;
112 return false;
113 }
114 else
115 {
116 offset -= tmp;
117 return true;
118 }
119 }
120 }
121
122 };
123
125
126 } // end of namespace
127
128 #endif
libdar::generic_file::generic_file
generic_file(gf_mode m)
main constructor
Definition: generic_file.hpp:80
libdar::thread_cancellation::check_self_cancellation
void check_self_cancellation() const
Checkpoint test : whether the current libdar call must abort or not.
libdar::thread_cancellation
class to be used as parent to provide checkpoints to inherited classes
Definition: thread_cancellation.hpp:69
libdar::gf_mode
gf_mode
generic_file openning modes
Definition: gf_mode.hpp:44
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:62
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:85
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:86
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::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:66
libdar::null_file::skip_to_eof
virtual bool skip_to_eof() override
skip to the end of file
Definition: null_file.hpp:61
thread_cancellation.hpp
to be able to cancel libdar operation while running in a given thread.
generic_file.hpp
class generic_file is defined here as well as class fichier
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:76
libdar::null_file::skip
virtual bool skip(const infinint &pos) override
skip at the absolute position
Definition: null_file.hpp:60
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition: generic_file.hpp:77
libdar::null_file::inherited_read
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
Definition: null_file.hpp:68
libdar::null_file
the null_file class implements the /dev/null behavior
Definition: null_file.hpp:50
libdar::null_file::inherited_sync_write
virtual void inherited_sync_write() override
write down any pending data
Definition: null_file.hpp:84
libdar::null_file::get_position
virtual infinint get_position() const override
get the current read/write position
Definition: null_file.hpp:63
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47