apt  2.2.4
About: Apt (Advanced Package Tool) is a management system for software packages (Debian/Ubuntu). Release series 2.2.
  Fossies Dox: apt-2.2.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

cachefilter.h
Go to the documentation of this file.
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/string_view.h>
11 
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
16 #include <regex.h>
17 
18 class pkgCacheFile;
19  /*}}}*/
20 namespace APT {
21 namespace CacheFilter {
22 
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 
32 public:
33  virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE = 0;
34  virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE { return (*this)(Ver.ParentPkg()); }
35  virtual bool operator() (pkgCache::GrpIterator const &/*Grp*/) APT_OVERRIDE { return false; }
36  virtual ~~PackageMatcher();
37 };
38 
39 // Generica like True, False, NOT, AND, OR /*{{{*/
40 class APT_PUBLIC TrueMatcher : public Matcher {
41 public:
42  virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
43  virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
44  virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
45 };
46 
48 public:
49  virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
50  virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
51  virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
52 };
53 
54 class APT_PUBLIC NOTMatcher : public Matcher {
55  Matcher * const matcher;
56 public:
57  explicit NOTMatcher(Matcher * const matcher);
58  virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
59  virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
60  virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
61  virtual ~~NOTMatcher();
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  virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
76  virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
77  virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
78  virtual ~~ANDMatcher();
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  virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
92  virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
93  virtual bool operator() (pkgCache::VerIterator const &Ver) APT_OVERRIDE;
94  virtual ~~ORMatcher();
95 };
96  /*}}}*/
98  regex_t* pattern;
99 public:
100  explicit PackageNameMatchesRegEx(std::string const &Pattern);
101  virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
102  virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
103  virtual ~~PackageNameMatchesRegEx();
104 };
105  /*}}}*/
107  const std::string Pattern;
108 public:
109  explicit PackageNameMatchesFnmatch(std::string const &Pattern);
110  virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
111  virtual bool operator() (pkgCache::GrpIterator const &Grp) APT_OVERRIDE;
113 };
114  /*}}}*/
116 /** \class PackageArchitectureMatchesSpecification
117  \brief matching against architecture specification strings
118 
119  The strings are of the format <libc>-<kernel>-<cpu> where either component,
120  or the whole string, can be the wildcard "any" as defined in
121  debian-policy §11.1 "Architecture specification strings".
122 
123  Examples: i386, mipsel, musl-linux-amd64, linux-any, any-amd64, any */
124  std::string literal;
125  std::string complete;
126  bool isPattern;
127 public:
128  /** \brief matching against architecture specification strings
129  *
130  * @param pattern is the architecture specification string
131  * @param isPattern defines if the given \b pattern is a
132  * architecture specification pattern to match others against
133  * or if it is the fixed string and matched against patterns
134  */
135  PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern = true);
136  bool operator() (char const * const &arch);
137  virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
139 };
140  /*}}}*/
143 public:
144  explicit PackageIsNewInstall(pkgCacheFile * const Cache);
145  virtual bool operator() (pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
146  virtual ~~PackageIsNewInstall();
147 };
148  /*}}}*/
149 
150 /// \brief Parse a pattern, return nullptr or pattern
151 APT_PUBLIC std::unique_ptr<APT::CacheFilter::Matcher> ParsePattern(APT::StringView pattern, pkgCacheFile *file);
152 }
153 }
154 #endif
std::vector< Matcher * > matchers
Definition: cachefilter.h:65
std::vector< Matcher * > matchers
Definition: cachefilter.h:81
Simple subset of std::string_view from C++17.
Definition: string_view.h:27
#define APT_OVERRIDE
Definition: macros.h:111
#define APT_PUBLIC
Definition: macros.h:77
APT_PUBLIC std::unique_ptr< APT::CacheFilter::Matcher > ParsePattern(APT::StringView pattern, pkgCacheFile *file)
Parse a pattern, return nullptr or pattern.
pkgCache - Structure definitions for the cache file