Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
criterium.hpp
Go to the documentation of this file.
00001 /*********************************************************************/
00002 // dar - disk archive - a backup/restoration program
00003 // Copyright (C) 2002-2052 Denis Corbin
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 // to contact the author : http://dar.linux.free.fr/email.html
00020 /*********************************************************************/
00021 
00025 
00026 #ifndef CRITERIUM_HPP
00027 #define CRITERIUM_HPP
00028 
00029 #include "../my_config.h"
00030 
00031 #include "on_pool.hpp"
00032 #include "cat_nomme.hpp"
00033 #include "cat_inode.hpp"
00034 #include "cat_directory.hpp"
00035 
00036 namespace libdar
00037 {
00038 
00041 
00043 
00044     enum over_action_data
00045     {
00046     data_preserve,                     //< do not overwrite (keep the 'in place' entry)
00047     data_overwrite,                    //< overwirte the 'in place' entry by the 'to be added' one
00048     data_preserve_mark_already_saved,  //< keep the 'in place' but mark it as already saved in the archive of reference
00049     data_overwrite_mark_already_saved, //< overwrite the 'in place' but mark the 'to be added' as already saved in the archive of reference
00050     data_remove,                       //< remove the original data/EA (file is completely deleted)
00051     data_undefined,                    //< action still undefined at this step of the evaluation
00052     data_ask                           //< ask for user decision about file's data
00053     };
00054 
00055 
00057 
00058     enum over_action_ea //< define the action to apply to each EA entry (not to the EA set of a particular inode)
00059     {
00060     EA_preserve,                     //< keep the EA of the 'in place' entry
00061     EA_overwrite,                    //< keep the EA of the 'to be added' entry
00062     EA_clear,                        //< drop the EA for the elected entry
00063         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)
00064         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)
00065     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
00066     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
00067     EA_undefined,                    //< action still undefined at this step of the evaluation
00068     EA_ask                           //< ask for user decision about EA
00069     };
00070 
00071 
00073 
00076 
00077     class crit_action: public on_pool
00078     {
00079     public:
00081     virtual ~crit_action() {};
00082 
00084 
00089     virtual void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const = 0;
00090 
00092 
00096     virtual crit_action *clone() const = 0;
00097     };
00098 
00099 
00101 
00104 
00105     class crit_constant_action : public crit_action
00106     {
00107     public:
00109 
00112     crit_constant_action(over_action_data data, over_action_ea ea) { x_data = data; x_ea = ea; };
00113 
00114 
00116     void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const { data = x_data; ea = x_ea; };
00117     crit_action *clone() const { return new (get_pool()) crit_constant_action(*this); };
00118 
00119     private:
00120     over_action_data x_data;
00121     over_action_ea x_ea;
00122     };
00123 
00124 
00125 
00127 
00132 
00133     class criterium : public on_pool
00134     {
00135     public:
00136     virtual ~criterium() throw(Ebug) {};
00137 
00139 
00143     virtual bool evaluate(const cat_nomme &first, const cat_nomme &second) const = 0;
00144 
00146 
00150     virtual criterium *clone() const = 0;
00151 
00152     protected:
00153     static const cat_inode *get_inode(const cat_nomme * arg);
00154     };
00155 
00156 
00157 
00159 
00162 
00163     class testing : public crit_action
00164     {
00165     public:
00167 
00171     testing(const criterium & input, const crit_action & go_true, const crit_action & go_false);
00172     testing(const testing & ref) : crit_action(ref) { copy_from(ref); if(!check()) throw Ememory("testing::testing(const testing &)"); };
00173     const testing & operator = (const testing & ref) { free(); copy_from(ref); if(!check()) throw Ememory("testing::testing(const testing &)"); return *this; };
00174     ~testing() { free(); };
00175 
00176 
00178     void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const
00179     {
00180         if(x_input->evaluate(first, second))
00181         x_go_true->get_action(first, second, data, ea);
00182         else
00183         x_go_false->get_action(first, second, data, ea);
00184     };
00185 
00186     crit_action *clone() const { return new (get_pool()) testing(*this); };
00187 
00188     private:
00189     criterium *x_input;
00190     crit_action *x_go_true;
00191     crit_action *x_go_false;
00192 
00193     void free();
00194     void copy_from(const testing & ref);
00195     bool check() const; //< returns false if an field is nullptr
00196     };
00197 
00198 
00200 
00203 
00204     class crit_chain : public crit_action
00205     {
00206     public:
00207     crit_chain() { sequence.clear(); };
00208     crit_chain(const crit_chain & ref) : crit_action(ref) { copy_from(ref); };
00209     const crit_chain & operator = (const crit_chain & ref) { destroy(); copy_from(ref); return *this; };
00210     ~crit_chain() { destroy(); };
00211 
00212     void add(const crit_action & act);
00213     void clear() { destroy(); };
00214     void gobe(crit_chain & to_be_voided);
00215 
00216     void get_action(const cat_nomme & first, const cat_nomme & second, over_action_data & data, over_action_ea & ea) const;
00217 
00218     crit_action *clone() const { return new (get_pool()) crit_chain(*this); };
00219 
00220     private:
00221     std::vector<crit_action *> sequence;
00222 
00223     void destroy();
00224     void copy_from(const crit_chain & ref);
00225     };
00226 
00230 
00231 
00233 
00236 
00237     class crit_in_place_is_inode : public criterium
00238     {
00239     public:
00240     bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
00241     criterium *clone() const { return new (get_pool()) crit_in_place_is_inode(*this); };
00242     };
00243 
00244 
00246 
00247     class crit_in_place_is_dir : public criterium
00248     {
00249     public:
00250     bool evaluate(const cat_nomme &first, const cat_nomme &second) const { return dynamic_cast<const cat_directory *>(&first) != nullptr; };
00251     criterium *clone() const { return new (get_pool()) crit_in_place_is_dir(*this); };
00252     };
00253 
00254 
00256 
00257     class crit_in_place_is_file : public criterium
00258     {
00259     public:
00260     bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
00261     criterium *clone() const { return new (get_pool()) crit_in_place_is_file(*this); };
00262     };
00263 
00265 
00267 
00268     class crit_in_place_is_hardlinked_inode : public criterium
00269     {
00270     public:
00271     bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
00272     criterium *clone() const { return new (get_pool()) crit_in_place_is_hardlinked_inode(*this); };
00273     };
00274 
00275 
00277     class crit_in_place_is_new_hardlinked_inode : public criterium
00278     {
00279     public:
00280     bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
00281     criterium *clone() const { return new (get_pool()) crit_in_place_is_new_hardlinked_inode(*this); };
00282     };
00283 
00284 
00286 
00288 
00289     class crit_in_place_data_more_recent : public criterium
00290     {
00291     public:
00292     crit_in_place_data_more_recent(const infinint & hourshift = 0) : x_hourshift(hourshift) {};
00293 
00294     bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
00295     criterium *clone() const { return new (get_pool()) crit_in_place_data_more_recent(*this); };
00296 
00297     private:
00298     infinint x_hourshift;
00299     };
00300 
00301 
00303 
00305 
00306 
00307     class crit_in_place_data_more_recent_or_equal_to : public criterium
00308     {
00309     public:
00310     crit_in_place_data_more_recent_or_equal_to(const infinint & date, const infinint & hourshift = 0) : x_hourshift(hourshift), x_date(date) {};
00311 
00312     bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
00313     criterium *clone() const { return new (get_pool()) crit_in_place_data_more_recent_or_equal_to(*this); };
00314 
00315     private:
00316     infinint x_hourshift;
00317     infinint x_date;
00318     };
00319 
00320 
00322 
00324 
00325     class crit_in_place_data_bigger : public criterium
00326     {
00327     public:
00328     bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
00329     criterium *clone() const { return new (get_pool()) crit_in_place_data_bigger(*this); };
00330     };
00331 
00332 
00333 
00335 
00337 
00338     class crit_in_place_data_saved : public criterium
00339     {
00340     public:
00341     bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
00342     criterium *clone() const { return new (get_pool()) crit_in_place_data_saved(*this); };
00343     };
00344 
00345 
00347 
00348     class crit_in_place_data_dirty : public criterium
00349     {
00350     public:
00351     bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
00352     criterium *clone() const { return new (get_pool()) crit_in_place_data_dirty(*this); };
00353     };
00354 
00356 
00357     class crit_in_place_data_sparse : public criterium
00358     {
00359     public:
00360     bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
00361     criterium *clone() const { return new (get_pool()) crit_in_place_data_sparse(*this); };
00362     };
00363 
00364 
00367 
00368     class crit_in_place_EA_present : public criterium
00369     {
00370     public:
00371     bool evaluate(const cat_nomme &first, const cat_nomme &second) const
00372     {
00373         const cat_inode *tmp = dynamic_cast<const cat_inode *>(&first);
00374         return tmp != nullptr && tmp->ea_get_saved_status() != cat_inode::ea_none && tmp->ea_get_saved_status() != cat_inode::ea_removed;
00375     };
00376     criterium *clone() const { return new (get_pool()) crit_in_place_EA_present(*this); };
00377     };
00378 
00379 
00381 
00386 
00387     class crit_in_place_EA_more_recent : public criterium
00388     {
00389     public:
00390     crit_in_place_EA_more_recent(const infinint & hourshift = 0) : x_hourshift(hourshift) {};
00391 
00392     bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
00393     criterium *clone() const { return new (get_pool()) crit_in_place_EA_more_recent(*this); };
00394 
00395     private:
00396     infinint x_hourshift;
00397     };
00398 
00399 
00401 
00404 
00405     class crit_in_place_EA_more_recent_or_equal_to : public criterium
00406     {
00407     public:
00408     crit_in_place_EA_more_recent_or_equal_to(const infinint & date, const infinint & hourshift = 0) : x_hourshift(hourshift), x_date(date) {};
00409 
00410     bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
00411     criterium *clone() const { return new (get_pool()) crit_in_place_EA_more_recent_or_equal_to(*this); };
00412 
00413     private:
00414     infinint x_hourshift;
00415     infinint x_date;
00416     };
00417 
00418 
00420 
00422 
00423     class crit_in_place_more_EA : public criterium
00424     {
00425     public:
00426     bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
00427     criterium *clone() const { return new (get_pool()) crit_in_place_more_EA(*this); };
00428     };
00429 
00430 
00431 
00433 
00435 
00436     class crit_in_place_EA_bigger : public crit_in_place_more_EA
00437     {
00438     public:
00439     bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
00440     criterium *clone() const { return new (get_pool()) crit_in_place_EA_bigger(*this); };
00441     };
00442 
00443 
00445 
00447 
00448     class crit_in_place_EA_saved : public criterium
00449     {
00450     public:
00451     bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
00452     criterium *clone() const { return new (get_pool()) crit_in_place_EA_saved(*this); };
00453     };
00454 
00455 
00457 
00460 
00461     class crit_same_type : public criterium
00462     {
00463     public:
00464     bool evaluate(const cat_nomme &first, const cat_nomme &second) const;
00465     criterium *clone() const { return new (get_pool()) crit_same_type(*this); };
00466     };
00467 
00468 
00470 
00471     class crit_not : public criterium
00472     {
00473     public:
00474     crit_not(const criterium & crit) { x_crit = crit.clone(); if(x_crit == nullptr) throw Ememory("crit_not::crit_not"); };
00475     crit_not(const crit_not & ref) : criterium (ref) { copy_from(ref); };
00476     const crit_not & operator = (const crit_not & ref) { destroy(); copy_from(ref); return *this; };
00477     ~crit_not() { destroy(); };
00478 
00479     bool evaluate(const cat_nomme & first, const cat_nomme & second) const { return ! x_crit->evaluate(first, second); };
00480     criterium *clone() const { return new (get_pool()) crit_not(*this); };
00481 
00482     protected:
00483     const criterium *x_crit;
00484 
00485     private:
00486     void copy_from(const crit_not & ref);
00487     void destroy() { if(x_crit != nullptr) { delete x_crit; x_crit = nullptr; } };
00488     };
00489 
00491 
00492     class crit_and : public criterium
00493     {
00494     public:
00495     crit_and() { clear(); };
00496     crit_and(const crit_and & ref) : criterium(ref) { copy_from(ref); };
00497     const crit_and & operator = (const crit_and & ref) { detruit(); copy_from(ref); return *this; };
00498     ~crit_and() { detruit(); };
00499 
00500     void add_crit(const criterium & ref);
00501     void clear() { detruit(); };
00502 
00504     void gobe(crit_and & to_be_voided);
00505 
00506     virtual bool evaluate(const cat_nomme & first, const cat_nomme & second) const;
00507     criterium *clone() const { return new (get_pool()) crit_and(*this); };
00508 
00509     protected:
00510     std::vector<criterium *> operand;
00511 
00512     private:
00513     void copy_from(const crit_and & ref);
00514     void detruit();
00515     };
00516 
00517     class crit_or : public crit_and
00518     {
00519     public:
00520     crit_or() { clear(); };
00521 
00522     bool evaluate(const cat_nomme & first, const cat_nomme & second) const;
00523     criterium *clone() const { return new (get_pool()) crit_or(*this); };
00524 
00525     };
00526 
00527     class crit_invert : public crit_not
00528     {
00529     public:
00530     crit_invert(const criterium & crit) : crit_not(crit) {};
00531 
00532     bool evaluate(const cat_nomme & first, const cat_nomme & second) const { return x_crit->evaluate(second, first); };
00533     criterium *clone() const { return new (get_pool()) crit_invert(*this); };
00534     };
00535 
00536 
00538 
00544     extern over_action_ea crit_ask_user_for_EA_action(user_interaction & dialog, const std::string & full_name, const cat_entree *already_here, const cat_entree *dolly);
00545 
00547 
00553     extern over_action_ea crit_ask_user_for_FSA_action(user_interaction & dialog, const std::string & full_name, const cat_entree *already_here, const cat_entree *dolly);
00554 
00556 
00562     extern over_action_data crit_ask_user_for_data_action(user_interaction & dialog, const std::string & full_name, const cat_entree *already_here, const cat_entree *dolly);
00563 
00564 
00566 
00571     extern void crit_show_entry_info(user_interaction & dialog, const std::string & full_name, const cat_entree *already_here, const cat_entree *dolly);
00572 
00574 
00575 } // end of namespace
00576 
00577 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines