| Disk ARchive 2.8.1 Full featured and portable backup and archiving tool

Loading...
Searching...
No Matches
null_file.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2025 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
35namespace 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 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
72 check_self_cancellation();
73#endif
74 return 0;
75 };
76
77 virtual void inherited_write(const char *a, U_I siz) override
78 {
79#ifdef MUTEX_WORKS
80 check_self_cancellation();
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
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition generic_file.hpp:77
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
the null_file class implements the /dev/null behavior
Definition null_file.hpp:50
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
class to be used as parent to provide checkpoints to inherited classes
Definition thread_cancellation.hpp:69
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.