Disk ARchive  2.4.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
string_file.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 
25 
26 #ifndef STRING_FILE_HPP
27 #define STRING_FILE_HPP
28 
29 #include "../my_config.h"
30 #include "infinint.hpp"
31 #include "generic_file.hpp"
32 #include "integers.hpp"
33 #include "erreurs.hpp"
34 
35 namespace libdar
36 {
37 
39 
41  class string_file : public generic_file
42  {
43  public:
44 
46  string_file(const std::string & contents): generic_file(gf_read_only) { data = contents; cur = 0; len = data.size(); };
47 
48  // inherited from generic_file
49  bool skip(const infinint & pos);
50  bool skip_to_eof() { cur = len; return true; };
51  bool skip_relative(S_I x);
52  infinint get_position() { return cur; };
53 
54 #ifdef LIBDAR_SPECIAL_ALLOC
55  USE_SPECIAL_ALLOC(string_file);
56 #endif
57  protected:
58  // inherited from generic_file
59  U_I inherited_read(char *a, U_I size);
60  void inherited_write(const char *a, U_I size) { throw Efeature("Writing on a string_file is not allowed"); };
63 
64  private:
65  std::string data;
66  infinint cur;
67  infinint len;
68  };
69 
70 } // end of namespace
71 
72 #endif
void inherited_sync_write()
write down any pending data
Definition: string_file.hpp:61
are defined here basic integer types that tend to be portable
infinint get_position()
get the current read/write position
Definition: string_file.hpp:52
class generic_file is defined here as well as class fichierthe generic_file interface is widely used ...
bool skip_to_eof()
skip to the end of file
Definition: string_file.hpp:50
bool skip_relative(S_I x)
skip relatively to the current position
class string_file emulates a generic_file frome a std::string
Definition: string_file.hpp:41
void inherited_terminate()
destructor-like call, except that it is allowed to throw exceptions
Definition: string_file.hpp:62
exception used when a requested feature is not (yet) implemented
Definition: erreurs.hpp:199
contains all the excetion class thrown by libdar
switch module to limitint (32 ou 64 bits integers) or infinint
bool skip(const infinint &pos)
skip at the absolute position
void inherited_write(const char *a, U_I size)
implementation of the write() operation
Definition: string_file.hpp:60
this is the interface class from which all other data transfer classes inherit
the arbitrary large positive integer class
read only access
U_I inherited_read(char *a, U_I size)
implementation of read() operation
string_file(const std::string &contents)
constructor
Definition: string_file.hpp:46