apt 3.2.0 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 <string_view>
14#include <vector>
15
16#include <regex.h>
17
18 class pkgCacheFile;
19 /*}}}*/
20 namespace APT {
21 namespace CacheFilter {
22
23 class APT_PUBLIC Matcher {
24 public:
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 {
32 public:
33 bool operator() (pkgCache::PkgIterator const &Pkg) override = 0;
34 bool operator() (pkgCache::VerIterator const &Ver) override { return (*this)(Ver.ParentPkg()); }
35 bool operator() (pkgCache::GrpIterator const &/*Grp*/) override { return false; }
36 ~PackageMatcher() override;
37};
38
39// Generica like True, False, NOT, AND, OR /*{{{*/
40 class APT_PUBLIC TrueMatcher : public Matcher {
41 public:
42 bool operator() (pkgCache::PkgIterator const &Pkg) override;
43 bool operator() (pkgCache::GrpIterator const &Grp) override;
44 bool operator() (pkgCache::VerIterator const &Ver) override;
45};
46
47 class APT_PUBLIC FalseMatcher : public Matcher {
48 public:
49 bool operator() (pkgCache::PkgIterator const &Pkg) override;
50 bool operator() (pkgCache::GrpIterator const &Grp) override;
51 bool operator() (pkgCache::VerIterator const &Ver) override;
52};
53
54 class APT_PUBLIC NOTMatcher : public Matcher {
55 Matcher * const matcher;
56 public:
57 explicit NOTMatcher(Matcher * const matcher);
58 bool operator() (pkgCache::PkgIterator const &Pkg) override;
59 bool operator() (pkgCache::GrpIterator const &Grp) override;
60 bool operator() (pkgCache::VerIterator const &Ver) override;
61 ~NOTMatcher() override;
62};
63
64 class APT_PUBLIC ANDMatcher : public Matcher {
65 std::vector<Matcher *> matchers;
66 public:
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) override;
76 bool operator() (pkgCache::GrpIterator const &Grp) override;
77 bool operator() (pkgCache::VerIterator const &Ver) override;
78 ~ANDMatcher() override;
79};
80 class APT_PUBLIC ORMatcher : public Matcher {
81 std::vector<Matcher *> matchers;
82 public:
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) override;
92 bool operator() (pkgCache::GrpIterator const &Grp) override;
93 bool operator() (pkgCache::VerIterator const &Ver) override;
94 ~ORMatcher() override;
95};
96 /*}}}*/
97 class APT_PUBLIC PackageNameMatchesRegEx : public PackageMatcher { /*{{{*/
98 regex_t* pattern;
99 public:
100 explicit PackageNameMatchesRegEx(std::string const &Pattern);
101 bool operator() (pkgCache::PkgIterator const &Pkg) override;
102 bool operator() (pkgCache::GrpIterator const &Grp) override;
103 ~PackageNameMatchesRegEx() override;
104};
105 /*}}}*/
106 class APT_PUBLIC PackageNameMatchesFnmatch : public PackageMatcher { /*{{{*/
107 const std::string Pattern;
108 public:
109 explicit PackageNameMatchesFnmatch(std::string const &Pattern);
110 bool operator() (pkgCache::PkgIterator const &Pkg) override;
111 bool operator() (pkgCache::GrpIterator const &Grp) override;
112 ~PackageNameMatchesFnmatch() override = default;
113};
114 /*}}}*/
115 class APT_PUBLIC PackageArchitectureMatchesSpecification : public PackageMatcher { /*{{{*/
124 std::string literal;
125 std::string complete;
126 bool isPattern;
127 public:
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) override;
139 ~PackageArchitectureMatchesSpecification() override;
140};
141 /*}}}*/
142 class APT_PUBLIC PackageIsNewInstall : public PackageMatcher { /*{{{*/
143 pkgCacheFile * const Cache;
144 public:
145 explicit PackageIsNewInstall(pkgCacheFile * const Cache);
146 using PackageMatcher::operator();
147 bool operator() (pkgCache::PkgIterator const &Pkg) override;
148 ~PackageIsNewInstall() override;
149};
150 /*}}}*/
151
153APT_PUBLIC std::unique_ptr<APT::CacheFilter::Matcher> ParsePattern(std::string_view pattern, pkgCacheFile *file);
154}
155}
156#endif
APT::CacheFilter::ParsePattern
APT_PUBLIC std::unique_ptr< APT::CacheFilter::Matcher > ParsePattern(std::string_view pattern, pkgCacheFile *file)
Parse a pattern, return nullptr or pattern.
Definition cachefilter-patterns.cc:591
APT::CacheFilter::FalseMatcher
Definition cachefilter.h:47
APT::CacheFilter::Matcher
Definition cachefilter.h:23
APT::CacheFilter::PackageArchitectureMatchesSpecification::PackageArchitectureMatchesSpecification
PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern=true)
matching against architecture specification strings
Definition cachefilter.cc:142
APT::CacheFilter::PackageMatcher
Definition cachefilter.h:31
APT::CacheFilter::TrueMatcher
Definition cachefilter.h:40
pkgCacheFile
Definition cachefile.h:33
pkgCache::GrpIterator
Definition cacheiterators.h:106
pkgCache::PkgIterator
Definition cacheiterators.h:147
pkgCache::VerIterator
Definition cacheiterators.h:218
pkgcache.h
pkgCache - Structure definitions for the cache file