Disk ARchive  2.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
fichier.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 // $Id: fichier.hpp,v 1.9 2011/04/17 13:12:29 edrusb Rel $
22 //
23 /*********************************************************************/
24 
28 
29 #ifndef FICHIER_HPP
30 #define FICHIER_HPP
31 
32 
33 #include "../my_config.h"
34 
35 extern "C"
36 {
37 #if HAVE_UNISTD_H
38 #include <unistd.h>
39 #endif
40 } // end extern "C"
41 
42 #include "integers.hpp"
43 #include "thread_cancellation.hpp"
44 #include "label.hpp"
45 #include "crc.hpp"
46 #include "user_interaction.hpp"
47 #include "mem_ui.hpp"
48 
49 #include <string>
50 
51 namespace libdar
52 {
53 
56 
57  class fichier : public generic_file, public thread_cancellation
58  {
59  public :
60  // constructors
61  fichier(user_interaction & dialog, S_I fd);
62  fichier(user_interaction & dialog, const char *name, gf_mode m, U_I mode, bool furtive_mode);
63  fichier(user_interaction & dialog, const std::string & chemin, gf_mode m, U_I mode, bool furtive_mode);
64  fichier(const std::string & chemin, bool furtive_mode = false); // builds a read-only object
65  fichier(const fichier & ref) : generic_file(ref) { copy_from(ref); };
66 
67  // assignment operator
68  const fichier & operator = (const fichier & ref) { detruit(); copy_from(ref); return *this; };
69 
70  // destructor
71  ~fichier() { detruit(); };
72 
73 
75  virtual void change_ownership(const std::string & user, const std::string & group);
76 
78  virtual void change_permission(U_I perm);
79 
81  infinint get_size() const;
82 
83  // inherited from generic_file
84  bool skip(const infinint & pos);
85  bool skip_to_eof();
86  bool skip_relative(S_I x);
87  infinint get_position();
88 
89  protected :
90  U_I inherited_read(char *a, U_I size);
91  void inherited_write(const char *a, U_I size);
92  void inherited_sync_write() {};
93  void inherited_terminate() {};
94 
95  private :
96  S_I filedesc;
97  user_interaction *x_dialog;
98 
99  void open(const char *name, gf_mode m, U_I perm, bool furtive_mode);
100  void copy_from(const fichier & ref);
101  void detruit() { close(filedesc); filedesc = -1; if(x_dialog != NULL) { delete x_dialog; x_dialog = NULL; } };
102  void init_dialog(user_interaction &dialog);
103  };
104 
106 
107 } // end of namespace
108 
109 #endif