Disk ARchive  2.6.1
Full featured and portable backup and archiving tool
crit_action.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2019 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 CRIT_ACTION_HPP
27 #define CRIT_ACTION_HPP
28 
29 #include "../my_config.h"
30 
31 #include <deque>
32 
33 #include "user_interaction.hpp"
34 #include "criterium.hpp"
35 
36 namespace libdar
37 {
38 
41 
43  class cat_nomme;
44 
46 
48  {
56  };
57 
58 
60 
63  {
73  };
74 
75 
77 
80 
82  {
83  public:
84  crit_action() = default;
85  crit_action(const crit_action & ref) = default;
86  crit_action(crit_action && ref) noexcept = default;
87  crit_action & operator = (const crit_action & ref) = default;
88  crit_action & operator = (crit_action && ref) noexcept = default;
89 
91  virtual ~crit_action() = default;
92 
94 
99  virtual void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const = 0;
100 
102 
106  virtual crit_action *clone() const = 0;
107  };
108 
109 
111 
114 
116  {
117  public:
119 
122  crit_constant_action(over_action_data data, over_action_ea ea) { x_data = data; x_ea = ea; };
123  crit_constant_action(const crit_constant_action & ref) = default;
124  crit_constant_action & operator = (const crit_constant_action & ref) = default;
125  ~crit_constant_action() = default;
126 
127 
129  virtual void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const override { data = x_data; ea = x_ea; };
130  virtual crit_action *clone() const override { return new (std::nothrow) crit_constant_action(*this); };
131 
132  private:
133  over_action_data x_data;
134  over_action_ea x_ea;
135  };
136 
137 
139 
142 
143  class testing : public crit_action
144  {
145  public:
147 
151  testing(const criterium & input, const crit_action & go_true, const crit_action & go_false);
152  testing(const testing & ref) : crit_action(ref) { copy_from(ref); if(!check()) throw Ememory("testing::testing(const testing &)"); };
153  testing(testing && ref) noexcept : crit_action(std::move(ref)) { nullifyptr(); move_from(std::move(ref)); };
154  testing & operator = (const testing & ref) { free(); copy_from(ref); if(!check()) throw Ememory("testing::testing(const testing &)"); return *this; };
155  testing & operator = (testing && ref) noexcept { crit_action::operator = (std::move(ref)); move_from(std::move(ref)); return *this; };
156  ~testing() { free(); };
157 
158 
160  virtual void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const override
161  {
162  if(x_input->evaluate(first, second))
163  x_go_true->get_action(first, second, data, ea);
164  else
165  x_go_false->get_action(first, second, data, ea);
166  };
167 
168  virtual crit_action *clone() const override { return new (std::nothrow) testing(*this); };
169 
170  private:
171  criterium *x_input;
172  crit_action *x_go_true;
173  crit_action *x_go_false;
174 
175  void nullifyptr() noexcept { x_input = nullptr; x_go_true = x_go_false = nullptr; };
176  void free() noexcept;
177  void copy_from(const testing & ref);
178  void move_from(testing && ref) noexcept;
179  bool check() const;
180  };
181 
182 
184 
187 
188  class crit_chain : public crit_action
189  {
190  public:
191  crit_chain() { sequence.clear(); };
192  crit_chain(const crit_chain & ref) : crit_action(ref) { copy_from(ref); };
193  crit_chain(crit_chain && ref) noexcept : crit_action(std::move(ref)) { sequence = std::move(ref.sequence); };
194  crit_chain & operator = (const crit_chain & ref) { destroy(); copy_from(ref); return *this; };
195  crit_chain & operator = (crit_chain && ref) noexcept { crit_action::operator = (std::move(ref)); sequence = std::move(ref.sequence); return *this; };
196  ~crit_chain() { destroy(); };
197 
198  void add(const crit_action & act);
199  void clear() { destroy(); };
200  void gobe(crit_chain & to_be_voided);
201 
202  virtual void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const override;
203 
204  virtual crit_action *clone() const override { return new (std::nothrow) crit_chain(*this); };
205 
206  private:
207  std::deque<crit_action *> sequence;
208 
209  void destroy();
210  void copy_from(const crit_chain & ref);
211  };
212 
214 
215 } // end of namespace
216 
217 #endif
contains classes that let the user define the policy for overwriting files
bool ea() noexcept
returns whether EA support has been activated at compilation time
merge EA but do not overwrite existing EA of &#39;in place&#39; by one of the same name of &#39;to be added&#39; inod...
Definition: crit_action.hpp:69
overwrite the &#39;in place&#39; but mark the &#39;to be added&#39; as already saved in the archive of reference ...
Definition: crit_action.hpp:52
over_action_data
the possible actions for overwriting data
Definition: crit_action.hpp:47
virtual void get_action(const cat_nomme &first, const cat_nomme &second, over_action_data &data, over_action_ea &ea) const =0
the action to take based on the files to compare
virtual crit_action * clone() const override
clone construction method
ask for user decision about file&#39;s data
Definition: crit_action.hpp:55
action still undefined at this step of the evaluation
Definition: crit_action.hpp:71
keep the EA of the &#39;in place&#39; entry
Definition: crit_action.hpp:64
virtual void get_action(const cat_nomme &first, const cat_nomme &second, over_action_data &data, over_action_ea &ea) const override
the inherited pure virtual method from class crit_action that must be implemented ...
virtual crit_action * clone() const override
clone construction method
the basic constant action
overwirte the &#39;in place&#39; entry by the &#39;to be added&#39; one
Definition: crit_action.hpp:50
over_action_ea
the possible action for overwriting EA
Definition: crit_action.hpp:62
virtual crit_action * clone() const override
clone construction method
drop any EA but mark them as already saved in the archive of reference (ctime is the one of the &#39;in p...
Definition: crit_action.hpp:67
the crit_chain class sequences crit_actions up to full definition of the action
drop any EA but mark them as already saved in the archive of reference (ctime is the one of the &#39;to b...
Definition: crit_action.hpp:68
defines the interaction interface between libdar and users.
action still undefined at this step of the evaluation
Definition: crit_action.hpp:54
exception used when memory has been exhausted
Definition: erreurs.hpp:126
keep the &#39;in place&#39; but mark it as already saved in the archive of reference
Definition: crit_action.hpp:51
the global action for overwriting
Definition: crit_action.hpp:81
the base class for all entry that have a name
Definition: cat_nomme.hpp:44
virtual ~crit_action()=default
the destructor
virtual crit_action * clone() const =0
clone construction method
merge EA but if both inode share an EA with the same name, take keep the one of the &#39;to be added&#39; ino...
Definition: crit_action.hpp:70
drop the EA for the elected entry
Definition: crit_action.hpp:66
the generic criterium class, parent of all criterium
Definition: criterium.hpp:51
virtual void get_action(const cat_nomme &first, const cat_nomme &second, over_action_data &data, over_action_ea &ea) const override
the inherited pure virtual methods from class action that must be implemented
ask for user decision about EA
Definition: crit_action.hpp:72
the testing class binds criterium to actions
crit_constant_action(over_action_data data, over_action_ea ea)
the constuctor
remove the original data/EA (file is completely deleted)
Definition: crit_action.hpp:53
do not overwrite (keep the &#39;in place&#39; entry)
Definition: crit_action.hpp:49
keep the EA of the &#39;to be added&#39; entry
Definition: crit_action.hpp:65
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:46