Disk ARchive  2.7.15
Full featured and portable backup and archiving tool
criterium.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2024 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, see the AUTHOR file
20 /*********************************************************************/
21 
25 
26 #ifndef CRITERIUM_HPP
27 #define CRITERIUM_HPP
28 
29 #include "../my_config.h"
30 
31 #include <deque>
32 #include "erreurs.hpp"
33 #include "infinint.hpp"
34 
35 namespace libdar
36 {
37 
40 
42  class cat_nomme;
43 
45 
50 
51  class criterium
52  {
53  public:
54  criterium() {};
55  criterium(const criterium & ref) = default;
56  criterium(criterium && ref) noexcept = default;
57  criterium & operator = (const criterium & ref) = default;
58  criterium & operator = (criterium && ref) noexcept = default;
59  virtual ~criterium() noexcept(false) {};
60 
62 
66  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const = 0;
67 
69 
73  virtual criterium *clone() const = 0;
74  };
75 
76  // //////////////////////////////////////////////////////////
77  // ////////// a set of criterium classes follows ////////////
78  // //////////////////////////////////////////////////////////
79 
80 
82 
85 
87  {
88  public:
90  crit_in_place_is_inode(const crit_in_place_is_inode & ref) = default;
91  crit_in_place_is_inode(crit_in_place_is_inode && ref) noexcept = default;
92  crit_in_place_is_inode & operator = (const crit_in_place_is_inode & ref) = default;
93  crit_in_place_is_inode & operator = (crit_in_place_is_inode && ref) noexcept = default;
94  ~crit_in_place_is_inode() = default;
95 
96  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
97  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_is_inode(*this); };
98  };
99 
100 
102 
104  {
105  public:
107  crit_in_place_is_dir(const crit_in_place_is_dir & ref) = default;
108  crit_in_place_is_dir(crit_in_place_is_dir && ref) noexcept = default;
109  crit_in_place_is_dir & operator = (const crit_in_place_is_dir & ref) = default;
110  crit_in_place_is_dir & operator = (crit_in_place_is_dir && ref) noexcept = default;
111  ~crit_in_place_is_dir() = default;
112 
113  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
114  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_is_dir(*this); };
115  };
116 
117 
119 
121  {
122  public:
124  crit_in_place_is_file(const crit_in_place_is_file & ref) = default;
125  crit_in_place_is_file(crit_in_place_is_file && ref) noexcept = default;
126  crit_in_place_is_file & operator = (const crit_in_place_is_file & ref) = default;
127  crit_in_place_is_file & operator = (crit_in_place_is_file && ref) noexcept = default;
128  ~crit_in_place_is_file() = default;
129 
130  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
131  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_is_file(*this); };
132  };
133 
135 
137 
139  {
140  public:
144  crit_in_place_is_hardlinked_inode & operator = (const crit_in_place_is_hardlinked_inode & ref) = default;
145  crit_in_place_is_hardlinked_inode & operator = (crit_in_place_is_hardlinked_inode && ref) noexcept = default;
147 
148  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
149  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_is_hardlinked_inode(*this); };
150  };
151 
152 
156 
158  {
159  public:
164  crit_in_place_is_new_hardlinked_inode & operator = (crit_in_place_is_new_hardlinked_inode && ref) noexcept = default;
166 
167  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
168  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_is_new_hardlinked_inode(*this); };
169  };
170 
171 
173 
175 
177  {
178  public:
179  crit_in_place_data_more_recent(const infinint & hourshift = 0) : x_hourshift(hourshift) {};
182  crit_in_place_data_more_recent & operator = (const crit_in_place_data_more_recent & ref) = default;
183  crit_in_place_data_more_recent & operator = (crit_in_place_data_more_recent && ref) noexcept = default;
184  ~crit_in_place_data_more_recent() = default;
185 
186  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
187  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_data_more_recent(*this); };
188 
189  private:
190  infinint x_hourshift;
191  };
192 
193 
196 
198 
199 
201  {
202  public:
203  crit_in_place_data_more_recent_or_equal_to(const infinint & date, const infinint & hourshift = 0) : x_hourshift(hourshift), x_date(date) {};
209 
210  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
211  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_data_more_recent_or_equal_to(*this); };
212 
213  private:
214  infinint x_hourshift;
215  infinint x_date;
216  };
217 
218 
220 
222 
224  {
225  public:
228  crit_in_place_data_bigger(crit_in_place_data_bigger && ref) noexcept = default;
229  crit_in_place_data_bigger & operator = (const crit_in_place_data_bigger & ref) = default;
230  crit_in_place_data_bigger & operator = (crit_in_place_data_bigger && ref) noexcept = default;
231  ~crit_in_place_data_bigger() = default;
232 
233  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
234  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_data_bigger(*this); };
235  };
236 
237 
238 
241 
243 
245  {
246  public:
248  crit_in_place_data_saved(const crit_in_place_data_saved & ref) = default;
249  crit_in_place_data_saved(crit_in_place_data_saved && ref) noexcept = default;
250  crit_in_place_data_saved & operator = (const crit_in_place_data_saved & ref) = default;
251  crit_in_place_data_saved & operator = (crit_in_place_data_saved && ref) noexcept = default;
252  ~crit_in_place_data_saved() = default;
253 
254  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
255  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_data_saved(*this); };
256  };
257 
258 
260 
262  {
263  public:
265  crit_in_place_data_dirty(const crit_in_place_data_dirty & ref) = default;
266  crit_in_place_data_dirty(crit_in_place_data_dirty && ref) noexcept = default;
267  crit_in_place_data_dirty & operator = (const crit_in_place_data_dirty & ref) = default;
268  crit_in_place_data_dirty & operator = (crit_in_place_data_dirty && ref) noexcept = default;
269  ~crit_in_place_data_dirty() = default;
270 
271  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
272  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_data_dirty(*this); };
273  };
274 
276 
278  {
279  public:
282  crit_in_place_data_sparse(crit_in_place_data_sparse && ref) noexcept = default;
283  crit_in_place_data_sparse & operator = (const crit_in_place_data_sparse & ref) = default;
284  crit_in_place_data_sparse & operator = (crit_in_place_data_sparse && ref) noexcept = default;
285  ~crit_in_place_data_sparse() = default;
286 
287  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
288  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_data_sparse(*this); };
289  };
290 
291 
293 
295  {
296  public:
299  crit_in_place_has_delta_sig(crit_in_place_has_delta_sig && ref) noexcept = default;
300  crit_in_place_has_delta_sig & operator = (const crit_in_place_has_delta_sig & ref) = default;
301  crit_in_place_has_delta_sig & operator = (crit_in_place_has_delta_sig && ref) noexcept = default;
302  ~crit_in_place_has_delta_sig() = default;
303 
304  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
305  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_has_delta_sig(*this); };
306  };
307 
309 
319 
321  {
322  public:
324  crit_same_inode_data(const crit_same_inode_data & ref) = default;
325  crit_same_inode_data(crit_same_inode_data && ref) noexcept = default;
326  crit_same_inode_data & operator = (const crit_same_inode_data & ref) = default;
327  crit_same_inode_data & operator = (crit_same_inode_data && ref) noexcept = default;
328  ~crit_same_inode_data() = default;
329 
330  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
331  virtual criterium *clone() const override { return new (std::nothrow) crit_same_inode_data(*this); };
332  };
333 
334 
337 
339  {
340  public:
342  crit_in_place_EA_present(const crit_in_place_EA_present & ref) = default;
343  crit_in_place_EA_present(crit_in_place_EA_present && ref) noexcept = default;
344  crit_in_place_EA_present & operator = (const crit_in_place_EA_present & ref) = default;
345  crit_in_place_EA_present & operator = (crit_in_place_EA_present && ref) noexcept = default;
346  ~crit_in_place_EA_present() = default;
347 
348  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
349  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_EA_present(*this); };
350  };
351 
352 
354 
359 
361  {
362  public:
363  crit_in_place_EA_more_recent(const infinint & hourshift = 0) : x_hourshift(hourshift) {};
366  crit_in_place_EA_more_recent & operator = (const crit_in_place_EA_more_recent & ref) = default;
367  crit_in_place_EA_more_recent & operator = (crit_in_place_EA_more_recent && ref) noexcept = default;
368  ~crit_in_place_EA_more_recent() = default;
369 
370 
371  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
372  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_EA_more_recent(*this); };
373 
374  private:
375  infinint x_hourshift;
376  };
377 
378 
380 
383 
385  {
386  public:
387  crit_in_place_EA_more_recent_or_equal_to(const infinint & date, const infinint & hourshift = 0) : x_hourshift(hourshift), x_date(date) {};
393 
394  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
395  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_EA_more_recent_or_equal_to(*this); };
396 
397  private:
398  infinint x_hourshift;
399  infinint x_date;
400  };
401 
402 
404 
406 
408  {
409  public:
411  crit_in_place_more_EA(const crit_in_place_more_EA & ref) = default;
412  crit_in_place_more_EA(crit_in_place_more_EA && ref) noexcept = default;
413  crit_in_place_more_EA & operator = (const crit_in_place_more_EA & ref) = default;
414  crit_in_place_more_EA & operator = (crit_in_place_more_EA && ref) noexcept = default;
415  ~crit_in_place_more_EA() = default;
416 
417  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
418  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_more_EA(*this); };
419  };
420 
421 
422 
424 
426 
428  {
429  public:
431  crit_in_place_EA_bigger(const crit_in_place_EA_bigger & ref) = default;
432  crit_in_place_EA_bigger(crit_in_place_EA_bigger && ref) noexcept = default;
433  crit_in_place_EA_bigger & operator = (const crit_in_place_EA_bigger & ref) = default;
434  crit_in_place_EA_bigger & operator = (crit_in_place_EA_bigger && ref) noexcept = default;
435  ~crit_in_place_EA_bigger() = default;
436 
437  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
438  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_EA_bigger(*this); };
439  };
440 
441 
443 
445 
447  {
448  public:
450  crit_in_place_EA_saved(const crit_in_place_EA_saved & ref) = default;
451  crit_in_place_EA_saved(crit_in_place_EA_saved && ref) noexcept = default;
452  crit_in_place_EA_saved & operator = (const crit_in_place_EA_saved & ref) = default;
453  crit_in_place_EA_saved & operator = (crit_in_place_EA_saved && ref) noexcept = default;
454  ~crit_in_place_EA_saved() = default;
455 
456  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
457  virtual criterium *clone() const override { return new (std::nothrow) crit_in_place_EA_saved(*this); };
458  };
459 
460 
462 
465 
466  class crit_same_type : public criterium
467  {
468  public:
469  crit_same_type() {};
470  crit_same_type(const crit_same_type & ref) = default;
471  crit_same_type(crit_same_type && ref) noexcept = default;
472  crit_same_type & operator = (const crit_same_type & ref) = default;
473  crit_same_type & operator = (crit_same_type && ref) noexcept = default;
474  ~crit_same_type() = default;
475 
476  virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override;
477  virtual criterium *clone() const override { return new (std::nothrow) crit_same_type(*this); };
478  };
479 
480 
482 
483  class crit_not : public criterium
484  {
485  public:
486  crit_not(const criterium & crit) { x_crit = crit.clone(); if(x_crit == nullptr) throw Ememory("crit_not::crit_not"); };
487  crit_not(const crit_not & ref): criterium(ref) { copy_from(ref); };
488  crit_not(crit_not && ref) noexcept: criterium(std::move(ref)) { x_crit = nullptr; std::swap(x_crit, ref.x_crit); };
489  crit_not & operator = (const crit_not & ref) { destroy(); copy_from(ref); return *this; };
490  crit_not & operator = (crit_not && ref) noexcept { criterium::operator = (std::move(ref)); std::swap(x_crit, ref.x_crit); return *this; };
491  ~crit_not() { destroy(); };
492 
493  virtual bool evaluate(const cat_nomme & first, const cat_nomme & second) const override { return ! x_crit->evaluate(first, second); };
494  virtual criterium *clone() const override { return new (std::nothrow) crit_not(*this); };
495 
496  protected:
497  const criterium *x_crit;
498 
499  private:
500  void copy_from(const crit_not & ref);
501  void destroy() { if(x_crit != nullptr) { delete x_crit; x_crit = nullptr; } };
502  };
503 
505 
506  class crit_and : public criterium
507  {
508  public:
509  crit_and() { clear(); };
510  crit_and(const crit_and & ref) : criterium(ref) { copy_from(ref); };
511  crit_and(crit_and && ref) = default; // moving the deque<criterium *> while the pointed to object are untouched
512  crit_and & operator = (const crit_and & ref) { detruit(); copy_from(ref); return *this; };
513  crit_and & operator = (crit_and && ref) noexcept = default; // moving the deque<criterium *> while the pointed to object are untouched
514  ~crit_and() { detruit(); };
515 
516  void add_crit(const criterium & ref);
517  void clear() { detruit(); };
518 
520  void gobe(crit_and & to_be_voided);
521 
522  virtual bool evaluate(const cat_nomme & first, const cat_nomme & second) const override;
523  virtual criterium *clone() const override { return new (std::nothrow) crit_and(*this); };
524 
525  protected:
526  std::deque<criterium *> operand;
527 
528  private:
529  void copy_from(const crit_and & ref);
530  void detruit();
531  };
532 
533  class crit_or : public crit_and
534  {
535  public:
536  crit_or() { clear(); };
537  crit_or(const crit_or & ref) = default;
538  crit_or(crit_or && ref) = default;
539  crit_or & operator = (const crit_or & ref) = default;
540  crit_or & operator = (crit_or && ref) noexcept = default;
541  ~crit_or() = default;
542 
543  virtual bool evaluate(const cat_nomme & first, const cat_nomme & second) const override;
544  virtual criterium *clone() const override { return new (std::nothrow) crit_or(*this); };
545 
546  };
547 
548  class crit_invert : public crit_not
549  {
550  public:
551  crit_invert(const criterium & crit) : crit_not(crit) {};
552  crit_invert(const crit_invert & ref) = default;
553  crit_invert(crit_invert && ref) noexcept = default;
554  crit_invert & operator = (const crit_invert & ref) = default;
555  crit_invert & operator = (crit_invert && ref) noexcept = default;
556  ~crit_invert() = default;
557 
558  virtual bool evaluate(const cat_nomme & first, const cat_nomme & second) const override { return x_crit->evaluate(second, first); };
559  virtual criterium *clone() const override { return new (std::nothrow) crit_invert(*this); };
560  };
561 
563 
564 } // end of namespace
565 
566 #endif
exception used when memory has been exhausted
Definition: erreurs.hpp:127
the base class for all entry that have a name
Definition: cat_nomme.hpp:45
realises the AND operator
Definition: criterium.hpp:507
void gobe(crit_and &to_be_voided)
this call merges to the current call the arguments of another "crit_and", the given argument is clear...
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:523
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
returns true if the space used by EA of the first entry is greater or equal to the space used by the ...
Definition: criterium.hpp:428
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:438
returns true if the EA of the first entry is more recent or equal to the fixed date given in argument...
Definition: criterium.hpp:385
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:395
returns true if the EA of the first entry is more recent or equal to the one of the second entry
Definition: criterium.hpp:361
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:372
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:349
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
returns true if the in place entry has its EA saved (not just marked as saved) in the archve of refer...
Definition: criterium.hpp:447
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:457
returns true if the data of the first entry is bigger or equal to the one of the second entry
Definition: criterium.hpp:224
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:234
return true if the entry is a dirty file (or hard linked dirty file)
Definition: criterium.hpp:262
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:272
If the in_place entry is not an inode its date is considered equal to zero. Comparison is done on mti...
Definition: criterium.hpp:201
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:211
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
returns true if the data of the first entry is more recent or of the same date of the one of the seco...
Definition: criterium.hpp:177
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:187
if the entry is not an inode the result is also true
Definition: criterium.hpp:245
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:255
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
return true if the entry is a sparse file (or hard linked sparse file)
Definition: criterium.hpp:278
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:288
return true if the entry has delta signature
Definition: criterium.hpp:295
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:305
returns true if the first entry is a cat_directory (whatever is the second)
Definition: criterium.hpp:104
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:114
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
returns true if the first entry is a plain file (whatever is the second)
Definition: criterium.hpp:121
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:131
returns true if the first entry is a inode with several hard links (whatever is the second entry)
Definition: criterium.hpp:139
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:149
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
returns true if the first entry is an inode (whatever is the second)
Definition: criterium.hpp:87
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:97
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:168
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
returns true if the first entry has more or even EA (in number not in size) than the second entry
Definition: criterium.hpp:408
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:418
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
realises the negation of the criterium given in argument to its constructor
Definition: criterium.hpp:484
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:494
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
Definition: criterium.hpp:493
returns true if both inputs are inode of the same type (file/pipe/device/...) and share inode informa...
Definition: criterium.hpp:321
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:331
returns true if the two entries are of the same type (plain-file/char dev/block dev/named pipe/symlin...
Definition: criterium.hpp:467
virtual criterium * clone() const override
clone construction method
Definition: criterium.hpp:477
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const override
criterum interface method
the generic criterium class, parent of all criterium
Definition: criterium.hpp:52
virtual criterium * clone() const =0
clone construction method
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const =0
criterum interface method
the arbitrary large positive integer class
contains all the excetion class thrown by libdar
switch module to limitint (32 ou 64 bits integers) or infinint
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47