]>
Commit | Line | Data |
---|---|---|
9ba5aa3b DK |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
3 | /** \file cachefilter.h | |
4 | Collection of functor classes */ | |
5 | /*}}}*/ | |
6 | #ifndef APT_CACHEFILTER_H | |
7 | #define APT_CACHEFILTER_H | |
8 | // Include Files /*{{{*/ | |
9 | #include <apt-pkg/pkgcache.h> | |
453b82a3 | 10 | #include <apt-pkg/cacheiterators.h> |
9ba5aa3b DK |
11 | |
12 | #include <string> | |
3721cb01 | 13 | #include <vector> |
9ba5aa3b DK |
14 | |
15 | #include <regex.h> | |
3721cb01 DK |
16 | |
17 | class pkgCacheFile; | |
9ba5aa3b DK |
18 | /*}}}*/ |
19 | namespace APT { | |
20 | namespace CacheFilter { | |
b9179170 | 21 | |
3721cb01 DK |
22 | class Matcher { |
23 | public: | |
24 | virtual bool operator() (pkgCache::PkgIterator const &/*Pkg*/) = 0; | |
25 | virtual bool operator() (pkgCache::GrpIterator const &/*Grp*/) = 0; | |
26 | virtual bool operator() (pkgCache::VerIterator const &/*Ver*/) = 0; | |
27 | virtual ~Matcher(); | |
b9179170 MV |
28 | }; |
29 | ||
3721cb01 DK |
30 | class PackageMatcher : public Matcher { |
31 | public: | |
32 | virtual bool operator() (pkgCache::PkgIterator const &Pkg) = 0; | |
33 | virtual bool operator() (pkgCache::VerIterator const &Ver) { return (*this)(Ver.ParentPkg()); } | |
34 | virtual bool operator() (pkgCache::GrpIterator const &/*Grp*/) { return false; } | |
35 | virtual ~PackageMatcher(); | |
36 | }; | |
37 | ||
38 | // Generica like True, False, NOT, AND, OR /*{{{*/ | |
39 | class TrueMatcher : public Matcher { | |
40 | public: | |
41 | virtual bool operator() (pkgCache::PkgIterator const &Pkg); | |
42 | virtual bool operator() (pkgCache::GrpIterator const &Grp); | |
43 | virtual bool operator() (pkgCache::VerIterator const &Ver); | |
44 | }; | |
45 | ||
46 | class FalseMatcher : public Matcher { | |
47 | public: | |
48 | virtual bool operator() (pkgCache::PkgIterator const &Pkg); | |
49 | virtual bool operator() (pkgCache::GrpIterator const &Grp); | |
50 | virtual bool operator() (pkgCache::VerIterator const &Ver); | |
51 | }; | |
52 | ||
53 | class NOTMatcher : public Matcher { | |
54 | Matcher * const matcher; | |
55 | public: | |
e8afd168 | 56 | explicit NOTMatcher(Matcher * const matcher); |
3721cb01 DK |
57 | virtual bool operator() (pkgCache::PkgIterator const &Pkg); |
58 | virtual bool operator() (pkgCache::GrpIterator const &Grp); | |
59 | virtual bool operator() (pkgCache::VerIterator const &Ver); | |
60 | virtual ~NOTMatcher(); | |
61 | }; | |
62 | ||
63 | class ANDMatcher : public Matcher { | |
64 | std::vector<Matcher *> matchers; | |
65 | public: | |
66 | // 5 ought to be enough for everybody… c++11 variadic templates would be nice | |
67 | ANDMatcher(); | |
e8afd168 | 68 | explicit ANDMatcher(Matcher * const matcher1); |
3721cb01 DK |
69 | ANDMatcher(Matcher * const matcher1, Matcher * const matcher2); |
70 | ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3); | |
71 | ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4); | |
72 | ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4, Matcher * const matcher5); | |
73 | ANDMatcher& AND(Matcher * const matcher); | |
74 | virtual bool operator() (pkgCache::PkgIterator const &Pkg); | |
75 | virtual bool operator() (pkgCache::GrpIterator const &Grp); | |
76 | virtual bool operator() (pkgCache::VerIterator const &Ver); | |
77 | virtual ~ANDMatcher(); | |
78 | }; | |
79 | class ORMatcher : public Matcher { | |
80 | std::vector<Matcher *> matchers; | |
81 | public: | |
82 | // 5 ought to be enough for everybody… c++11 variadic templates would be nice | |
83 | ORMatcher(); | |
e8afd168 | 84 | explicit ORMatcher(Matcher * const matcher1); |
3721cb01 DK |
85 | ORMatcher(Matcher * const matcher1, Matcher * const matcher2); |
86 | ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3); | |
87 | ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4); | |
88 | ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4, Matcher * const matcher5); | |
89 | ORMatcher& OR(Matcher * const matcher); | |
90 | virtual bool operator() (pkgCache::PkgIterator const &Pkg); | |
91 | virtual bool operator() (pkgCache::GrpIterator const &Grp); | |
92 | virtual bool operator() (pkgCache::VerIterator const &Ver); | |
93 | virtual ~ORMatcher(); | |
94 | }; | |
95 | /*}}}*/ | |
96 | class PackageNameMatchesRegEx : public PackageMatcher { /*{{{*/ | |
9ba5aa3b DK |
97 | regex_t* pattern; |
98 | public: | |
e8afd168 | 99 | explicit PackageNameMatchesRegEx(std::string const &Pattern); |
b9179170 MV |
100 | virtual bool operator() (pkgCache::PkgIterator const &Pkg); |
101 | virtual bool operator() (pkgCache::GrpIterator const &Grp); | |
314a3f88 | 102 | virtual ~PackageNameMatchesRegEx(); |
9ba5aa3b DK |
103 | }; |
104 | /*}}}*/ | |
3721cb01 DK |
105 | class PackageNameMatchesFnmatch : public PackageMatcher { /*{{{*/ |
106 | const std::string Pattern; | |
b9179170 | 107 | public: |
e8afd168 | 108 | explicit PackageNameMatchesFnmatch(std::string const &Pattern); |
3721cb01 | 109 | virtual bool operator() (pkgCache::PkgIterator const &Pkg); |
b9179170 | 110 | virtual bool operator() (pkgCache::GrpIterator const &Grp); |
314a3f88 | 111 | virtual ~PackageNameMatchesFnmatch() {}; |
b9179170 MV |
112 | }; |
113 | /*}}}*/ | |
3721cb01 | 114 | class PackageArchitectureMatchesSpecification : public PackageMatcher { /*{{{*/ |
424ff669 DK |
115 | /** \class PackageArchitectureMatchesSpecification |
116 | \brief matching against architecture specification strings | |
117 | ||
118 | The strings are of the format <kernel>-<cpu> where either component, | |
119 | or the whole string, can be the wildcard "any" as defined in | |
120 | debian-policy §11.1 "Architecture specification strings". | |
121 | ||
122 | Examples: i386, mipsel, linux-any, any-amd64, any */ | |
424ff669 DK |
123 | std::string literal; |
124 | std::string complete; | |
125 | bool isPattern; | |
424ff669 DK |
126 | public: |
127 | /** \brief matching against architecture specification strings | |
128 | * | |
129 | * @param pattern is the architecture specification string | |
130 | * @param isPattern defines if the given \b pattern is a | |
131 | * architecture specification pattern to match others against | |
132 | * or if it is the fixed string and matched against patterns | |
133 | */ | |
134 | PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern = true); | |
135 | bool operator() (char const * const &arch); | |
b9179170 | 136 | virtual bool operator() (pkgCache::PkgIterator const &Pkg); |
314a3f88 | 137 | virtual ~PackageArchitectureMatchesSpecification(); |
424ff669 DK |
138 | }; |
139 | /*}}}*/ | |
3721cb01 DK |
140 | class PackageIsNewInstall : public PackageMatcher { /*{{{*/ |
141 | pkgCacheFile * const Cache; | |
142 | public: | |
e8afd168 | 143 | explicit PackageIsNewInstall(pkgCacheFile * const Cache); |
3721cb01 DK |
144 | virtual bool operator() (pkgCache::PkgIterator const &Pkg); |
145 | virtual ~PackageIsNewInstall(); | |
146 | }; | |
147 | /*}}}*/ | |
148 | ||
9ba5aa3b DK |
149 | } |
150 | } | |
151 | #endif |