1 // -*- mode: cpp; mode: fold -*-
3 /** \file cachefilter.h
4 Collection of functor classes */
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>
20 namespace CacheFilter
{
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;
30 class PackageMatcher
: public Matcher
{
32 virtual bool operator() (pkgCache::PkgIterator
const &Pkg
) = 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();
38 // Generica like True, False, NOT, AND, OR /*{{{*/
39 class TrueMatcher
: public Matcher
{
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
;
46 class FalseMatcher
: public Matcher
{
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
;
53 class NOTMatcher
: public Matcher
{
54 Matcher
* const matcher
;
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();
63 class ANDMatcher
: public Matcher
{
64 std::vector
<Matcher
*> matchers
;
66 // 5 ought to be enough for everybody… c++11 variadic templates would be nice
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();
79 class ORMatcher
: public Matcher
{
80 std::vector
<Matcher
*> matchers
;
82 // 5 ought to be enough for everybody… c++11 variadic templates would be nice
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
;
96 class PackageNameMatchesRegEx
: public PackageMatcher
{ /*{{{*/
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();
105 class PackageNameMatchesFnmatch
: public PackageMatcher
{ /*{{{*/
106 const std::string Pattern
;
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() {};
114 class PackageArchitectureMatchesSpecification
: public PackageMatcher
{ /*{{{*/
115 /** \class PackageArchitectureMatchesSpecification
116 \brief matching against architecture specification strings
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".
122 Examples: i386, mipsel, linux-any, any-amd64, any */
124 std::string complete
;
127 /** \brief matching against architecture specification strings
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
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();
140 class PackageIsNewInstall
: public PackageMatcher
{ /*{{{*/
141 pkgCacheFile
* const Cache
;
143 explicit PackageIsNewInstall(pkgCacheFile
* const Cache
);
144 virtual bool operator() (pkgCache::PkgIterator
const &Pkg
) APT_OVERRIDE
;
145 virtual ~PackageIsNewInstall();