cachefilter.h 5.1 KB

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