mask.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 : dar.linux@free.fr
00020 /*********************************************************************/
00021 // $Id: mask.hpp,v 1.17.2.1 2007/07/22 16:35:00 edrusb Rel $
00022 //
00023 /*********************************************************************/
00024 
00030 
00031 #ifndef MASK_HPP
00032 #define MASK_HPP
00033 
00034 #include "../my_config.h"
00035 
00036 extern "C"
00037 {
00038 #if HAVE_UNISTD_H
00039 #include <unistd.h>
00040 #endif
00041 
00042 #if HAVE_REGEX_H
00043 #include <regex.h>
00044 #endif
00045 } // end extern "C"
00046 
00047 #include <string>
00048 #include <vector>
00049 #include "path.hpp"
00050 
00051 namespace libdar
00052 {
00053 
00056 
00058 
00061     class mask
00062     {
00063     public :
00064         virtual ~mask() {};
00065 
00067 
00071         virtual bool is_covered(const std::string &expression) const = 0;
00072 
00075         virtual mask *clone() const = 0;
00076     };
00077 
00078 
00080 
00082     class bool_mask : public mask
00083     {
00084     public :
00086 
00090         bool_mask(bool always) { val = always; };
00091 
00093         bool is_covered(const std::string &) const { return val; };
00095         mask *clone() const { return new bool_mask(val); };
00096 
00097     private :
00098         bool val;
00099     };
00100 
00101 
00103 
00104     class simple_mask : public mask
00105     {
00106     public :
00107 
00109 
00112         simple_mask(const std::string & wilde_card_expression, bool case_sensit);
00114         simple_mask(const simple_mask & m) : mask(m) { copy_from(m); };
00116         simple_mask & operator = (const simple_mask & m);
00117 
00119         bool is_covered(const std::string &expression) const;
00121         mask *clone() const { return new simple_mask(*this); };
00122 
00123     private :
00124         std::string the_mask;
00125         bool case_s;
00126 
00127         void copy_from(const simple_mask & m);
00128     };
00129 
00130 
00132 
00133     class regular_mask : public mask
00134     {
00135     public :
00136 
00138 
00141         regular_mask(const std::string & wilde_card_expression,
00142                      bool x_case_sensit);
00144         regular_mask(const regular_mask & ref);
00146         regular_mask & operator= (const regular_mask & ref);
00147 
00149         virtual ~regular_mask() { regfree(&preg); };
00150 
00152         bool is_covered(const std::string & expression) const;
00154         mask *clone() const { return new regular_mask(*this); };
00155 
00156     private :
00157         regex_t preg;
00158         std::string mask_exp; //< used only by the copy constructor
00159         bool case_sensit;     //< used only by the copy constructor
00160 
00161         void set_preg(const std::string & wilde_card_expression,
00162                       bool x_case_sensit);
00163     };
00164 
00165 
00167 
00170     class not_mask : public mask
00171     {
00172     public :
00174 
00178         not_mask(const mask &m) { copy_from(m); };
00180         not_mask(const not_mask & m) : mask(m) { copy_from(m); };
00182         not_mask & operator = (const not_mask & m);
00184         ~not_mask() { detruit(); };
00185 
00187         bool is_covered(const std::string &expression) const { return !ref->is_covered(expression); };
00189         mask *clone() const { return new not_mask(*this); };
00190 
00191     private :
00192         mask *ref;
00193 
00194         void copy_from(const not_mask &m);
00195         void copy_from(const mask &m);
00196         void detruit();
00197     };
00198 
00199 
00201 
00202     class et_mask : public mask
00203     {
00204     public :
00205 
00207 
00211         et_mask() {};
00213         et_mask(const et_mask &m) : mask(m) { copy_from(m); };
00215         et_mask & operator = (const et_mask &m);
00217         ~et_mask() { detruit(); };
00218 
00219 
00221 
00225         void add_mask(const mask & toadd);
00226 
00228         bool is_covered(const std::string & expression) const;
00230         mask *clone() const { return new et_mask(*this); };
00231 
00233 
00236         U_I size() const { return lst.size(); };
00237 
00239 
00243         void clear() { detruit(); };
00244 
00245     protected :
00246         std::vector<mask *> lst;
00247 
00248     private :
00249         void copy_from(const et_mask & m);
00250         void detruit();
00251     };
00252 
00253 
00255 
00260     class ou_mask : public et_mask
00261     {
00262     public :
00264         bool is_covered(const std::string & expression) const;
00266         mask *clone() const { return new ou_mask(*this); };
00267     };
00268 
00269 
00271 
00272     class simple_path_mask : public mask
00273     {
00274     public :
00276 
00280         simple_path_mask(const std::string &p, bool case_sensit) : chemin(p) { case_s = case_sensit; };
00281 
00283         bool is_covered(const std::string &ch) const;
00285         mask *clone() const { return new simple_path_mask(*this); };
00286 
00287     private :
00288         path chemin;
00289         bool case_s;
00290     };
00291 
00292 
00294 
00295     class same_path_mask : public mask
00296     {
00297     public :
00299 
00302         same_path_mask(const std::string &p, bool case_sensit) { chemin = p; case_s = case_sensit; };
00303 
00305         bool is_covered(const std::string &ch) const;
00307         mask *clone() const { return new same_path_mask(*this); };
00308 
00309     private :
00310         std::string chemin;
00311         bool case_s;
00312     };
00313 
00314 
00316 
00317     class exclude_dir_mask : public mask
00318     {
00319     public:
00321 
00324         exclude_dir_mask(const std::string &p, bool case_sensit) { chemin = p; case_s = case_sensit;};
00325 
00327         bool is_covered(const std::string &ch) const { return path(ch).is_subdir_of(chemin, case_s); }
00329         mask *clone() const { return new exclude_dir_mask(*this); };
00330 
00331     private:
00332         std::string chemin;
00333         bool case_s;
00334     };
00335 
00337 
00338 } // end of namespace
00339 
00340 #endif
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines
Generated on Mon Apr 19 00:32:06 2010 for Disk ARchive by  doxygen 1.6.3