apt: apt-pkg/cachefilter.h Source File

apt 2.7.10 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#include <apt-pkg/string_view.h>
11
12#include <memory>
13#include <string>
14#include <vector>
15
16#include <regex.h>
17
18class pkgCacheFile;
19 /*}}}*/
20namespace APT {
21namespace CacheFilter {
22
23 class APT_PUBLIC Matcher {
24public:
25 virtual bool operator() (pkgCache::PkgIterator const &/*Pkg*/) = 0;
26 virtual bool operator() (pkgCache::GrpIterator const &/*Grp*/) = 0;
27 virtual bool operator() (pkgCache::VerIterator const &/*Ver*/) = 0;
28 virtual ~Matcher();
29};
30
31 class APT_PUBLIC PackageMatcher : public Matcher {
32public:
33 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE = 0;
34 bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE { return (*this)(Ver.ParentPkg()); }
35 bool operator() (pkgCache::GrpIterator const &/*Grp*/) APT_OVERRIDE { return false; }
36 ~PackageMatcher() APT_OVERRIDE;
37};
38
39// Generica like True, False, NOT, AND, OR /*{{{*/
40 class APT_PUBLIC TrueMatcher : public Matcher {
41public:
42 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
43 bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
44 bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
45};
46
47 class APT_PUBLIC FalseMatcher : public Matcher {
48public:
49 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
50 bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
51 bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
52};
53
54 class APT_PUBLIC NOTMatcher : public Matcher {
55 Matcher * const matcher;
56public:
57 explicit NOTMatcher(Matcher * const matcher);
58 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
59 bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
60 bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
61 ~NOTMatcher() APT_OVERRIDE;
62};
63
64 class APT_PUBLIC ANDMatcher : public Matcher {
65 std::vector<Matcher *> matchers;
66public:
67 // 5 ought to be enough for everybody… c++11 variadic templates would be nice
68 ANDMatcher();
69 explicit ANDMatcher(Matcher * const matcher1);
70 ANDMatcher(Matcher * const matcher1, Matcher * const matcher2);
71 ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3);
72 ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4);
73 ANDMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4, Matcher * const matcher5);
74 ANDMatcher& AND(Matcher * const matcher);
75 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
76 bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
77 bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
78 ~ANDMatcher() APT_OVERRIDE;
79};
80 class APT_PUBLIC ORMatcher : public Matcher {
81 std::vector<Matcher *> matchers;
82public:
83 // 5 ought to be enough for everybody… c++11 variadic templates would be nice
84 ORMatcher();
85 explicit ORMatcher(Matcher * const matcher1);
86 ORMatcher(Matcher * const matcher1, Matcher * const matcher2);
87 ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3);
88 ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4);
89 ORMatcher(Matcher * const matcher1, Matcher * const matcher2, Matcher * const matcher3, Matcher * const matcher4, Matcher * const matcher5);
90 ORMatcher& OR(Matcher * const matcher);
91 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
92 bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
93 bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
94 ~ORMatcher() APT_OVERRIDE;
95};
96 /*}}}*/
97 class APT_PUBLIC PackageNameMatchesRegEx : public PackageMatcher { /*{{{*/
98 regex_t* pattern;
99public:
100 explicit PackageNameMatchesRegEx(std::string const &Pattern);
101 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
102 bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
103 ~PackageNameMatchesRegEx() APT_OVERRIDE;
104};
105 /*}}}*/
106 class APT_PUBLIC PackageNameMatchesFnmatch : public PackageMatcher { /*{{{*/
107 const std::string Pattern;
108public:
109 explicit PackageNameMatchesFnmatch(std::string const &Pattern);
110 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
111 bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
112 ~PackageNameMatchesFnmatch() APT_OVERRIDE = default;
113};
114 /*}}}*/
115 class APT_PUBLIC PackageArchitectureMatchesSpecification : public PackageMatcher { /*{{{*/
124 std::string literal;
125 std::string complete;
126 bool isPattern;
127public:
135 PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern = true);
136 bool operator() (char const * const &arch);
137 using PackageMatcher::operator();
138 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
139 ~PackageArchitectureMatchesSpecification() APT_OVERRIDE;
140};
141 /*}}}*/
142 class APT_PUBLIC PackageIsNewInstall : public PackageMatcher { /*{{{*/
143 pkgCacheFile * const Cache;
144public:
145 explicit PackageIsNewInstall(pkgCacheFile * const Cache);
146 using PackageMatcher::operator();
147 bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
148 ~PackageIsNewInstall() APT_OVERRIDE;
149};
150 /*}}}*/
151
153APT_PUBLIC std::unique_ptr<APT::CacheFilter::Matcher> ParsePattern(APT::StringView pattern, pkgCacheFile *file);
154}
155}
156#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.
Definition cachefilter-patterns.cc:586
APT::CacheFilter::ANDMatcher
Definition cachefilter.h:64
APT::CacheFilter::FalseMatcher
Definition cachefilter.h:47
APT::CacheFilter::Matcher
Definition cachefilter.h:23
APT::CacheFilter::NOTMatcher
Definition cachefilter.h:54
APT::CacheFilter::ORMatcher
Definition cachefilter.h:80
APT::CacheFilter::PackageArchitectureMatchesSpecification
Definition cachefilter.h:115
APT::CacheFilter::PackageIsNewInstall
Definition cachefilter.h:142
APT::CacheFilter::PackageMatcher
Definition cachefilter.h:31
APT::CacheFilter::PackageNameMatchesFnmatch
Definition cachefilter.h:106
APT::CacheFilter::PackageNameMatchesRegEx
Definition cachefilter.h:97
APT::CacheFilter::TrueMatcher
Definition cachefilter.h:40
APT::StringView
Simple subset of std::string_view from C++17.
Definition string_view.h:27
pkgCacheFile
Definition cachefile.h:33
pkgcache.h
pkgCache - Structure definitions for the cache file