private-cacheset.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 <vector>
  7. #include <list>
  8. #include <set>
  9. #include <string>
  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. };
  25. struct VersionSortDescriptionLocality /*{{{*/
  26. {
  27. bool operator () (const VerIteratorWithCaching &v_lhs,
  28. const VerIteratorWithCaching &v_rhs)
  29. {
  30. pkgCache::DescFile const *A = v_lhs.CachedDescFile();
  31. pkgCache::DescFile const *B = v_rhs.CachedDescFile();
  32. if (A == nullptr && B == nullptr)
  33. return false;
  34. if (A == nullptr)
  35. return true;
  36. if (B == nullptr)
  37. return false;
  38. if (A->File == B->File)
  39. return A->Offset < B->Offset;
  40. return A->File < B->File;
  41. }
  42. };
  43. /*}}}*/
  44. // sorted by locality which makes iterating much faster
  45. typedef APT::VersionContainer<
  46. std::set<VerIteratorWithCaching,
  47. VersionSortDescriptionLocality> > LocalitySortedVersionSet;
  48. class Matcher {
  49. public:
  50. virtual bool operator () (const pkgCache::PkgIterator &/*P*/) {
  51. return true;}
  52. };
  53. // FIXME: add default argument for OpProgress (or overloaded function)
  54. bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
  55. APT::VersionContainerInterface * const vci,
  56. Matcher &matcher,
  57. OpProgress * const progress);
  58. bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
  59. APT::VersionContainerInterface * const vci,
  60. OpProgress * const progress);
  61. // CacheSetHelper saving virtual packages /*{{{*/
  62. class CacheSetHelperVirtuals: public APT::CacheSetHelper {
  63. public:
  64. APT::PackageSet virtualPkgs;
  65. virtual pkgCache::VerIterator canNotGetVersion(enum CacheSetHelper::VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
  66. virtual void canNotFindVersion(enum CacheSetHelper::VerSelector const select, APT::VersionContainerInterface * vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
  67. virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str) APT_OVERRIDE;
  68. CacheSetHelperVirtuals(bool const ShowErrors = true, GlobalError::MsgType const &ErrorType = GlobalError::NOTICE);
  69. };
  70. /*}}}*/
  71. // CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/
  72. class CacheSetHelperAPTGet : public APT::CacheSetHelper {
  73. /** \brief stream message should be printed to */
  74. std::ostream &out;
  75. /** \brief were things like Task or RegEx used to select packages? */
  76. bool explicitlyNamed;
  77. APT::PackageSet virtualPkgs;
  78. public:
  79. std::list<std::pair<pkgCache::VerIterator, std::string> > selectedByRelease;
  80. explicit CacheSetHelperAPTGet(std::ostream &out);
  81. virtual void showTaskSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE;
  82. virtual void showFnmatchSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE;
  83. virtual void showRegExSelection(pkgCache::PkgIterator const &Pkg, std::string const &pattern) APT_OVERRIDE;
  84. virtual void showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/, pkgCache::VerIterator const Ver,
  85. std::string const &ver, bool const /*verIsRel*/) APT_OVERRIDE;
  86. bool showVirtualPackageErrors(pkgCacheFile &Cache);
  87. virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
  88. virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
  89. virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str) APT_OVERRIDE;
  90. APT::VersionSet tryVirtualPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg,
  91. CacheSetHelper::VerSelector const select);
  92. inline bool allPkgNamedExplicitly() const { return explicitlyNamed; }
  93. };
  94. /*}}}*/
  95. #endif