cacheset.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /** \file cacheset.h
  4. Wrappers around std::set to have set::iterators which behave
  5. similar to the Iterators of the cache structures.
  6. Provides also a few helper methods which work with these sets */
  7. /*}}}*/
  8. #ifndef APT_CACHESET_H
  9. #define APT_CACHESET_H
  10. // Include Files /*{{{*/
  11. #include <iostream>
  12. #include <fstream>
  13. #include <set>
  14. #include <string>
  15. #include <apt-pkg/pkgcache.h>
  16. /*}}}*/
  17. namespace APT {
  18. class PackageSet : public std::set<pkgCache::PkgIterator> { /*{{{*/
  19. /** \class APT::PackageSet
  20. Simple wrapper around a std::set to provide a similar interface to
  21. a set of packages as to the complete set of all packages in the
  22. pkgCache. */
  23. public: /*{{{*/
  24. /** \brief smell like a pkgCache::PkgIterator */
  25. class const_iterator : public std::set<pkgCache::PkgIterator>::const_iterator {
  26. public:
  27. const_iterator(std::set<pkgCache::PkgIterator>::const_iterator x) :
  28. std::set<pkgCache::PkgIterator>::const_iterator(x) {}
  29. operator pkgCache::PkgIterator(void) { return **this; }
  30. inline const char *Name() const {return (**this).Name(); }
  31. inline std::string FullName(bool const &Pretty) const { return (**this).FullName(Pretty); }
  32. inline std::string FullName() const { return (**this).FullName(); }
  33. inline const char *Section() const {return (**this).Section(); }
  34. inline bool Purge() const {return (**this).Purge(); }
  35. inline const char *Arch() const {return (**this).Arch(); }
  36. inline pkgCache::GrpIterator Group() const { return (**this).Group(); }
  37. inline pkgCache::VerIterator VersionList() const { return (**this).VersionList(); }
  38. inline pkgCache::VerIterator CurrentVer() const { return (**this).CurrentVer(); }
  39. inline pkgCache::DepIterator RevDependsList() const { return (**this).RevDependsList(); }
  40. inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); }
  41. inline pkgCache::PkgIterator::OkState State() const { return (**this).State(); }
  42. inline const char *CandVersion() const { return (**this).CandVersion(); }
  43. inline const char *CurVersion() const { return (**this).CurVersion(); }
  44. inline pkgCache *Cache() const { return (**this).Cache(); };
  45. inline unsigned long Index() const {return (**this).Index();};
  46. // we have only valid iterators here
  47. inline bool end() const { return false; };
  48. friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, (*i)); }
  49. inline pkgCache::Package const * operator->() const {
  50. return &***this;
  51. };
  52. };
  53. // 103. set::iterator is required to be modifiable, but this allows modification of keys
  54. typedef typename APT::PackageSet::const_iterator iterator;
  55. /** \brief returns all packages in the cache whose name matchs a given pattern
  56. A simple helper responsible for executing a regular expression on all
  57. package names in the cache. Optional it prints a a notice about the
  58. packages chosen cause of the given package.
  59. \param Cache the packages are in
  60. \param pattern regular expression for package names
  61. \param out stream to print the notice to */
  62. static APT::PackageSet FromRegEx(pkgCache &Cache, std::string pattern, std::ostream &out);
  63. static APT::PackageSet FromRegEx(pkgCache &Cache, std::string const &pattern) {
  64. std::ostream out (std::ofstream("/dev/null").rdbuf());
  65. return APT::PackageSet::FromRegEx(Cache, pattern, out);
  66. }
  67. /** \brief returns all packages specified on the commandline
  68. Get all package names from the commandline and executes regex's if needed.
  69. No special package command is supported, just plain names.
  70. \param Cache the packages are in
  71. \param cmdline Command line the package names should be extracted from
  72. \param out stream to print various notices to */
  73. static APT::PackageSet FromCommandLine(pkgCache &Cache, const char **cmdline, std::ostream &out);
  74. static APT::PackageSet FromCommandLine(pkgCache &Cache, const char **cmdline) {
  75. std::ostream out (std::ofstream("/dev/null").rdbuf());
  76. return APT::PackageSet::FromCommandLine(Cache, cmdline, out);
  77. }
  78. /*}}}*/
  79. }; /*}}}*/
  80. class VersionSet : public std::set<pkgCache::VerIterator> { /*{{{*/
  81. /** \class APT::VersionSet
  82. Simple wrapper around a std::set to provide a similar interface to
  83. a set of versions as to the complete set of all versions in the
  84. pkgCache. */
  85. public: /*{{{*/
  86. /** \brief smell like a pkgCache::VerIterator */
  87. class const_iterator : public std::set<pkgCache::VerIterator>::const_iterator {
  88. public:
  89. const_iterator(std::set<pkgCache::VerIterator>::const_iterator x) :
  90. std::set<pkgCache::VerIterator>::const_iterator(x) {}
  91. operator pkgCache::VerIterator(void) { return **this; }
  92. inline pkgCache *Cache() const { return (**this).Cache(); };
  93. inline unsigned long Index() const {return (**this).Index();};
  94. // we have only valid iterators here
  95. inline bool end() const { return false; };
  96. inline pkgCache::Version const * operator->() const {
  97. return &***this;
  98. };
  99. inline int CompareVer(const pkgCache::VerIterator &B) const { return (**this).CompareVer(B); };
  100. inline const char *VerStr() const { return (**this).VerStr(); };
  101. inline const char *Section() const { return (**this).Section(); };
  102. inline const char *Arch() const { return (**this).Arch(); };
  103. inline const char *Arch(bool const pseudo) const { return (**this).Arch(pseudo); };
  104. inline pkgCache::PkgIterator ParentPkg() const { return (**this).ParentPkg(); };
  105. inline pkgCache::DescIterator DescriptionList() const { return (**this).DescriptionList(); };
  106. inline pkgCache::DescIterator TranslatedDescription() const { return (**this).TranslatedDescription(); };
  107. inline pkgCache::DepIterator DependsList() const { return (**this).DependsList(); };
  108. inline pkgCache::PrvIterator ProvidesList() const { return (**this).ProvidesList(); };
  109. inline pkgCache::VerFileIterator FileList() const { return (**this).FileList(); };
  110. inline bool Downloadable() const { return (**this).Downloadable(); };
  111. inline const char *PriorityType() const { return (**this).PriorityType(); };
  112. inline string RelStr() const { return (**this).RelStr(); };
  113. inline bool Automatic() const { return (**this).Automatic(); };
  114. inline bool Pseudo() const { return (**this).Pseudo(); };
  115. inline pkgCache::VerFileIterator NewestFile() const { return (**this).NewestFile(); };
  116. };
  117. // 103. set::iterator is required to be modifiable, but this allows modification of keys
  118. typedef typename APT::VersionSet::const_iterator iterator;
  119. /*}}}*/
  120. }; /*}}}*/
  121. }
  122. #endif