private-cacheset.h 4.1 KB

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