Disk ARchive  2.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
criterium.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: criterium.hpp,v 1.14 2011/05/27 12:29:18 edrusb Rel $
22 //
23 /*********************************************************************/
24 
28 
29 #ifndef CRITERIUM_HPP
30 #define CRITERIUM_HPP
31 
32 #include "../my_config.h"
33 
34 #include "catalogue.hpp"
35 
36 namespace libdar
37 {
38 
41 
43 
45  {
46  data_preserve, //< do not overwrite (keep the 'in place' entry)
47  data_overwrite, //< overwirte the 'in place' entry by the 'to be added' one
48  data_preserve_mark_already_saved, //< keep the 'in place' but mark it as already saved in the archive of reference
49  data_overwrite_mark_already_saved, //< overwrite the 'in place' but mark the 'to be added' as already saved in the archive of reference
50  data_remove, //< remove the original data/EA (file is completely deleted)
51  data_undefined, //< action still undefined at this step of the evaluation
52  data_ask //< ask for user decision about file's data
53  };
54 
55 
57 
58  enum over_action_ea //< define the action to apply to each EA entry (not to the EA set of a particular inode)
59  {
60  EA_preserve, //< keep the EA of the 'in place' entry
61  EA_overwrite, //< keep the EA of the 'to be added' entry
62  EA_clear, //< drop the EA for the elected entry
63  EA_preserve_mark_already_saved, //< drop any EA but mark them as already saved in the archive of reference (ctime is the one of the 'in place' inode)
64  EA_overwrite_mark_already_saved, //< drop any EA but mark them as already saved in the archive of reference (ctime is the one of the 'to be added' inode)
65  EA_merge_preserve, //< merge EA but do not overwrite existing EA of 'in place' by one of the same name of 'to be added' inode
66  EA_merge_overwrite, //< merge EA but if both inode share an EA with the same name, take keep the one of the 'to be added' inode
67  EA_undefined, //< action still undefined at this step of the evaluation
68  EA_ask //< ask for user decision about EA
69  };
70 
71 
73 
76 
78  {
79  public:
81  virtual ~crit_action() {};
82 
84 
89  virtual void get_action(const nomme & first, const nomme & second, over_action_data & data, over_action_ea & ea) const = 0;
90 
92 
96  virtual crit_action *clone() const = 0;
97  };
98 
99 
101 
104 
106  {
107  public:
109 
112  crit_constant_action(over_action_data data, over_action_ea ea) { x_data = data; x_ea = ea; };
113 
114 
116  void get_action(const nomme & first, const nomme & second, over_action_data & data, over_action_ea & ea) const { data = x_data; ea = x_ea; };
117  crit_action *clone() const { return new crit_constant_action(*this); };
118 
119  private:
120  over_action_data x_data;
121  over_action_ea x_ea;
122  };
123 
124 
125 
127 
132 
133  class criterium
134  {
135  public:
136  virtual ~criterium() {};
137 
139 
143  virtual bool evaluate(const nomme &first, const nomme &second) const = 0;
144 
146 
150  virtual criterium *clone() const = 0;
151 
152  protected:
153  static const inode *get_inode(const nomme * arg);
154  };
155 
156 
157 
159 
162 
163  class testing : public crit_action
164  {
165  public:
167 
171  testing(const criterium & input, const crit_action & go_true, const crit_action & go_false);
172  testing(const testing & ref) : crit_action(ref) { copy_from(ref); if(!check()) throw Ememory("testing::testing(const testing &)"); };
173  const testing & operator = (const testing & ref) { free(); copy_from(ref); if(!check()) throw Ememory("testing::testing(const testing &)"); };
174  ~testing() { free(); };
175 
176 
178  void get_action(const nomme & first, const nomme & second, over_action_data & data, over_action_ea & ea) const
179  {
180  if(x_input->evaluate(first, second))
181  x_go_true->get_action(first, second, data, ea);
182  else
183  x_go_false->get_action(first, second, data, ea);
184  };
185 
186  crit_action *clone() const { return new testing(*this); };
187 
188  private:
189  criterium *x_input;
190  crit_action *x_go_true;
191  crit_action *x_go_false;
192 
193  void free();
194  void copy_from(const testing & ref);
195  bool check() const; //< returns false if an field is NULL
196  };
197 
198 
200 
203 
204  class crit_chain : public crit_action
205  {
206  public:
207  crit_chain() { sequence.clear(); };
208  crit_chain(const crit_chain & ref) : crit_action(ref) { copy_from(ref); };
209  const crit_chain & operator = (const crit_chain & ref) { destroy(); copy_from(ref); return *this; };
210  ~crit_chain() { destroy(); };
211 
212  void add(const crit_action & act);
213  void clear() { destroy(); };
214  void gobe(crit_chain & to_be_voided);
215 
216  void get_action(const nomme & first, const nomme & second, over_action_data & data, over_action_ea & ea) const;
217 
218  crit_action *clone() const { return new crit_chain(*this); };
219 
220  private:
221  std::vector<crit_action *> sequence;
222 
223  void destroy();
224  void copy_from(const crit_chain & ref);
225  };
226 
230 
231 
233 
236 
238  {
239  public:
240  bool evaluate(const nomme &first, const nomme &second) const { return dynamic_cast<const inode *>(&first) != NULL || dynamic_cast<const mirage *>(&first) != NULL; };
241  criterium *clone() const { return new crit_in_place_is_inode(*this); };
242  };
243 
244 
246 
248  {
249  public:
250  bool evaluate(const nomme &first, const nomme &second) const { return dynamic_cast<const directory *>(&first) != NULL; };
251  criterium *clone() const { return new crit_in_place_is_dir(*this); };
252  };
253 
254 
256 
258  {
259  public:
260  bool evaluate(const nomme &first, const nomme &second) const;
261  criterium *clone() const { return new crit_in_place_is_file(*this); };
262  };
263 
265 
267 
269  {
270  public:
271  bool evaluate(const nomme &first, const nomme &second) const { return dynamic_cast<const mirage *>(&first) != NULL; };
272  criterium *clone() const { return new crit_in_place_is_hardlinked_inode(*this); };
273  };
274 
275 
278  {
279  bool evaluate(const nomme &first, const nomme &second) const
280  {
281  const mirage * tmp = dynamic_cast<const mirage *>(&first);
282  return tmp != NULL && tmp->is_first_mirage();
283  };
284  criterium *clone() const { return new crit_in_place_is_new_hardlinked_inode(*this); };
285  };
286 
287 
289 
291 
293  {
294  public:
295  crit_in_place_data_more_recent(const infinint & hourshift = 0) : x_hourshift(hourshift) {};
296 
297  bool evaluate(const nomme &first, const nomme &second) const;
298  criterium *clone() const { return new crit_in_place_data_more_recent(*this); };
299 
300  private:
301  infinint x_hourshift;
302  };
303 
304 
306 
308 
309 
311  {
312  public:
313  crit_in_place_data_more_recent_or_equal_to(const infinint & date, const infinint & hourshift = 0) : x_hourshift(hourshift), x_date(date) {};
314 
315  bool evaluate(const nomme &first, const nomme &second) const;
317 
318  private:
319  infinint x_hourshift;
320  infinint x_date;
321  };
322 
323 
325 
327 
329  {
330  public:
331  bool evaluate(const nomme &first, const nomme &second) const;
332  criterium *clone() const { return new crit_in_place_data_bigger(*this); };
333  };
334 
335 
336 
338 
340 
342  {
343  public:
344  bool evaluate(const nomme &first, const nomme &second) const;
345  criterium *clone() const { return new crit_in_place_data_saved(*this); };
346  };
347 
348 
350 
352  {
353  public:
354  bool evaluate(const nomme &first, const nomme &second) const;
355  criterium *clone() const { return new crit_in_place_data_dirty(*this); };
356  };
357 
359 
361  {
362  public:
363  bool evaluate(const nomme &first, const nomme &second) const;
364  criterium *clone() const { return new crit_in_place_data_sparse(*this); };
365  };
366 
367 
370 
372  {
373  public:
374  bool evaluate(const nomme &first, const nomme &second) const
375  {
376  const inode *tmp = dynamic_cast<const inode *>(&first);
377  return tmp != NULL && tmp->ea_get_saved_status() != inode::ea_none && tmp->ea_get_saved_status() != inode::ea_removed;
378  };
379  criterium *clone() const { return new crit_in_place_EA_present(*this); };
380  };
381 
382 
384 
389 
391  {
392  public:
393  crit_in_place_EA_more_recent(const infinint & hourshift = 0) : x_hourshift(hourshift) {};
394 
395  bool evaluate(const nomme &first, const nomme &second) const;
396  criterium *clone() const { return new crit_in_place_EA_more_recent(*this); };
397 
398  private:
399  infinint x_hourshift;
400  };
401 
402 
404 
407 
409  {
410  public:
411  crit_in_place_EA_more_recent_or_equal_to(const infinint & date, const infinint & hourshift = 0) : x_hourshift(hourshift), x_date(date) {};
412 
413  bool evaluate(const nomme &first, const nomme &second) const;
415 
416  private:
417  infinint x_hourshift;
418  infinint x_date;
419  };
420 
421 
423 
425 
427  {
428  public:
429  bool evaluate(const nomme &first, const nomme &second) const;
430  criterium *clone() const { return new crit_in_place_more_EA(*this); };
431  };
432 
433 
434 
436 
438 
440  {
441  public:
442  bool evaluate(const nomme &first, const nomme &second) const;
443  criterium *clone() const { return new crit_in_place_EA_bigger(*this); };
444  };
445 
446 
448 
450 
452  {
453  public:
454  bool evaluate(const nomme &first, const nomme &second) const;
455  criterium *clone() const { return new crit_in_place_EA_saved(*this); };
456  };
457 
458 
460 
463 
464  class crit_same_type : public criterium
465  {
466  public:
467  bool evaluate(const nomme &first, const nomme &second) const;
468  criterium *clone() const { return new crit_same_type(*this); };
469  };
470 
471 
473 
474  class crit_not : public criterium
475  {
476  public:
477  crit_not(const criterium & crit) { x_crit = crit.clone(); if(x_crit == NULL) throw Ememory("crit_not::crit_not"); };
478  crit_not(const crit_not & ref) : criterium (ref) { copy_from(ref); };
479  const crit_not & operator = (const crit_not & ref) { destroy(); copy_from(ref); return *this; };
480  ~crit_not() { destroy(); };
481 
482  bool evaluate(const nomme & first, const nomme & second) const { return ! x_crit->evaluate(first, second); };
483  criterium *clone() const { return new crit_not(*this); };
484 
485  protected:
486  const criterium *x_crit;
487 
488  private:
489  void copy_from(const crit_not & ref);
490  void destroy() { if(x_crit != NULL) { delete x_crit; x_crit = NULL; } };
491  };
492 
494 
495  class crit_and : public criterium
496  {
497  public:
498  crit_and() { clear(); };
499  crit_and(const crit_and & ref) : criterium(ref) { copy_from(ref); };
500  const crit_and & operator = (const crit_and & ref) { detruit(); copy_from(ref); return *this; };
501  ~crit_and() { detruit(); };
502 
503  void add_crit(const criterium & ref);
504  void clear() { detruit(); };
505 
507  void gobe(crit_and & to_be_voided);
508 
509  virtual bool evaluate(const nomme & first, const nomme & second) const;
510  criterium *clone() const { return new crit_and(*this); };
511 
512  protected:
513  std::vector<criterium *> operand;
514 
515  private:
516  void copy_from(const crit_and & ref);
517  void detruit();
518  };
519 
520  class crit_or : public crit_and
521  {
522  public:
523  crit_or() { clear(); };
524 
525  bool evaluate(const nomme & first, const nomme & second) const;
526  criterium *clone() const { return new crit_or(*this); };
527 
528  };
529 
530  class crit_invert : public crit_not
531  {
532  public:
533  crit_invert(const criterium & crit) : crit_not(crit) {};
534 
535  bool evaluate(const nomme & first, const nomme & second) const { return x_crit->evaluate(second, first); };
536  criterium *clone() const { return new crit_invert(*this); };
537  };
538 
539 
541 
547  extern over_action_ea crit_ask_user_for_EA_action(user_interaction & dialog, const std::string & full_name, const entree *already_here, const entree *dolly);
548 
550 
556  extern over_action_data crit_ask_user_for_data_action(user_interaction & dialog, const std::string & full_name, const entree *already_here, const entree *dolly);
557 
559 
564  extern void crit_show_entry_info(user_interaction & dialog, const std::string & full_name, const entree *already_here, const entree *dolly);
565 
567 
568 } // end of namespace
569 
570 #endif