cachefilter.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. #else
  71. class PackageMatcher {
  72. public:
  73. virtual bool operator() (pkgCache::PkgIterator const &Pkg) { return false; };
  74. virtual bool operator() (pkgCache::GrpIterator const &Grp) { return false; };
  75. virtual bool operator() (pkgCache::VerIterator const &Ver) { return false; };
  76. virtual ~PackageMatcher() {};
  77. };
  78. // PackageNameMatchesRegEx /*{{{*/
  79. class PackageNameMatchesRegEx : public PackageMatcher {
  80. /** \brief dpointer placeholder (for later in case we need it) */
  81. void *d;
  82. regex_t* pattern;
  83. public:
  84. PackageNameMatchesRegEx(std::string const &Pattern);
  85. virtual bool operator() (pkgCache::PkgIterator const &Pkg);
  86. virtual bool operator() (pkgCache::GrpIterator const &Grp);
  87. virtual ~PackageNameMatchesRegEx();
  88. };
  89. /*}}}*/
  90. // PackageNameMatchesFnmatch /*{{{*/
  91. class PackageNameMatchesFnmatch : public PackageMatcher{
  92. /** \brief dpointer placeholder (for later in case we need it) */
  93. void *d;
  94. const std::string Pattern;
  95. public:
  96. PackageNameMatchesFnmatch(std::string const &Pattern)
  97. : Pattern(Pattern) {};
  98. virtual bool operator() (pkgCache::PkgIterator const &Pkg);
  99. virtual bool operator() (pkgCache::GrpIterator const &Grp);
  100. virtual ~PackageNameMatchesFnmatch() {};
  101. };
  102. /*}}}*/
  103. // PackageArchitectureMatchesSpecification /*{{{*/
  104. /** \class PackageArchitectureMatchesSpecification
  105. \brief matching against architecture specification strings
  106. The strings are of the format <kernel>-<cpu> where either component,
  107. or the whole string, can be the wildcard "any" as defined in
  108. debian-policy §11.1 "Architecture specification strings".
  109. Examples: i386, mipsel, linux-any, any-amd64, any */
  110. class PackageArchitectureMatchesSpecification : public PackageMatcher {
  111. std::string literal;
  112. std::string complete;
  113. bool isPattern;
  114. /** \brief dpointer placeholder (for later in case we need it) */
  115. void *d;
  116. public:
  117. /** \brief matching against architecture specification strings
  118. *
  119. * @param pattern is the architecture specification string
  120. * @param isPattern defines if the given \b pattern is a
  121. * architecture specification pattern to match others against
  122. * or if it is the fixed string and matched against patterns
  123. */
  124. PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern = true);
  125. bool operator() (char const * const &arch);
  126. virtual bool operator() (pkgCache::PkgIterator const &Pkg);
  127. virtual bool operator() (pkgCache::VerIterator const &Ver);
  128. virtual ~PackageArchitectureMatchesSpecification();
  129. };
  130. #endif
  131. /*}}}*/
  132. }
  133. }
  134. #endif