secu_memory_file.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2023 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 SECU_MEMORY_FILE_HPP
#define SECU_MEMORY_FILE_HPP
#include "generic_file.hpp"
#include "storage.hpp"
#include "secu_string.hpp"
namespace libdar
{
class secu_memory_file : public generic_file
{
public:
// Constructors & Destructor
secu_memory_file(U_I storage_size) : generic_file(gf_read_write), data(storage_size) { position = 0; };
secu_memory_file(const secu_memory_file & ref) = default;
secu_memory_file(secu_memory_file && ref) noexcept = default;
secu_memory_file & operator = (const secu_memory_file & ref) = default;
secu_memory_file & operator = (secu_memory_file && ref) noexcept = default;
~secu_memory_file() = default;
// memory_storage specific methods
void reset(U_I size) { if(is_terminated()) throw SRC_BUG; position = 0; data.resize(size); };
infinint get_size() const { return data.get_size(); };
infinint get_allocated_size() const { return data.get_allocated_size(); };
void randomize(U_I size) { if(size > data.get_allocated_size()) reset(size); data.randomize(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 false; };
virtual infinint get_position() const override { if(is_terminated()) throw SRC_BUG; return position; };
const secu_string & get_contents() const { return data; };
protected:
// virtual method inherited from generic_file
virtual void inherited_read_ahead(const infinint & amount) override {};
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 { throw Efeature("truncate a secu_memory_file object"); };
virtual void inherited_sync_write() override {};
virtual void inherited_flush_read() override {};
virtual void inherited_terminate() override {};
private:
secu_string data;
U_I 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:327
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
secu_string.hpp
this file contains the definition of secu_string class, a std::string like class but allocated in sec...
storage.hpp
contains a class that permits arbitrary large data storage