Disk ARchive  2.6.8
Full featured and portable backup and archiving tool
secu_memory_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 
25 
26 #ifndef SECU_MEMORY_FILE_HPP
27 #define SECU_MEMORY_FILE_HPP
28 
29 #include "generic_file.hpp"
30 #include "storage.hpp"
31 #include "secu_string.hpp"
32 
33 namespace libdar
34 {
35 
38 
39  class secu_memory_file : public generic_file
40  {
41  public:
42 
43  // Constructors & Destructor
44  secu_memory_file(U_I storage_size) : generic_file(gf_read_write), data(storage_size) { position = 0; };
45  secu_memory_file(const secu_memory_file & ref) = default;
46  secu_memory_file(secu_memory_file && ref) noexcept = default;
47  secu_memory_file & operator = (const secu_memory_file & ref) = default;
48  secu_memory_file & operator = (secu_memory_file && ref) noexcept = default;
49  ~secu_memory_file() = default;
50 
51  // memory_storage specific methods
52 
54  void reset(U_I size) { if(is_terminated()) throw SRC_BUG; position = 0; data.resize(size); };
55 
57  infinint get_size() const { return data.get_size(); };
58 
60  infinint get_allocated_size() const { return data.get_allocated_size(); };
61 
63  void randomize(U_I size) { if(size > data.get_allocated_size()) reset(size); data.randomize(size); };
64 
65 
66  // virtual method inherited from generic_file
67  virtual bool skippable(skippability direction, const infinint & amount) override { return true; };
68  virtual bool skip(const infinint & pos) override;
69  virtual bool skip_to_eof() override;
70  virtual bool skip_relative(S_I x) override;
71  virtual infinint get_position() const override { if(is_terminated()) throw SRC_BUG; return position; };
72 
73  const secu_string & get_contents() const { return data; };
74 
75  protected:
76 
77  // virtual method inherited from generic_file
78  virtual void inherited_read_ahead(const infinint & amount) override {};
79  virtual U_I inherited_read(char *a, U_I size) override;
80  virtual void inherited_write(const char *a, U_I size) override;
81  virtual void inherited_sync_write() override {};
82  virtual void inherited_flush_read() override {};
83  virtual void inherited_terminate() override {};
84 
85  private:
86  secu_string data;
87  U_I position;
88  };
89 
91 
92 } // end of namespace
93 
94 #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:300
generic_file.hpp
class generic_file is defined here as well as class fichier
secu_string.hpp
this file contains the definition of secu_string class, a std::string like class but allocated in sec...
libdar::gf_read_write
read and write access
Definition: gf_mode.hpp:47
storage.hpp
contains a class that permits arbitrary large data storage
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:46