cachefilter.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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/cacheiterators.h>
  11. #include <string>
  12. #include <regex.h>
  13. /*}}}*/
  14. namespace APT {
  15. namespace CacheFilter {
  16. #define PACKAGE_MATCHER_ABI_COMPAT 1
  17. #ifdef PACKAGE_MATCHER_ABI_COMPAT
  18. // PackageNameMatchesRegEx /*{{{*/
  19. class PackageNameMatchesRegEx {
  20. /** \brief dpointer placeholder (for later in case we need it) */
  21. void *d;
  22. regex_t* pattern;
  23. public:
  24. PackageNameMatchesRegEx(std::string const &Pattern);
  25. bool operator() (pkgCache::PkgIterator const &Pkg);
  26. bool operator() (pkgCache::GrpIterator const &Grp);
  27. ~PackageNameMatchesRegEx();
  28. };
  29. /*}}}*/
  30. // PackageNameMatchesFnmatch /*{{{*/
  31. class PackageNameMatchesFnmatch {
  32. /** \brief dpointer placeholder (for later in case we need it) */
  33. void *d;
  34. const std::string Pattern;
  35. public:
  36. PackageNameMatchesFnmatch(std::string const &Pattern)
  37. : Pattern(Pattern) {};
  38. bool operator() (pkgCache::PkgIterator const &Pkg);
  39. bool operator() (pkgCache::GrpIterator const &Grp);
  40. ~PackageNameMatchesFnmatch() {};
  41. };
  42. /*}}}*/
  43. // PackageArchitectureMatchesSpecification /*{{{*/
  44. /** \class PackageArchitectureMatchesSpecification
  45. \brief matching against architecture specification strings
  46. The strings are of the format \<kernel\>-\<cpu\> where either component,
  47. or the whole string, can be the wildcard "any" as defined in
  48. debian-policy §11.1 "Architecture specification strings".
  49. Examples: i386, mipsel, linux-any, any-amd64, any */
  50. class PackageArchitectureMatchesSpecification {
  51. std::string literal;
  52. std::string complete;
  53. bool isPattern;
  54. /** \brief dpointer placeholder (for later in case we need it) */
  55. void *d;
  56. public:
  57. /** \brief matching against architecture specification strings
  58. *
  59. * @param pattern is the architecture specification string
  60. * @param isPattern defines if the given \b pattern is a
  61. * architecture specification pattern to match others against
  62. * or if it is the fixed string and matched against patterns
  63. */
  64. PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern = true);
  65. bool operator() (char const * const &arch);
  66. bool operator() (pkgCache::PkgIterator const &Pkg);
  67. bool operator() (pkgCache::VerIterator const &Ver);
  68. ~PackageArchitectureMatchesSpecification();
  69. };
  70. /*}}}*/
  71. #else
  72. class PackageMatcher {
  73. public:
  74. virtual bool operator() (pkgCache::PkgIterator const &Pkg) { return false; };
  75. virtual bool operator() (pkgCache::GrpIterator const &Grp) { return false; };
  76. virtual bool operator() (pkgCache::VerIterator const &Ver) { return false; };
  77. virtual ~PackageMatcher() {};
  78. };
  79. // PackageNameMatchesRegEx /*{{{*/
  80. class PackageNameMatchesRegEx : public PackageMatcher {
  81. /** \brief dpointer placeholder (for later in case we need it) */
  82. void *d;
  83. regex_t* pattern;
  84. public:
  85. PackageNameMatchesRegEx(std::string const &Pattern);
  86. virtual bool operator() (pkgCache::PkgIterator const &Pkg);
  87. virtual bool operator() (pkgCache::GrpIterator const &Grp);
  88. virtual ~PackageNameMatchesRegEx();
  89. };
  90. /*}}}*/
  91. // PackageNameMatchesFnmatch /*{{{*/
  92. class PackageNameMatchesFnmatch : public PackageMatcher{
  93. /** \brief dpointer placeholder (for later in case we need it) */
  94. void *d;
  95. const std::string Pattern;
  96. public:
  97. PackageNameMatchesFnmatch(std::string const &Pattern)
  98. : Pattern(Pattern) {};
  99. virtual bool operator() (pkgCache::PkgIterator const &Pkg);
  100. virtual bool operator() (pkgCache::GrpIterator const &Grp);
  101. virtual ~PackageNameMatchesFnmatch() {};
  102. };
  103. /*}}}*/
  104. // PackageArchitectureMatchesSpecification /*{{{*/
  105. /** \class PackageArchitectureMatchesSpecification
  106. \brief matching against architecture specification strings
  107. The strings are of the format <kernel>-<cpu> where either component,
  108. or the whole string, can be the wildcard "any" as defined in
  109. debian-policy §11.1 "Architecture specification strings".
  110. Examples: i386, mipsel, linux-any, any-amd64, any */
  111. class PackageArchitectureMatchesSpecification : public PackageMatcher {
  112. std::string literal;
  113. std::string complete;
  114. bool isPattern;
  115. /** \brief dpointer placeholder (for later in case we need it) */
  116. void *d;
  117. public:
  118. /** \brief matching against architecture specification strings
  119. *
  120. * @param pattern is the architecture specification string
  121. * @param isPattern defines if the given \b pattern is a
  122. * architecture specification pattern to match others against
  123. * or if it is the fixed string and matched against patterns
  124. */
  125. PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern = true);
  126. bool operator() (char const * const &arch);
  127. virtual bool operator() (pkgCache::PkgIterator const &Pkg);
  128. virtual bool operator() (pkgCache::VerIterator const &Ver);
  129. virtual ~PackageArchitectureMatchesSpecification();
  130. };
  131. #endif
  132. /*}}}*/
  133. }
  134. }
  135. #endif