Disk ARchive  2.4.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
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 <new>
00032 
00033 #include "catalogue.hpp"
00034 
00035 namespace libdar
00036 {
00037 
00040 
00042 
00043     enum over_action_data
00044     {
00045         data_preserve,                     //< do not overwrite (keep the 'in place' entry)
00046         data_overwrite,                    //< overwirte the 'in place' entry by the 'to be added' one
00047         data_preserve_mark_already_saved,  //< keep the 'in place' but mark it as already saved in the archive of reference
00048         data_overwrite_mark_already_saved, //< overwrite the 'in place' but mark the 'to be added' as already saved in the archive of reference
00049         data_remove,                       //< remove the original data/EA (file is completely deleted)
00050         data_undefined,                    //< action still undefined at this step of the evaluation
00051         data_ask                           //< ask for user decision about file's data
00052     };
00053 
00054 
00056 
00057     enum over_action_ea //< define the action to apply to each EA entry (not to the EA set of a particular inode)
00058     {
00059         EA_preserve,                     //< keep the EA of the 'in place' entry
00060         EA_overwrite,                    //< keep the EA of the 'to be added' entry
00061         EA_clear,                        //< drop the EA for the elected entry
00062         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)
00063         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)
00064         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
00065         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
00066         EA_undefined,                    //< action still undefined at this step of the evaluation
00067         EA_ask                           //< ask for user decision about EA
00068     };
00069 
00070 
00072 
00075 
00076     class crit_action
00077     {
00078     public:
00080         virtual ~crit_action() {};
00081 
00083 
00088         virtual void get_action(const nomme & first, const nomme & second, over_action_data & data, over_action_ea & ea) const = 0;
00089 
00091 
00095         virtual crit_action *clone() const = 0;
00096     };
00097 
00098 
00100 
00103 
00104     class crit_constant_action : public crit_action
00105     {
00106     public:
00108 
00111         crit_constant_action(over_action_data data, over_action_ea ea) { x_data = data; x_ea = ea; };
00112 
00113 
00115         void get_action(const nomme & first, const nomme & second, over_action_data & data, over_action_ea & ea) const { data = x_data; ea = x_ea; };
00116         crit_action *clone() const { return new (std::nothrow) crit_constant_action(*this); };
00117 
00118     private:
00119         over_action_data x_data;
00120         over_action_ea x_ea;
00121     };
00122 
00123 
00124 
00126 
00131 
00132     class criterium
00133     {
00134     public:
00135         virtual ~criterium() {};
00136 
00138 
00142         virtual bool evaluate(const nomme &first, const nomme &second) const = 0;
00143 
00145 
00149         virtual criterium *clone() const = 0;
00150 
00151     protected:
00152         static const inode *get_inode(const nomme * arg);
00153     };
00154 
00155 
00156 
00158 
00161 
00162     class testing : public crit_action
00163     {
00164     public:
00166 
00170         testing(const criterium & input, const crit_action & go_true, const crit_action & go_false);
00171         testing(const testing & ref) : crit_action(ref) { copy_from(ref); if(!check()) throw Ememory("testing::testing(const testing &)"); };
00172         const testing & operator = (const testing & ref) { free(); copy_from(ref); if(!check()) throw Ememory("testing::testing(const testing &)"); };
00173         ~testing() { free(); };
00174 
00175 
00177         void get_action(const nomme & first, const nomme & second, over_action_data & data, over_action_ea & ea) const
00178         {
00179             if(x_input->evaluate(first, second))
00180                 x_go_true->get_action(first, second, data, ea);
00181             else
00182                 x_go_false->get_action(first, second, data, ea);
00183         };
00184 
00185         crit_action *clone() const { return new (std::nothrow) testing(*this); };
00186 
00187     private:
00188         criterium *x_input;
00189         crit_action *x_go_true;
00190         crit_action *x_go_false;
00191 
00192         void free();
00193         void copy_from(const testing & ref);
00194         bool check() const; //< returns false if an field is NULL
00195     };
00196 
00197 
00199 
00202 
00203     class crit_chain : public crit_action
00204     {
00205     public:
00206         crit_chain() { sequence.clear(); };
00207         crit_chain(const crit_chain & ref) : crit_action(ref) { copy_from(ref); };
00208         const crit_chain & operator = (const crit_chain & ref) { destroy(); copy_from(ref); return *this; };
00209         ~crit_chain() { destroy(); };
00210 
00211         void add(const crit_action & act);
00212         void clear() { destroy(); };
00213         void gobe(crit_chain & to_be_voided);
00214 
00215         void get_action(const nomme & first, const nomme & second, over_action_data & data, over_action_ea & ea) const;
00216 
00217         crit_action *clone() const { return new (std::nothrow) crit_chain(*this); };
00218 
00219     private:
00220         std::vector<crit_action *> sequence;
00221 
00222         void destroy();
00223         void copy_from(const crit_chain & ref);
00224     };
00225 
00229 
00230 
00232 
00235 
00236     class crit_in_place_is_inode : public criterium
00237     {
00238     public:
00239         bool evaluate(const nomme &first, const nomme &second) const { return dynamic_cast<const inode *>(&first) != NULL || dynamic_cast<const mirage *>(&first) != NULL; };
00240         criterium *clone() const { return new (std::nothrow) crit_in_place_is_inode(*this); };
00241     };
00242 
00243 
00245 
00246     class crit_in_place_is_dir : public criterium
00247     {
00248     public:
00249         bool evaluate(const nomme &first, const nomme &second) const { return dynamic_cast<const directory *>(&first) != NULL; };
00250         criterium *clone() const { return new (std::nothrow) crit_in_place_is_dir(*this); };
00251     };
00252 
00253 
00255 
00256     class crit_in_place_is_file : public criterium
00257     {
00258     public:
00259         bool evaluate(const nomme &first, const nomme &second) const;
00260         criterium *clone() const { return new (std::nothrow) crit_in_place_is_file(*this); };
00261     };
00262 
00264 
00266 
00267     class crit_in_place_is_hardlinked_inode : public criterium
00268     {
00269     public:
00270         bool evaluate(const nomme &first, const nomme &second) const { return dynamic_cast<const mirage *>(&first) != NULL; };
00271         criterium *clone() const { return new (std::nothrow) crit_in_place_is_hardlinked_inode(*this); };
00272     };
00273 
00274 
00276     class crit_in_place_is_new_hardlinked_inode : public criterium
00277     {
00278         bool evaluate(const nomme &first, const nomme &second) const
00279         {
00280             const mirage * tmp = dynamic_cast<const mirage *>(&first);
00281             return tmp != NULL && tmp->is_first_mirage();
00282         };
00283         criterium *clone() const { return new (std::nothrow) crit_in_place_is_new_hardlinked_inode(*this); };
00284     };
00285 
00286 
00288 
00290 
00291     class crit_in_place_data_more_recent : public criterium
00292     {
00293     public:
00294         crit_in_place_data_more_recent(const infinint & hourshift = 0) : x_hourshift(hourshift) {};
00295 
00296         bool evaluate(const nomme &first, const nomme &second) const;
00297         criterium *clone() const { return new (std::nothrow) crit_in_place_data_more_recent(*this); };
00298 
00299     private:
00300         infinint x_hourshift;
00301     };
00302 
00303 
00305 
00307 
00308 
00309     class crit_in_place_data_more_recent_or_equal_to : public criterium
00310     {
00311     public:
00312         crit_in_place_data_more_recent_or_equal_to(const infinint & date, const infinint & hourshift = 0) : x_hourshift(hourshift), x_date(date) {};
00313 
00314         bool evaluate(const nomme &first, const nomme &second) const;
00315         criterium *clone() const { return new (std::nothrow) crit_in_place_data_more_recent_or_equal_to(*this); };
00316 
00317     private:
00318         infinint x_hourshift;
00319         infinint x_date;
00320     };
00321 
00322 
00324 
00326 
00327     class crit_in_place_data_bigger : public criterium
00328     {
00329     public:
00330         bool evaluate(const nomme &first, const nomme &second) const;
00331         criterium *clone() const { return new (std::nothrow) crit_in_place_data_bigger(*this); };
00332     };
00333 
00334 
00335 
00337 
00339 
00340     class crit_in_place_data_saved : public criterium
00341     {
00342     public:
00343         bool evaluate(const nomme &first, const nomme &second) const;
00344         criterium *clone() const { return new (std::nothrow) crit_in_place_data_saved(*this); };
00345     };
00346 
00347 
00349 
00350     class crit_in_place_data_dirty : public criterium
00351     {
00352     public:
00353         bool evaluate(const nomme &first, const nomme &second) const;
00354         criterium *clone() const { return new (std::nothrow) crit_in_place_data_dirty(*this); };
00355     };
00356 
00358 
00359     class crit_in_place_data_sparse : public criterium
00360     {
00361     public:
00362         bool evaluate(const nomme &first, const nomme &second) const;
00363         criterium *clone() const { return new (std::nothrow) crit_in_place_data_sparse(*this); };
00364     };
00365 
00366 
00369 
00370     class crit_in_place_EA_present : public criterium
00371     {
00372     public:
00373         bool evaluate(const nomme &first, const nomme &second) const
00374         {
00375             const inode *tmp = dynamic_cast<const inode *>(&first);
00376             return tmp != NULL && tmp->ea_get_saved_status() != inode::ea_none && tmp->ea_get_saved_status() != inode::ea_removed;
00377         };
00378         criterium *clone() const { return new (std::nothrow) crit_in_place_EA_present(*this); };
00379     };
00380 
00381 
00383 
00388 
00389     class crit_in_place_EA_more_recent : public criterium
00390     {
00391     public:
00392         crit_in_place_EA_more_recent(const infinint & hourshift = 0) : x_hourshift(hourshift) {};
00393 
00394         bool evaluate(const nomme &first, const nomme &second) const;
00395         criterium *clone() const { return new (std::nothrow) crit_in_place_EA_more_recent(*this); };
00396 
00397     private:
00398         infinint x_hourshift;
00399     };
00400 
00401 
00403 
00406 
00407     class crit_in_place_EA_more_recent_or_equal_to : public criterium
00408     {
00409     public:
00410         crit_in_place_EA_more_recent_or_equal_to(const infinint & date, const infinint & hourshift = 0) : x_hourshift(hourshift), x_date(date) {};
00411 
00412         bool evaluate(const nomme &first, const nomme &second) const;
00413         criterium *clone() const { return new (std::nothrow) crit_in_place_EA_more_recent_or_equal_to(*this); };
00414 
00415     private:
00416         infinint x_hourshift;
00417         infinint x_date;
00418     };
00419 
00420 
00422 
00424 
00425     class crit_in_place_more_EA : public criterium
00426     {
00427     public:
00428         bool evaluate(const nomme &first, const nomme &second) const;
00429         criterium *clone() const { return new (std::nothrow) crit_in_place_more_EA(*this); };
00430     };
00431 
00432 
00433 
00435 
00437 
00438     class crit_in_place_EA_bigger : public crit_in_place_more_EA
00439     {
00440     public:
00441         bool evaluate(const nomme &first, const nomme &second) const;
00442         criterium *clone() const { return new (std::nothrow) crit_in_place_EA_bigger(*this); };
00443     };
00444 
00445 
00447 
00449 
00450     class crit_in_place_EA_saved : public criterium
00451     {
00452     public:
00453         bool evaluate(const nomme &first, const nomme &second) const;
00454         criterium *clone() const { return new (std::nothrow) crit_in_place_EA_saved(*this); };
00455     };
00456 
00457 
00459 
00462 
00463     class crit_same_type : public criterium
00464     {
00465     public:
00466         bool evaluate(const nomme &first, const nomme &second) const;
00467         criterium *clone() const { return new (std::nothrow) crit_same_type(*this); };
00468     };
00469 
00470 
00472 
00473     class crit_not : public criterium
00474     {
00475     public:
00476         crit_not(const criterium & crit) { x_crit = crit.clone(); if(x_crit == NULL) throw Ememory("crit_not::crit_not"); };
00477         crit_not(const crit_not & ref) : criterium (ref) { copy_from(ref); };
00478         const crit_not & operator = (const crit_not & ref) { destroy(); copy_from(ref); return *this; };
00479         ~crit_not() { destroy(); };
00480 
00481         bool evaluate(const nomme & first, const nomme & second) const { return ! x_crit->evaluate(first, second); };
00482         criterium *clone() const { return new (std::nothrow) crit_not(*this); };
00483 
00484     protected:
00485         const criterium *x_crit;
00486 
00487     private:
00488         void copy_from(const crit_not & ref);
00489         void destroy() { if(x_crit != NULL) { delete x_crit; x_crit = NULL; } };
00490     };
00491 
00493 
00494     class crit_and : public criterium
00495     {
00496     public:
00497         crit_and() { clear(); };
00498         crit_and(const crit_and & ref) : criterium(ref) { copy_from(ref); };
00499         const crit_and & operator = (const crit_and & ref) { detruit(); copy_from(ref); return *this; };
00500         ~crit_and() { detruit(); };
00501 
00502         void add_crit(const criterium & ref);
00503         void clear() { detruit(); };
00504 
00506         void gobe(crit_and & to_be_voided);
00507 
00508         virtual bool evaluate(const nomme & first, const nomme & second) const;
00509         criterium *clone() const { return new (std::nothrow) crit_and(*this); };
00510 
00511     protected:
00512         std::vector<criterium *> operand;
00513 
00514     private:
00515         void copy_from(const crit_and & ref);
00516         void detruit();
00517     };
00518 
00519     class crit_or : public crit_and
00520     {
00521     public:
00522         crit_or() { clear(); };
00523 
00524         bool evaluate(const nomme & first, const nomme & second) const;
00525         criterium *clone() const { return new (std::nothrow) crit_or(*this); };
00526 
00527     };
00528 
00529     class crit_invert : public crit_not
00530     {
00531     public:
00532         crit_invert(const criterium & crit) : crit_not(crit) {};
00533 
00534         bool evaluate(const nomme & first, const nomme & second) const { return x_crit->evaluate(second, first); };
00535         criterium *clone() const { return new (std::nothrow) crit_invert(*this); };
00536     };
00537 
00538 
00540 
00546     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);
00547 
00549 
00555     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);
00556 
00558 
00563     extern void crit_show_entry_info(user_interaction & dialog, const std::string & full_name, const entree *already_here, const entree *dolly);
00564 
00566 
00567 } // end of namespace
00568 
00569 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines