private-cacheset.h 4.4 KB

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