crit_action.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2023 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef CRIT_ACTION_HPP
#define CRIT_ACTION_HPP
#include "../my_config.h"
#include <deque>
#include "criterium.hpp"
namespace libdar
{
class cat_nomme;
enum over_action_data
{
data_preserve,
data_overwrite,
data_preserve_mark_already_saved,
data_overwrite_mark_already_saved,
data_remove,
data_undefined,
data_ask
};
enum over_action_ea
{
EA_preserve,
EA_overwrite,
EA_clear,
EA_preserve_mark_already_saved,
EA_overwrite_mark_already_saved,
EA_merge_preserve,
EA_merge_overwrite,
EA_undefined,
EA_ask
};
class crit_action
{
public:
crit_action() = default;
crit_action(const crit_action & ref) = default;
crit_action(crit_action && ref) noexcept = default;
crit_action & operator = (const crit_action & ref) = default;
crit_action & operator = (crit_action && ref) noexcept = default;
virtual ~crit_action() = default;
virtual void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const = 0;
virtual crit_action *clone() const = 0;
};
class crit_constant_action : public crit_action
{
public:
crit_constant_action(over_action_data data, over_action_ea ea) { x_data = data; x_ea = ea; };
crit_constant_action(const crit_constant_action & ref) = default;
crit_constant_action & operator = (const crit_constant_action & ref) = default;
~crit_constant_action() = default;
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; };
virtual crit_action *clone() const override { return new (std::nothrow) crit_constant_action(*this); };
private:
over_action_data x_data;
over_action_ea x_ea;
};
class testing : public crit_action
{
public:
testing(const criterium & input, const crit_action & go_true, const crit_action & go_false);
testing(const testing & ref) : crit_action(ref) { copy_from(ref); if(!check()) throw Ememory("testing::testing(const testing &)"); };
testing(testing && ref) noexcept : crit_action(std::move(ref)) { nullifyptr(); move_from(std::move(ref)); };
testing & operator = (const testing & ref) { free(); copy_from(ref); if(!check()) throw Ememory("testing::testing(const testing &)"); return *this; };
testing & operator = (testing && ref) noexcept { crit_action::operator = (std::move(ref)); move_from(std::move(ref)); return *this; };
~testing() { free(); };
virtual void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const override
{
if(x_input->evaluate(first, second))
x_go_true->get_action(first, second, data, ea);
else
x_go_false->get_action(first, second, data, ea);
};
virtual crit_action *clone() const override { return new (std::nothrow) testing(*this); };
private:
criterium *x_input;
crit_action *x_go_true;
crit_action *x_go_false;
void nullifyptr() noexcept { x_input = nullptr; x_go_true = x_go_false = nullptr; };
void free() noexcept;
void copy_from(const testing & ref);
void move_from(testing && ref) noexcept;
bool check() const;
};
class crit_chain : public crit_action
{
public:
crit_chain() { sequence.clear(); };
crit_chain(const crit_chain & ref) : crit_action(ref) { copy_from(ref); };
crit_chain(crit_chain && ref) noexcept : crit_action(std::move(ref)) { sequence = std::move(ref.sequence); };
crit_chain & operator = (const crit_chain & ref) { destroy(); copy_from(ref); return *this; };
crit_chain & operator = (crit_chain && ref) noexcept { crit_action::operator = (std::move(ref)); sequence = std::move(ref.sequence); return *this; };
~crit_chain() { destroy(); };
void add(const crit_action & act);
void clear() { destroy(); };
void gobe(crit_chain & to_be_voided);
virtual void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const override;
virtual crit_action *clone() const override { return new (std::nothrow) crit_chain(*this); };
private:
std::deque<crit_action *> sequence;
void destroy();
void copy_from(const crit_chain & ref);
};
} // end of namespace
#endif
libdar::Ememory
exception used when memory has been exhausted
Definition: erreurs.hpp:127
libdar::cat_nomme
the base class for all entry that have a name
Definition: cat_nomme.hpp:45
libdar::crit_action
the global action for overwriting
Definition: crit_action.hpp:81
libdar::crit_action::~crit_action
virtual ~crit_action()=default
the destructor
libdar::crit_action::get_action
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
libdar::crit_action::clone
virtual crit_action * clone() const =0
clone construction method
libdar::crit_chain
the crit_chain class sequences crit_actions up to full definition of the action
Definition: crit_action.hpp:188
libdar::crit_chain::clone
virtual crit_action * clone() const override
clone construction method
Definition: crit_action.hpp:203
libdar::crit_chain::get_action
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
libdar::crit_constant_action
the basic constant action
Definition: crit_action.hpp:115
libdar::crit_constant_action::crit_constant_action
crit_constant_action(over_action_data data, over_action_ea ea)
the constuctor
Definition: crit_action.hpp:121
libdar::crit_constant_action::get_action
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
Definition: crit_action.hpp:128
libdar::crit_constant_action::clone
virtual crit_action * clone() const override
clone construction method
Definition: crit_action.hpp:129
libdar::criterium
the generic criterium class, parent of all criterium
Definition: criterium.hpp:52
libdar::criterium::evaluate
virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const =0
criterum interface method
libdar::testing
the testing class binds criterium to actions
Definition: crit_action.hpp:143
libdar::testing::clone
virtual crit_action * clone() const override
clone construction method
Definition: crit_action.hpp:167
libdar::testing::get_action
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
Definition: crit_action.hpp:159
libdar::testing::check
bool check() const
returns false if an field is nullptr
libdar::testing::testing
testing(const criterium &input, const crit_action &go_true, const crit_action &go_false)
the constructor
criterium.hpp
contains classes that let the user define the policy for overwriting files
libdar::over_action_ea
over_action_ea
the possible action for overwriting EA
Definition: crit_action.hpp:62
libdar::over_action_data
over_action_data
the possible actions for overwriting data
Definition: crit_action.hpp:47
libdar::EA_ask
@ EA_ask
ask for user decision about EA
Definition: crit_action.hpp:71
libdar::EA_merge_preserve
@ 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
libdar::EA_preserve_mark_already_saved
@ 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
libdar::EA_overwrite
@ EA_overwrite
keep the EA of the 'to be added' entry
Definition: crit_action.hpp:64
libdar::EA_preserve
@ EA_preserve
keep the EA of the 'in place' entry
Definition: crit_action.hpp:63
libdar::EA_merge_overwrite
@ 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
libdar::EA_undefined
@ EA_undefined
action still undefined at this step of the evaluation
Definition: crit_action.hpp:70
libdar::EA_clear
@ EA_clear
drop the EA for the elected entry
Definition: crit_action.hpp:65
libdar::EA_overwrite_mark_already_saved
@ 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
libdar::data_preserve
@ data_preserve
do not overwrite (keep the 'in place' entry)
Definition: crit_action.hpp:48
libdar::data_preserve_mark_already_saved
@ 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
libdar::data_overwrite
@ data_overwrite
overwirte the 'in place' entry by the 'to be added' one
Definition: crit_action.hpp:49
libdar::data_ask
@ data_ask
ask for user decision about file's data
Definition: crit_action.hpp:54
libdar::data_remove
@ data_remove
remove the original data/EA (file is completely deleted)
Definition: crit_action.hpp:52
libdar::data_undefined
@ data_undefined
action still undefined at this step of the evaluation
Definition: crit_action.hpp:53
libdar::data_overwrite_mark_already_saved
@ 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
libdar::compile_time::ea
bool ea() noexcept
returns whether EA support has been activated at compilation time
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47