Disk ARchive 2.7.16
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-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 CRIT_ACTION_HPP
27#define CRIT_ACTION_HPP
28
29#include "../my_config.h"
30
31#include <deque>
32
33#include "criterium.hpp"
34
35namespace libdar
36{
37
40
42 class cat_nomme;
43
45
47 {
55 };
56
57
59
62 {
71 EA_ask
72 };
73
74
76
79
81 {
82 public:
83 crit_action() {};
84 crit_action(const crit_action & ref) = default;
85 crit_action(crit_action && ref) noexcept = default;
86 crit_action & operator = (const crit_action & ref) = default;
87 crit_action & operator = (crit_action && ref) noexcept = default;
88
90 virtual ~crit_action() = default;
91
93
98 virtual void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const = 0;
99
101
105 virtual crit_action *clone() const = 0;
106 };
107
108
110
113
115 {
116 public:
118
121 crit_constant_action(over_action_data data, over_action_ea ea) { x_data = data; x_ea = ea; };
122 crit_constant_action(const crit_constant_action & ref) = default;
123 crit_constant_action & operator = (const crit_constant_action & ref) = default;
124 ~crit_constant_action() = default;
125
126
128 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; };
129 virtual crit_action *clone() const override { return new (std::nothrow) crit_constant_action(*this); };
130
131 private:
132 over_action_data x_data;
133 over_action_ea x_ea;
134 };
135
136
138
141
142 class testing : public crit_action
143 {
144 public:
146
150 testing(const criterium & input, const crit_action & go_true, const crit_action & go_false);
151 testing(const testing & ref) : crit_action(ref) { copy_from(ref); if(!check()) throw Ememory("testing::testing(const testing &)"); };
152 testing(testing && ref) noexcept : crit_action(std::move(ref)) { nullifyptr(); move_from(std::move(ref)); };
153 testing & operator = (const testing & ref) { free(); copy_from(ref); if(!check()) throw Ememory("testing::testing(const testing &)"); return *this; };
154 testing & operator = (testing && ref) noexcept { crit_action::operator = (std::move(ref)); move_from(std::move(ref)); return *this; };
155 ~testing() { free(); };
156
157
159 virtual void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const override
160 {
161 if(x_input->evaluate(first, second))
162 x_go_true->get_action(first, second, data, ea);
163 else
164 x_go_false->get_action(first, second, data, ea);
165 };
166
167 virtual crit_action *clone() const override { return new (std::nothrow) testing(*this); };
168
169 private:
170 criterium *x_input;
171 crit_action *x_go_true;
172 crit_action *x_go_false;
173
174 void nullifyptr() noexcept { x_input = nullptr; x_go_true = x_go_false = nullptr; };
175 void free() noexcept;
176 void copy_from(const testing & ref);
177 void move_from(testing && ref) noexcept;
178 bool check() const;
179 };
180
181
183
186
187 class crit_chain : public crit_action
188 {
189 public:
190 crit_chain() { sequence.clear(); };
191 crit_chain(const crit_chain & ref) : crit_action(ref) { copy_from(ref); };
192 crit_chain(crit_chain && ref) noexcept : crit_action(std::move(ref)) { sequence = std::move(ref.sequence); };
193 crit_chain & operator = (const crit_chain & ref) { destroy(); copy_from(ref); return *this; };
194 crit_chain & operator = (crit_chain && ref) noexcept { crit_action::operator = (std::move(ref)); sequence = std::move(ref.sequence); return *this; };
195 ~crit_chain() { destroy(); };
196
197 void add(const crit_action & act);
198 void clear() { destroy(); };
199 void gobe(crit_chain & to_be_voided);
200
201 virtual void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const override;
202
203 virtual crit_action *clone() const override { return new (std::nothrow) crit_chain(*this); };
204
205 private:
206 std::deque<crit_action *> sequence;
207
208 void destroy();
209 void copy_from(const crit_chain & ref);
210 };
211
213
214} // end of namespace
215
216#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
the global action for overwriting
Definition: crit_action.hpp:81
virtual ~crit_action()=default
the destructor
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 =0
clone construction method
the crit_chain class sequences crit_actions up to full definition of the action
virtual crit_action * clone() const override
clone construction method
virtual void get_action(const cat_nomme &first, const cat_nomme &second, over_action_data &data, over_action_ea &ea) const override
the action to take based on the files to compare
the basic constant action
crit_constant_action(over_action_data data, over_action_ea ea)
the constuctor
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
virtual crit_action * clone() const override
clone construction method
the generic criterium class, parent of all criterium
Definition: criterium.hpp:52
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const =0
criterum interface method
the testing class binds criterium to actions
virtual crit_action * clone() const override
clone construction method
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
bool check() const
returns false if an field is nullptr
testing(const criterium &input, const crit_action &go_true, const crit_action &go_false)
the constructor
contains classes that let the user define the policy for overwriting files
over_action_ea
the possible action for overwriting EA
Definition: crit_action.hpp:62
over_action_data
the possible actions for overwriting data
Definition: crit_action.hpp:47
@ EA_ask
ask for user decision about EA
Definition: crit_action.hpp:71
@ EA_merge_preserve
merge EA but do not overwrite existing EA of 'in place' by one of the same name of 'to be added' inod...
Definition: crit_action.hpp:68
@ 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 p...
Definition: crit_action.hpp:66
@ EA_overwrite
keep the EA of the 'to be added' entry
Definition: crit_action.hpp:64
@ EA_preserve
keep the EA of the 'in place' entry
Definition: crit_action.hpp:63
@ 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' ino...
Definition: crit_action.hpp:69
@ EA_undefined
action still undefined at this step of the evaluation
Definition: crit_action.hpp:70
@ EA_clear
drop the EA for the elected entry
Definition: crit_action.hpp:65
@ 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 b...
Definition: crit_action.hpp:67
@ data_preserve
do not overwrite (keep the 'in place' entry)
Definition: crit_action.hpp:48
@ data_preserve_mark_already_saved
keep the 'in place' but mark it as already saved in the archive of reference
Definition: crit_action.hpp:50
@ data_overwrite
overwirte the 'in place' entry by the 'to be added' one
Definition: crit_action.hpp:49
@ data_ask
ask for user decision about file's data
Definition: crit_action.hpp:54
@ data_remove
remove the original data/EA (file is completely deleted)
Definition: crit_action.hpp:52
@ data_undefined
action still undefined at this step of the evaluation
Definition: crit_action.hpp:53
@ data_overwrite_mark_already_saved
overwrite the 'in place' but mark the 'to be added' as already saved in the archive of reference
Definition: crit_action.hpp:51
bool ea() noexcept
returns whether EA support has been activated at compilation time
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47