apt 2.9.14 commandline package manager

cachefilter.h
Go to the documentation of this file.
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
5 /*}}}*/
6#ifndef APT_CACHEFILTER_H
7#define APT_CACHEFILTER_H
8// Include Files /*{{{*/
9#include <apt-pkg/pkgcache.h>
10
11#include <memory>
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 APT_PUBLIC 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 APT_PUBLIC PackageMatcher : public Matcher {
31 public:
32 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE = 0;
33 bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE { return (*this)(Ver.ParentPkg()); }
34 bool operator() (pkgCache::GrpIterator const &/*Grp*/) APT_OVERRIDE { return false; }
35 ~PackageMatcher() APT_OVERRIDE;
36};
37
38// Generica like True, False, NOT, AND, OR /*{{{*/
39 class APT_PUBLIC TrueMatcher : public Matcher {
40 public:
41 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
42 bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
43 bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
44};
45
46 class APT_PUBLIC FalseMatcher : public Matcher {
47 public:
48 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
49 bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
50 bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
51};
52
53 class APT_PUBLIC NOTMatcher : public Matcher {
54 Matcher * const matcher;
55 public:
56 explicit NOTMatcher(Matcher * const matcher);
57 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
58 bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
59 bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
60 ~NOTMatcher() APT_OVERRIDE;
61};
62
63 class APT_PUBLIC 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 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
75 bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
76 bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
77 ~ANDMatcher() APT_OVERRIDE;
78};
79 class APT_PUBLIC 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 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
91 bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
92 bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
93 ~ORMatcher() APT_OVERRIDE;
94};
95 /*}}}*/
96 class APT_PUBLIC PackageNameMatchesRegEx : public PackageMatcher { /*{{{*/
97 regex_t* pattern;
98 public:
99 explicit PackageNameMatchesRegEx(std::string const &Pattern);
100 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
101 bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
102 ~PackageNameMatchesRegEx() APT_OVERRIDE;
103};
104 /*}}}*/
105 class APT_PUBLIC PackageNameMatchesFnmatch : public PackageMatcher { /*{{{*/
106 const std::string Pattern;
107 public:
108 explicit PackageNameMatchesFnmatch(std::string const &Pattern);
109 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
110 bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
111 ~PackageNameMatchesFnmatch() APT_OVERRIDE = default;
112};
113 /*}}}*/
114 class APT_PUBLIC PackageArchitectureMatchesSpecification : public PackageMatcher { /*{{{*/
123 std::string literal;
124 std::string complete;
125 bool isPattern;
126 public:
134 PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern = true);
135 bool operator() (char const * const &arch);
136 using PackageMatcher::operator();
137 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
138 ~PackageArchitectureMatchesSpecification() APT_OVERRIDE;
139};
140 /*}}}*/
141 class APT_PUBLIC PackageIsNewInstall : public PackageMatcher { /*{{{*/
142 pkgCacheFile * const Cache;
143 public:
144 explicit PackageIsNewInstall(pkgCacheFile * const Cache);
145 using PackageMatcher::operator();
146 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
147 ~PackageIsNewInstall() APT_OVERRIDE;
148};
149 /*}}}*/
150
152APT_PUBLIC std::unique_ptr<APT::CacheFilter::Matcher> ParsePattern(APT::StringView pattern, pkgCacheFile *file);
153}
154}
155#endif
APT::CacheFilter::ParsePattern
APT_PUBLIC std::unique_ptr< APT::CacheFilter::Matcher > ParsePattern(APT::StringView pattern, pkgCacheFile *file)
Parse a pattern, return nullptr or pattern.
APT::CacheFilter::ANDMatcher
Definition cachefilter.h:63
APT::CacheFilter::FalseMatcher
Definition cachefilter.h:46
APT::CacheFilter::Matcher
Definition cachefilter.h:22
APT::CacheFilter::NOTMatcher
Definition cachefilter.h:53
APT::CacheFilter::ORMatcher
Definition cachefilter.h:79
APT::CacheFilter::PackageArchitectureMatchesSpecification
Definition cachefilter.h:114
APT::CacheFilter::PackageIsNewInstall
Definition cachefilter.h:141
APT::CacheFilter::PackageMatcher
Definition cachefilter.h:30
APT::CacheFilter::PackageNameMatchesFnmatch
Definition cachefilter.h:105
APT::CacheFilter::PackageNameMatchesRegEx
Definition cachefilter.h:96
APT::CacheFilter::TrueMatcher
Definition cachefilter.h:39
APT::StringView
Simple subset of std::string_view from C++17.
Definition string_view.h:35
pkgCacheFile
Definition cachefile.h:33
pkgCache::GrpIterator
Definition cacheiterators.h:106
pkgCache::PkgIterator
Definition cacheiterators.h:147
pkgCache::VerIterator
Definition cacheiterators.h:193
pkgcache.h
pkgCache - Structure definitions for the cache file