| Disk ARchive 2.5.10 Full featured and portable backup and archiving tool

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

mask.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
28
29 #ifndef MASK_HPP
30 #define MASK_HPP
31
32 #include "../my_config.h"
33
34 extern "C"
35 {
36 #if HAVE_UNISTD_H
37 #include <unistd.h>
38 #endif
39
40 #if HAVE_REGEX_H
41 #include <regex.h>
42 #endif
43 } // end extern "C"
44
45 #include <string>
46 #include <vector>
47
48 #include "path.hpp"
49 #include "on_pool.hpp"
50
51 namespace libdar
52 {
53
56
58
61 class mask : public on_pool
62 {
63 public :
64 virtual ~mask() {};
65
67
71 virtual bool is_covered(const std::string &expression) const = 0;
72
74
79 virtual bool is_covered(const path & chemin) const { return is_covered(chemin.display()); };
80
83 virtual mask *clone() const = 0;
84 };
85
86
88
90 class bool_mask : public mask
91 {
92 public :
94
98 bool_mask(bool always) { val = always; };
99
101 bool is_covered(const std::string & expression) const { return val; };
102 bool is_covered(const path & chemin) const { return val; };
103
105 mask *clone() const { return new (get_pool()) bool_mask(val); };
106
107 private :
108 bool val;
109 };
110
111
113
114 class simple_mask : public mask
115 {
116 public :
117
119
122 simple_mask(const std::string & wilde_card_expression, bool case_sensit);
124 simple_mask(const simple_mask & m) : mask(m) { copy_from(m); };
126 const simple_mask & operator = (const simple_mask & m);
127
129 bool is_covered(const std::string &expression) const;
130
132 mask *clone() const { return new (get_pool()) simple_mask(*this); };
133
134 private :
135 std::string the_mask;
136 bool case_s;
137
138 void copy_from(const simple_mask & m);
139 };
140
141
143
144 class regular_mask : public mask
145 {
146 public :
147
149
152 regular_mask(const std::string & wilde_card_expression,
153 bool x_case_sensit);
155 regular_mask(const regular_mask & ref);
157 regular_mask & operator= (const regular_mask & ref);
158
160 virtual ~regular_mask() { regfree(&preg); };
161
163 bool is_covered(const std::string & expression) const;
164
166 mask *clone() const { return new (get_pool()) regular_mask(*this); };
167
168 private :
169 regex_t preg;
170 std::string mask_exp; //< used only by the copy constructor
171 bool case_sensit; //< used only by the copy constructor
172
173 void set_preg(const std::string & wilde_card_expression,
174 bool x_case_sensit);
175 };
176
177
179
182 class not_mask : public mask
183 {
184 public :
186
190 not_mask(const mask &m) { copy_from(m); };
192 not_mask(const not_mask & m) : mask(m) { copy_from(m); };
194 const not_mask & operator = (const not_mask & m);
196 ~not_mask() { detruit(); };
197
199 bool is_covered(const std::string &expression) const { return !ref->is_covered(expression); };
200 bool is_covered(const path & chemin) const { return !ref->is_covered(chemin); };
201
203 mask *clone() const { return new (get_pool()) not_mask(*this); };
204
205 private :
206 mask *ref;
207
208 void copy_from(const not_mask &m);
209 void copy_from(const mask &m);
210 void detruit();
211 };
212
213
215
216 class et_mask : public mask
217 {
218 public :
219
221
225 et_mask() {};
227 et_mask(const et_mask &m) : mask(m) { copy_from(m); };
229 const et_mask & operator = (const et_mask &m);
231 ~et_mask() { detruit(); };
232
233
235
239 void add_mask(const mask & toadd);
240
242 bool is_covered(const std::string & expression) const { return t_is_covered(expression); };
243 bool is_covered(const path & chemin) const { return t_is_covered(chemin); };
244
246 mask *clone() const { return new (get_pool()) et_mask(*this); };
247
249
252 U_I size() const { return lst.size(); };
253
255
259 void clear() { detruit(); };
260
261 protected :
262 std::vector<mask *> lst;
263
264 private :
265 void copy_from(const et_mask & m);
266 void detruit();
267
268 template<class T> bool t_is_covered(const T & expression) const
269 {
270 std::vector<mask *>::const_iterator it = lst.begin();
271
272 if(lst.empty())
273 throw Erange("et_mask::is_covered", dar_gettext("No mask in the list of mask to operate on"));
274
275 while(it != lst.end() && (*it)->is_covered(expression))
276 ++it;
277
278 return it == lst.end();
279 }
280
281 };
282
283
285
290 class ou_mask : public et_mask
291 {
292 public:
294 bool is_covered(const std::string & expression) const { return t_is_covered(expression); };
295 bool is_covered(const path & chemin) const { return t_is_covered(chemin); }
296 ;
298 mask *clone() const { return new (get_pool()) ou_mask(*this); };
299
300 private:
301 template<class T> bool t_is_covered(const T & expression) const
302 {
303 std::vector<mask *>::const_iterator it = lst.begin();
304
305 if(lst.empty())
306 throw Erange("et_mask::is_covered", dar_gettext("No mask to operate on in the list of mask"));
307
308 while(it != lst.end() && ! (*it)->is_covered(expression))
309 it++;
310
311 return it != lst.end();
312 }
313
314 };
315
316
318
319 class simple_path_mask : public mask
320 {
321 public :
323
327 simple_path_mask(const path &p, bool case_sensit) : chemin(p) { case_s = case_sensit; };
328
330 bool is_covered(const std::string & expression) const { throw SRC_BUG; };
331 bool is_covered(const path & chemin) const;
332
334 mask *clone() const { return new (get_pool()) simple_path_mask(*this); };
335
336 private :
337 path chemin;
338 bool case_s;
339 };
340
341
343
344 class same_path_mask : public mask
345 {
346 public :
348
351 same_path_mask(const std::string &p, bool case_sensit) { chemin = p; case_s = case_sensit; };
352
354 bool is_covered(const std::string &chemin) const;
355
357 mask *clone() const { return new (get_pool()) same_path_mask(*this); };
358
359 private :
360 std::string chemin;
361 bool case_s;
362 };
363
364
366
367 class exclude_dir_mask : public mask
368 {
369 public:
371
374 exclude_dir_mask(const std::string &p, bool case_sensit) { chemin = p; case_s = case_sensit;};
375
377 bool is_covered(const std::string &expression) const { throw SRC_BUG; }
378 bool is_covered(const path &chemin) const { return chemin.is_subdir_of(chemin, case_s); };
379
381 mask *clone() const { return new (get_pool()) exclude_dir_mask(*this); };
382
383 private:
384 std::string chemin;
385 bool case_s;
386 };
387
389
390 } // end of namespace
391
392 #endif
libdar::on_pool
Definition: on_pool.hpp:52
libdar::ou_mask::is_covered
bool is_covered(const path &chemin) const
check whether the given path is covered by the mask
Definition: mask.hpp:295
libdar::regular_mask::clone
mask * clone() const
inherited from the mask class
Definition: mask.hpp:166
libdar::same_path_mask::same_path_mask
same_path_mask(const std::string &p, bool case_sensit)
the constructor to be used by libdar external programs
Definition: mask.hpp:351
libdar::not_mask::is_covered
bool is_covered(const path &chemin) const
check whether the given path is covered by the mask
Definition: mask.hpp:200
libdar::regular_mask::is_covered
bool is_covered(const std::string &expression) const
inherited from the mask class
libdar::mask
the generic class, parent of all masks
Definition: mask.hpp:61
libdar::et_mask::~et_mask
~et_mask()
destructor
Definition: mask.hpp:231
libdar::ou_mask
makes the OR operator between two or more masks
Definition: mask.hpp:290
libdar::et_mask::size
U_I size() const
the number of mask on which is done the AND operator
Definition: mask.hpp:252
libdar::et_mask::clear
void clear()
clear the mask
Definition: mask.hpp:259
libdar::et_mask
makes an AND operator between two or more masks
Definition: mask.hpp:216
libdar::exclude_dir_mask::exclude_dir_mask
exclude_dir_mask(const std::string &p, bool case_sensit)
the constructor to be used by libdar external programs
Definition: mask.hpp:374
libdar::dar_gettext
const char * dar_gettext(const char *)
a routine to change NLS domaine forth and back for inline routines
libdar::et_mask::is_covered
bool is_covered(const std::string &expression) const
inherited from the mask class
Definition: mask.hpp:242
libdar::regular_mask
matches regular expressions (see "man 7 regex")
Definition: mask.hpp:144
libdar::bool_mask::is_covered
bool is_covered(const path &chemin) const
check whether the given path is covered by the mask
Definition: mask.hpp:102
libdar::simple_path_mask::is_covered
bool is_covered(const std::string &expression) const
inherited from the mask class
Definition: mask.hpp:330
libdar::not_mask::is_covered
bool is_covered(const std::string &expression) const
inherited from the mask class
Definition: mask.hpp:199
libdar::not_mask::not_mask
not_mask(const mask &m)
the constructor to be used by libdar external programs
Definition: mask.hpp:190
libdar::not_mask
negation of another mask
Definition: mask.hpp:182
libdar::bool_mask
boolean mask, either always true or false
Definition: mask.hpp:90
libdar::simple_mask::clone
mask * clone() const
inherited from the mask class
Definition: mask.hpp:132
libdar::ou_mask::clone
mask * clone() const
inherited from the mask class
Definition: mask.hpp:298
libdar::regular_mask::operator=
regular_mask & operator=(const regular_mask &ref)
the assignment operator
libdar::simple_path_mask
string matches if it is subdir of mask or mask is a subdir of expression
Definition: mask.hpp:319
libdar::same_path_mask
matches if string is exactly the given mask (no wilde card expression)
Definition: mask.hpp:344
libdar::not_mask::operator=
const not_mask & operator=(const not_mask &m)
assignment operator
libdar::path::is_subdir_of
bool is_subdir_of(const path &p, bool case_sensit) const
test whether the current object is a subdir of the method's argument
libdar::on_pool::get_pool
memory_pool * get_pool() const
Definition: on_pool.hpp:144
libdar::regular_mask::~regular_mask
virtual ~regular_mask()
destructor
Definition: mask.hpp:160
libdar::et_mask::et_mask
et_mask(const et_mask &m)
copy constructor
Definition: mask.hpp:227
libdar::simple_mask
matches as done on shell command lines (see "man 7 glob")
Definition: mask.hpp:114
path.hpp
here is the definition of the path classthe path class handle path and provide several operation on t...
libdar::mask::clone
virtual mask * clone() const =0
libdar::same_path_mask::is_covered
bool is_covered(const std::string &chemin) const
inherited from the mask class
libdar::not_mask::clone
mask * clone() const
inherited from the mask class
Definition: mask.hpp:203
libdar::exclude_dir_mask
matches if string is the given constructor string or a sub directory of it
Definition: mask.hpp:367
libdar::simple_path_mask::clone
mask * clone() const
inherited from the mask class
Definition: mask.hpp:334
libdar::et_mask::clone
mask * clone() const
inherited from the mask class
Definition: mask.hpp:246
libdar::bool_mask::is_covered
bool is_covered(const std::string &expression) const
inherited from the mask class
Definition: mask.hpp:101
libdar::mask::is_covered
virtual bool is_covered(const path &chemin) const
check whether the given path is covered by the mask
Definition: mask.hpp:79
libdar::simple_path_mask::simple_path_mask
simple_path_mask(const path &p, bool case_sensit)
the constructor to be used by libdar external programs
Definition: mask.hpp:327
libdar::bool_mask::bool_mask
bool_mask(bool always)
the constructor
Definition: mask.hpp:98
libdar::et_mask::is_covered
bool is_covered(const path &chemin) const
check whether the given path is covered by the mask
Definition: mask.hpp:243
libdar::Erange
exception used to signal range error
Definition: erreurs.hpp:179
libdar::not_mask::not_mask
not_mask(const not_mask &m)
copy constructor
Definition: mask.hpp:192
libdar::et_mask::operator=
const et_mask & operator=(const et_mask &m)
assignment operator
libdar::exclude_dir_mask::is_covered
bool is_covered(const path &chemin) const
check whether the given path is covered by the mask
Definition: mask.hpp:378
libdar::exclude_dir_mask::is_covered
bool is_covered(const std::string &expression) const
inherited from the mask class
Definition: mask.hpp:377
libdar::simple_mask::is_covered
bool is_covered(const std::string &expression) const
inherited from the mask class
on_pool.hpp
this is the base class of object that can be allocated on a memory pool
libdar::et_mask::et_mask
et_mask()
the constructor to be used by libdar external programs
Definition: mask.hpp:225
libdar::path::display
std::string display() const
convert back a path to a string
libdar::not_mask::~not_mask
~not_mask()
destructor
Definition: mask.hpp:196
libdar::same_path_mask::clone
mask * clone() const
inherited from the mask class
Definition: mask.hpp:357
libdar::simple_mask::simple_mask
simple_mask(const simple_mask &m)
copy constructor
Definition: mask.hpp:124
libdar::ou_mask::is_covered
bool is_covered(const std::string &expression) const
inherited from the mask class
Definition: mask.hpp:294
libdar::regular_mask::regular_mask
regular_mask(const std::string &wilde_card_expression, bool x_case_sensit)
the constructor to be used by libdar external programs
libdar::mask::is_covered
virtual bool is_covered(const std::string &expression) const =0
check wether the given string is covered by the mask
libdar::simple_mask::simple_mask
simple_mask(const std::string &wilde_card_expression, bool case_sensit)
the constructor to use by libdar external programs
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
libdar::exclude_dir_mask::clone
mask * clone() const
inherited from the mask class
Definition: mask.hpp:381
libdar::bool_mask::clone
mask * clone() const
inherited from the mask class
Definition: mask.hpp:105
libdar::simple_mask::operator=
const simple_mask & operator=(const simple_mask &m)
assignment operator
libdar::et_mask::add_mask
void add_mask(const mask &toadd)
add a mask to the operator
libdar::path
the class path is here to manipulate paths in the Unix notation: using'/'
Definition: path.hpp:50