You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

127 lines
4.6 KiB

  1. #ifndef APT_PRIVATE_CACHESET_H
  2. #define APT_PRIVATE_CACHESET_H
  3. #include <apt-pkg/cacheset.h>
  4. #include <apt-pkg/macros.h>
  5. #include <apt-private/private-output.h>
  6. #include <list>
  7. #include <set>
  8. #include <string>
  9. #include <vector>
  10. class OpProgress;
  11. class VerIteratorWithCaching
  12. {
  13. const pkgCache::VerIterator iter;
  14. const pkgCache::DescFile * descFile;
  15. public:
  16. VerIteratorWithCaching(const pkgCache::VerIterator& iter) :
  17. iter(iter),
  18. descFile(iter->DescriptionList != 0
  19. ? (const pkgCache::DescFile *) iter.TranslatedDescription().FileList()
  20. : nullptr)
  21. {}
  22. const pkgCache::DescFile * CachedDescFile() const { return descFile; }
  23. operator pkgCache::VerIterator() const { return iter; }
  24. map_id_t ID() const { return iter->ID; }
  25. };
  26. struct VersionSortDescriptionLocality /*{{{*/
  27. {
  28. bool operator () (const VerIteratorWithCaching &v_lhs,
  29. const VerIteratorWithCaching &v_rhs)
  30. {
  31. pkgCache::DescFile const *A = v_lhs.CachedDescFile();
  32. pkgCache::DescFile const *B = v_rhs.CachedDescFile();
  33. if (A == nullptr)
  34. {
  35. if (B == nullptr)
  36. return v_lhs.ID() < v_rhs.ID();
  37. return true;
  38. }
  39. else if (B == nullptr)
  40. return false;
  41. if (A->File == B->File)
  42. {
  43. if (A->Offset == B->Offset)
  44. return v_lhs.ID() < v_rhs.ID();
  45. return A->Offset < B->Offset;
  46. }
  47. return A->File < B->File;
  48. }
  49. };
  50. /*}}}*/
  51. // sorted by locality which makes iterating much faster
  52. typedef APT::VersionContainer<
  53. std::set<VerIteratorWithCaching,
  54. VersionSortDescriptionLocality> > LocalitySortedVersionSet;
  55. class Matcher {
  56. public:
  57. virtual bool operator () (const pkgCache::PkgIterator &/*P*/) {
  58. return true;}
  59. };
  60. // FIXME: add default argument for OpProgress (or overloaded function)
  61. bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
  62. APT::VersionContainerInterface * const vci,
  63. Matcher &matcher,
  64. OpProgress * const progress);
  65. bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
  66. APT::VersionContainerInterface * const vci,
  67. OpProgress * const progress);
  68. // CacheSetHelper saving virtual packages /*{{{*/
  69. class CacheSetHelperVirtuals: public APT::CacheSetHelper {
  70. public:
  71. APT::PackageSet virtualPkgs;
  72. virtual pkgCache::VerIterator canNotGetVersion(enum CacheSetHelper::VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
  73. virtual void canNotFindVersion(enum CacheSetHelper::VerSelector const select, APT::VersionContainerInterface * vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
  74. virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str) APT_OVERRIDE;
  75. CacheSetHelperVirtuals(bool const ShowErrors = true, GlobalError::MsgType const &ErrorType = GlobalError::NOTICE);
  76. };
  77. /*}}}*/
  78. // CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/
  79. class CacheSetHelperAPTGet : public APT::CacheSetHelper {
  80. /** \brief stream message should be printed to */
  81. std::ostream &out;
  82. /** \brief were things like Task or RegEx used to select packages? */
  83. bool explicitlyNamed;
  84. APT::PackageSet virtualPkgs;
  85. public:
  86. std::list<std::pair<pkgCache::VerIterator, std::string> > selectedByRelease;
  87. std::set<std::string> notFound;
  88. explicit CacheSetHelperAPTGet(std::ostream &out);
  89. virtual void showTaskSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE;
  90. virtual void showFnmatchSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE;
  91. virtual void showRegExSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE;
  92. virtual void showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/, pkgCache::VerIterator const Ver,
  93. std::string const &ver, bool const /*verIsRel*/) APT_OVERRIDE;
  94. bool showVirtualPackageErrors(pkgCacheFile &Cache);
  95. virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
  96. virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
  97. virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str) APT_OVERRIDE;
  98. APT::VersionSet tryVirtualPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg,
  99. CacheSetHelper::VerSelector const select);
  100. inline bool allPkgNamedExplicitly() const { return explicitlyNamed; }
  101. };
  102. /*}}}*/
  103. #endif