Disk ARchive  2.4.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
.pc/delete2/mask.hpp
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$
00022 //
00023 /*********************************************************************/
00024 
00025 #ifndef MASK_HPP
00026 #define MASK_HPP
00027 
00028 #pragma interface
00029 
00030 #include <string.h>
00031 #include <string>
00032 #include <vector>
00033 #include <regex.h>
00034 #include "path.hpp"
00035 
00036 using namespace std;
00037 
00038 class mask
00039 {
00040 public :
00041     virtual ~mask() {};
00042 
00043     virtual bool is_covered(const string &expression) const = 0;
00044     virtual mask *clone() const = 0;
00045 };
00046 
00047 class bool_mask : public mask
00048 {
00049 public :
00050     bool_mask(bool always) { val = always; };
00051 
00052     bool is_covered(const string &exp) const { return val; };
00053     mask *clone() const { return new bool_mask(val); };
00054 
00055 private :
00056     bool val;
00057 };
00058 
00059 class simple_mask : public mask
00060 {
00061 public :
00062     simple_mask(const string & wilde_card_expression);
00063     simple_mask(const simple_mask & m) { copy_from(m); };
00064     simple_mask & operator = (const simple_mask & m) { detruit(); copy_from(m); return *this; };
00065     virtual ~simple_mask() { detruit(); };
00066 
00067     bool is_covered(const string &expression) const;
00068     mask *clone() const { return new simple_mask(*this); };
00069 
00070 private :
00071     char *the_mask;
00072 
00073     void copy_from(const simple_mask & m);
00074     void detruit() { if(the_mask != NULL) delete the_mask; the_mask = NULL; };
00075 };
00076 
00077 
00078 class regular_mask : public mask
00079 {
00080 public :
00081     regular_mask(const string & wild_card_expression);
00082     virtual ~regular_mask() { regfree(&preg); };
00083 
00084     bool is_covered(const string & expression) const;
00085     mask *clone() const { return new regular_mask(*this); };
00086 
00087 private :
00088     regex_t preg;
00089 };
00090 
00091 class not_mask : public mask
00092 {
00093 public :
00094     not_mask(const mask &m) { copy_from(m); };
00095     not_mask(const not_mask & m) { copy_from(m); };
00096     not_mask & operator = (const not_mask & m) { detruit(); copy_from(m); return *this; };
00097     ~not_mask() { detruit(); };
00098 
00099     bool is_covered(const string &expression) const { return !ref->is_covered(expression); };
00100     mask *clone() const { return new not_mask(*this); };
00101 
00102 private :
00103     mask *ref;
00104 
00105     void copy_from(const not_mask &m);
00106     void copy_from(const mask &m);
00107     void detruit();
00108 };
00109     
00110 class et_mask : public mask
00111 {
00112 public :
00113     et_mask() {};
00114     et_mask(const et_mask &m) { copy_from(m); };
00115     et_mask & operator = (const et_mask &m) { detruit(); copy_from(m); return *this; };
00116     ~et_mask() { detruit(); };
00117 
00118     void add_mask(const mask & toadd);
00119 
00120     bool is_covered(const string & expression) const;
00121     mask *clone() const { return new et_mask(*this); };
00122     U_I size() const { return lst.size(); };
00123 protected :
00124     vector<mask *> lst;
00125     
00126 private :
00127     void copy_from(const et_mask & m);
00128     void detruit();
00129 };
00130 
00131 class ou_mask : public et_mask
00132 {
00133 public :
00134     bool is_covered(const string & expression) const;
00135     mask *clone() const { return new ou_mask(*this); };
00136 };
00137 
00138 class simple_path_mask : public mask
00139 {
00140 public :
00141     simple_path_mask(const string &p) : chemin(p) {};
00142 
00143     bool is_covered(const string &ch) const;
00144     mask *clone() const { return new simple_path_mask(*this); };
00145     
00146 private :
00147     path chemin;
00148 };
00149 
00150 class same_path_mask : public mask
00151 {
00152 public : 
00153     same_path_mask(const string &p) { chemin = p; };
00154     
00155     bool is_covered(const string &ch) const { return ch == chemin; };
00156     mask *clone() const { return new same_path_mask(*this); };
00157 
00158 private :
00159     string chemin;
00160 };
00161 
00162 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines