]> git.saurik.com Git - apt.git/blob - apt-pkg/cachefilter.h
test: Allow db_dump-5 instead of db_dump
[apt.git] / apt-pkg / cachefilter.h
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>
10 #include <apt-pkg/cacheiterators.h>
11
12 #include <string>
13 #include <vector>
14
15 #include <regex.h>
16
17 class pkgCacheFile;
18 /*}}}*/
19 namespace APT {
20 namespace CacheFilter {
21
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();
28 };
29
30 class PackageMatcher : public Matcher {
31 public:
32 virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE = 0;
33 virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE { return (*this)(Ver.ParentPkg()); }
34 virtual bool operator() (pkgCache::GrpIterator const &/*Grp*/) APT_OVERRIDE { 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) APT_OVERRIDE;
42 virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
43 virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
44 };
45
46 class FalseMatcher : public Matcher {
47 public:
48 virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
49 virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
50 virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
51 };
52
53 class NOTMatcher : public Matcher {
54 Matcher * const matcher;
55 public:
56 explicit NOTMatcher(Matcher * const matcher);
57 virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
58 virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
59 virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
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();
68 explicit ANDMatcher(Matcher * const matcher1);
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) APT_OVERRIDE;
75 virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
76 virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
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();
84 explicit ORMatcher(Matcher * const matcher1);
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) APT_OVERRIDE;
91 virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
92 virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
93 virtual ~ORMatcher();
94 };
95 /*}}}*/
96 class PackageNameMatchesRegEx : public PackageMatcher { /*{{{*/
97 regex_t* pattern;
98 public:
99 explicit PackageNameMatchesRegEx(std::string const &Pattern);
100 virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
101 virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
102 virtual ~PackageNameMatchesRegEx();
103 };
104 /*}}}*/
105 class PackageNameMatchesFnmatch : public PackageMatcher { /*{{{*/
106 const std::string Pattern;
107 public:
108 explicit PackageNameMatchesFnmatch(std::string const &Pattern);
109 virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
110 virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
111 virtual ~PackageNameMatchesFnmatch() {};
112 };
113 /*}}}*/
114 class PackageArchitectureMatchesSpecification : public PackageMatcher { /*{{{*/
115 /** \class PackageArchitectureMatchesSpecification
116 \brief matching against architecture specification strings
117
118 The strings are of the format <libc>-<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, musl-linux-amd64, linux-any, any-amd64, any */
123 std::string literal;
124 std::string complete;
125 bool isPattern;
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);
136 virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
137 virtual ~PackageArchitectureMatchesSpecification();
138 };
139 /*}}}*/
140 class PackageIsNewInstall : public PackageMatcher { /*{{{*/
141 pkgCacheFile * const Cache;
142 public:
143 explicit PackageIsNewInstall(pkgCacheFile * const Cache);
144 virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
145 virtual ~PackageIsNewInstall();
146 };
147 /*}}}*/
148
149 }
150 }
151 #endif