Loading...
Searching...
No Matches
memory_file.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2026 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef MEMORY_FILE_HPP
#define MEMORY_FILE_HPP
#include "generic_file.hpp"
#include "storage.hpp"
namespace libdar
{
class memory_file : public generic_file
{
public:
memory_file() : generic_file(gf_read_write), data(0) { position = 0; };
memory_file(const memory_file & ref) = default;
memory_file(memory_file && ref) noexcept = default;
memory_file & operator = (const memory_file & ref) = default;
memory_file & operator = (memory_file && ref) noexcept = default;
~memory_file() = default;
// memory_storage specific methods
void reset() { if(is_terminated()) throw SRC_BUG; position = 0; data = storage(0); };
infinint size() const { return data.size(); };
// virtual method inherited from generic_file
virtual bool skippable(skippability direction, const infinint & amount) override { return true; };
virtual bool skip(const infinint & pos) override;
virtual bool skip_to_eof() override;
virtual bool skip_relative(S_I x) override;
virtual bool truncatable(const infinint & pos) const override { return true; };
virtual infinint get_position() const override { if(is_terminated()) throw SRC_BUG; return position; };
protected:
// virtual method inherited from generic_file
virtual void inherited_read_ahead(const infinint & amount) override {}; // no optimization can be done here, we rely on the OS here
virtual U_I inherited_read(char *a, U_I size) override;
virtual void inherited_write(const char *a, U_I size) override;
virtual void inherited_truncate(const infinint & pos) override;
virtual void inherited_sync_write() override {};
virtual void inherited_flush_read() override {};
virtual void inherited_terminate() override {};
private:
storage data;
infinint position;
};
} // end of namespace
#endif
libdar::generic_file::generic_file
generic_file(gf_mode m)
main constructor
Definition generic_file.hpp:80
libdar::generic_file::is_terminated
bool is_terminated() const
Definition generic_file.hpp:328
libdar::infinint
the arbitrary large positive integer class
Definition real_infinint.hpp:62
libdar::memory_file
generic_file stored in memory
Definition memory_file.hpp:41
libdar::memory_file::inherited_terminate
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
Definition memory_file.hpp:76
libdar::memory_file::inherited_read
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
libdar::memory_file::skip
virtual bool skip(const infinint &pos) override
skip at the absolute position
libdar::memory_file::get_position
virtual infinint get_position() const override
get the current read/write position
Definition memory_file.hpp:64
libdar::memory_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 memory_file.hpp:70
libdar::memory_file::inherited_truncate
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
libdar::memory_file::truncatable
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
Definition memory_file.hpp:63
libdar::memory_file::memory_file
memory_file()
Constructors & Destructor.
Definition memory_file.hpp:45
libdar::memory_file::inherited_write
virtual void inherited_write(const char *a, U_I size) override
implementation of the write() operation
libdar::memory_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 memory_file.hpp:75
libdar::memory_file::skippable
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
Definition memory_file.hpp:59
libdar::memory_file::skip_relative
virtual bool skip_relative(S_I x) override
skip relatively to the current position
libdar::memory_file::inherited_sync_write
virtual void inherited_sync_write() override
write down any pending data
Definition memory_file.hpp:74
libdar::memory_file::skip_to_eof
virtual bool skip_to_eof() override
skip to the end of file
libdar::storage
arbitrary large storage structure
Definition storage.hpp:53
generic_file.hpp
class generic_file is defined here as well as class fichier
libdar::gf_read_write
@ gf_read_write
read and write access
Definition gf_mode.hpp:47
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47
storage.hpp
contains a class that permits arbitrary large data storage