Disk ARchive  2.4.5
 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 // $Id$
00022 //
00023 /*********************************************************************/
00024 
00028 
00029 #ifndef CRITERIUM_HPP
00030 #define CRITERIUM_HPP
00031 
00032 #include "../my_config.h"
00033 
00034 #include "catalogue.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
00078     {
00079     public:
00081         virtual ~crit_action() {};
00082 
00084 
00089         virtual void get_action(const nomme & first, const 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 nomme & first, const nomme & second, over_action_data & data, over_action_ea & ea) const { data = x_data; ea = x_ea; };
00117         crit_action *clone() const { return new 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
00134     {
00135     public:
00136         virtual ~criterium() {};
00137 
00139 
00143         virtual bool evaluate(const nomme &first, const nomme &second) const = 0;
00144 
00146 
00150         virtual criterium *clone() const = 0;
00151 
00152     protected:
00153         static const inode *get_inode(const 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 &)"); };
00174         ~testing() { free(); };
00175 
00176 
00178         void get_action(const nomme & first, const 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 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 NULL
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 nomme & first, const nomme & second, over_action_data & data, over_action_ea & ea) const;
00217 
00218         crit_action *clone() const { return new 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 nomme &first, const nomme &second) const { return dynamic_cast<const inode *>(&first) != NULL || dynamic_cast<const mirage *>(&first) != NULL; };
00241         criterium *clone() const { return new 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 nomme &first, const nomme &second) const { return dynamic_cast<const directory *>(&first) != NULL; };
00251         criterium *clone() const { return new 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 nomme &first, const nomme &second) const;
00261         criterium *clone() const { return new 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 nomme &first, const nomme &second) const { return dynamic_cast<const mirage *>(&first) != NULL; };
00272         criterium *clone() const { return new crit_in_place_is_hardlinked_inode(*this); };
00273     };
00274 
00275 
00277     class crit_in_place_is_new_hardlinked_inode : public criterium
00278     {
00279         bool evaluate(const nomme &first, const nomme &second) const
00280         {
00281             const mirage * tmp = dynamic_cast<const mirage *>(&first);
00282             return tmp != NULL && tmp->is_first_mirage();
00283         };
00284         criterium *clone() const { return new crit_in_place_is_new_hardlinked_inode(*this); };
00285     };
00286 
00287 
00289 
00291 
00292     class crit_in_place_data_more_recent : public criterium
00293     {
00294     public:
00295         crit_in_place_data_more_recent(const infinint & hourshift = 0) : x_hourshift(hourshift) {};
00296 
00297         bool evaluate(const nomme &first, const nomme &second) const;
00298         criterium *clone() const { return new crit_in_place_data_more_recent(*this); };
00299 
00300     private:
00301         infinint x_hourshift;
00302     };
00303 
00304 
00306 
00308 
00309 
00310     class crit_in_place_data_more_recent_or_equal_to : public criterium
00311     {
00312     public:
00313         crit_in_place_data_more_recent_or_equal_to(const infinint & date, const infinint & hourshift = 0) : x_hourshift(hourshift), x_date(date) {};
00314 
00315         bool evaluate(const nomme &first, const nomme &second) const;
00316         criterium *clone() const { return new crit_in_place_data_more_recent_or_equal_to(*this); };
00317 
00318     private:
00319         infinint x_hourshift;
00320         infinint x_date;
00321     };
00322 
00323 
00325 
00327 
00328     class crit_in_place_data_bigger : public criterium
00329     {
00330     public:
00331         bool evaluate(const nomme &first, const nomme &second) const;
00332         criterium *clone() const { return new crit_in_place_data_bigger(*this); };
00333     };
00334 
00335 
00336 
00338 
00340 
00341     class crit_in_place_data_saved : public criterium
00342     {
00343     public:
00344         bool evaluate(const nomme &first, const nomme &second) const;
00345         criterium *clone() const { return new crit_in_place_data_saved(*this); };
00346     };
00347 
00348 
00350 
00351     class crit_in_place_data_dirty : public criterium
00352     {
00353     public:
00354         bool evaluate(const nomme &first, const nomme &second) const;
00355         criterium *clone() const { return new crit_in_place_data_dirty(*this); };
00356     };
00357 
00359 
00360     class crit_in_place_data_sparse : public criterium
00361     {
00362     public:
00363         bool evaluate(const nomme &first, const nomme &second) const;
00364         criterium *clone() const { return new crit_in_place_data_sparse(*this); };
00365     };
00366 
00367 
00370 
00371     class crit_in_place_EA_present : public criterium
00372     {
00373     public:
00374         bool evaluate(const nomme &first, const nomme &second) const
00375         {
00376             const inode *tmp = dynamic_cast<const inode *>(&first);
00377             return tmp != NULL && tmp->ea_get_saved_status() != inode::ea_none && tmp->ea_get_saved_status() != inode::ea_removed;
00378         };
00379         criterium *clone() const { return new crit_in_place_EA_present(*this); };
00380     };
00381 
00382 
00384 
00389 
00390     class crit_in_place_EA_more_recent : public criterium
00391     {
00392     public:
00393         crit_in_place_EA_more_recent(const infinint & hourshift = 0) : x_hourshift(hourshift) {};
00394 
00395         bool evaluate(const nomme &first, const nomme &second) const;
00396         criterium *clone() const { return new crit_in_place_EA_more_recent(*this); };
00397 
00398     private:
00399         infinint x_hourshift;
00400     };
00401 
00402 
00404 
00407 
00408     class crit_in_place_EA_more_recent_or_equal_to : public criterium
00409     {
00410     public:
00411         crit_in_place_EA_more_recent_or_equal_to(const infinint & date, const infinint & hourshift = 0) : x_hourshift(hourshift), x_date(date) {};
00412 
00413         bool evaluate(const nomme &first, const nomme &second) const;
00414         criterium *clone() const { return new crit_in_place_EA_more_recent_or_equal_to(*this); };
00415 
00416     private:
00417         infinint x_hourshift;
00418         infinint x_date;
00419     };
00420 
00421 
00423 
00425 
00426     class crit_in_place_more_EA : public criterium
00427     {
00428     public:
00429         bool evaluate(const nomme &first, const nomme &second) const;
00430         criterium *clone() const { return new crit_in_place_more_EA(*this); };
00431     };
00432 
00433 
00434 
00436 
00438 
00439     class crit_in_place_EA_bigger : public crit_in_place_more_EA
00440     {
00441     public:
00442         bool evaluate(const nomme &first, const nomme &second) const;
00443         criterium *clone() const { return new crit_in_place_EA_bigger(*this); };
00444     };
00445 
00446 
00448 
00450 
00451     class crit_in_place_EA_saved : public criterium
00452     {
00453     public:
00454         bool evaluate(const nomme &first, const nomme &second) const;
00455         criterium *clone() const { return new crit_in_place_EA_saved(*this); };
00456     };
00457 
00458 
00460 
00463 
00464     class crit_same_type : public criterium
00465     {
00466     public:
00467         bool evaluate(const nomme &first, const nomme &second) const;
00468         criterium *clone() const { return new crit_same_type(*this); };
00469     };
00470 
00471 
00473 
00474     class crit_not : public criterium
00475     {
00476     public:
00477         crit_not(const criterium & crit) { x_crit = crit.clone(); if(x_crit == NULL) throw Ememory("crit_not::crit_not"); };
00478         crit_not(const crit_not & ref) : criterium (ref) { copy_from(ref); };
00479         const crit_not & operator = (const crit_not & ref) { destroy(); copy_from(ref); return *this; };
00480         ~crit_not() { destroy(); };
00481 
00482         bool evaluate(const nomme & first, const nomme & second) const { return ! x_crit->evaluate(first, second); };
00483         criterium *clone() const { return new crit_not(*this); };
00484 
00485     protected:
00486         const criterium *x_crit;
00487 
00488     private:
00489         void copy_from(const crit_not & ref);
00490         void destroy() { if(x_crit != NULL) { delete x_crit; x_crit = NULL; } };
00491     };
00492 
00494 
00495     class crit_and : public criterium
00496     {
00497     public:
00498         crit_and() { clear(); };
00499         crit_and(const crit_and & ref) : criterium(ref) { copy_from(ref); };
00500         const crit_and & operator = (const crit_and & ref) { detruit(); copy_from(ref); return *this; };
00501         ~crit_and() { detruit(); };
00502 
00503         void add_crit(const criterium & ref);
00504         void clear() { detruit(); };
00505 
00507         void gobe(crit_and & to_be_voided);
00508 
00509         virtual bool evaluate(const nomme & first, const nomme & second) const;
00510         criterium *clone() const { return new crit_and(*this); };
00511 
00512     protected:
00513         std::vector<criterium *> operand;
00514 
00515     private:
00516         void copy_from(const crit_and & ref);
00517         void detruit();
00518     };
00519 
00520     class crit_or : public crit_and
00521     {
00522     public:
00523         crit_or() { clear(); };
00524 
00525         bool evaluate(const nomme & first, const nomme & second) const;
00526         criterium *clone() const { return new crit_or(*this); };
00527 
00528     };
00529 
00530     class crit_invert : public crit_not
00531     {
00532     public:
00533         crit_invert(const criterium & crit) : crit_not(crit) {};
00534 
00535         bool evaluate(const nomme & first, const nomme & second) const { return x_crit->evaluate(second, first); };
00536         criterium *clone() const { return new crit_invert(*this); };
00537     };
00538 
00539 
00541 
00547     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);
00548 
00550 
00556     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);
00557 
00559 
00564     extern void crit_show_entry_info(user_interaction & dialog, const std::string & full_name, const entree *already_here, const entree *dolly);
00565 
00567 
00568 } // end of namespace
00569 
00570 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines