Disk ARchive 2.7.16
Full featured and portable backup and archiving tool
memory_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
25
26#ifndef MEMORY_FILE_HPP
27#define MEMORY_FILE_HPP
28
29#include "generic_file.hpp"
30#include "storage.hpp"
31
32namespace libdar
33{
34
37
39
41 {
42 public:
43
45 memory_file() : generic_file(gf_read_write), data(0) { position = 0; };
46 memory_file(const memory_file & ref) = default;
47 memory_file(memory_file && ref) noexcept = default;
48 memory_file & operator = (const memory_file & ref) = default;
49 memory_file & operator = (memory_file && ref) noexcept = default;
50 ~memory_file() = default;
51
52 // memory_storage specific methods
53
54 void reset() { if(is_terminated()) throw SRC_BUG; position = 0; data = storage(0); };
55 infinint size() const { return data.size(); };
56
57
58 // virtual method inherited from generic_file
59 virtual bool skippable(skippability direction, const infinint & amount) override { return true; };
60 virtual bool skip(const infinint & pos) override;
61 virtual bool skip_to_eof() override;
62 virtual bool skip_relative(S_I x) override;
63 virtual bool truncatable(const infinint & pos) const override { return true; };
64 virtual infinint get_position() const override { if(is_terminated()) throw SRC_BUG; return position; };
65
66
67 protected:
68
69 // virtual method inherited from generic_file
70 virtual void inherited_read_ahead(const infinint & amount) override {}; // no optimization can be done here, we rely on the OS here
71 virtual U_I inherited_read(char *a, U_I size) override;
72 virtual void inherited_write(const char *a, U_I size) override;
73 virtual void inherited_truncate(const infinint & pos) override;
74 virtual void inherited_sync_write() override {};
75 virtual void inherited_flush_read() override {};
76 virtual void inherited_terminate() override {};
77
78 private:
79 storage data;
80 infinint position;
81 };
82
84
85} // end of namespace
86
87#endif
this is the interface class from which all other data transfer classes inherit
bool is_terminated() const
the arbitrary large positive integer class
generic_file stored in memory
Definition: memory_file.hpp:41
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
Definition: memory_file.hpp:76
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
virtual bool skip(const infinint &pos) override
skip at the absolute position
virtual infinint get_position() const override
get the current read/write position
Definition: memory_file.hpp:64
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: memory_file.hpp:70
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
Definition: memory_file.hpp:63
memory_file()
Constructors & Destructor.
Definition: memory_file.hpp:45
virtual void inherited_write(const char *a, U_I size) override
implementation of the write() operation
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
Definition: memory_file.hpp:75
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
Definition: memory_file.hpp:59
virtual bool skip_relative(S_I x) override
skip relatively to the current position
virtual void inherited_sync_write() override
write down any pending data
Definition: memory_file.hpp:74
virtual bool skip_to_eof() override
skip to the end of file
arbitrary large storage structure
Definition: storage.hpp:53
class generic_file is defined here as well as class fichier
@ gf_read_write
read and write access
Definition: gf_mode.hpp:47
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
contains a class that permits arbitrary large data storage