private-cachefile.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef APT_PRIVATE_CACHEFILE_H
  2. #define APT_PRIVATE_CACHEFILE_H
  3. #include <apt-pkg/cachefile.h>
  4. #include <apt-pkg/progress.h>
  5. #include <apt-pkg/configuration.h>
  6. #include <apt-pkg/pkgcache.h>
  7. #include <apt-pkg/macros.h>
  8. #include <apt-pkg/sourcelist.h>
  9. #include <apt-pkg/cacheset.h>
  10. #include <apti18n.h>
  11. // FIXME: we need to find a way to export this
  12. class APT_PUBLIC SourceList : public pkgSourceList
  13. {
  14. public:
  15. // Add custom metaIndex (e.g. local files)
  16. void AddMetaIndex(metaIndex *mi) {
  17. SrcList.push_back(mi);
  18. }
  19. };
  20. // class CacheFile - Cover class for some dependency cache functions /*{{{*/
  21. class APT_PUBLIC CacheFile : public pkgCacheFile
  22. {
  23. public:
  24. std::vector<map_pointer_t> UniverseList;
  25. bool CheckDeps(bool AllowBroken = false);
  26. bool BuildCaches(bool WithLock = true)
  27. {
  28. OpTextProgress Prog(*_config);
  29. if (pkgCacheFile::BuildCaches(&Prog,WithLock) == false)
  30. return false;
  31. return true;
  32. }
  33. // FIXME: this can go once the "libapt-pkg" pkgSourceList has a way
  34. // to add custom metaIndexes (or custom local files or so)
  35. bool BuildSourceList(OpProgress */*Progress*/ = NULL) {
  36. if (SrcList != NULL)
  37. return true;
  38. SrcList = new SourceList();
  39. if (SrcList->ReadMainList() == false)
  40. return _error->Error(_("The list of sources could not be read."));
  41. return true;
  42. }
  43. bool Open(bool WithLock = true)
  44. {
  45. OpTextProgress Prog(*_config);
  46. return pkgCacheFile::Open(&Prog,WithLock);
  47. };
  48. bool OpenForInstall()
  49. {
  50. if (_config->FindB("APT::Get::Print-URIs") == true)
  51. return Open(false);
  52. else
  53. return Open(true);
  54. }
  55. };
  56. /*}}}*/
  57. class APT_PUBLIC SortedPackageUniverse : public APT::PackageUniverse
  58. {
  59. std::vector<map_pointer_t> &List;
  60. void LazyInit() const;
  61. public:
  62. SortedPackageUniverse(CacheFile &Cache);
  63. class const_iterator : public APT::Container_iterator_base<APT::PackageContainerInterface, SortedPackageUniverse, SortedPackageUniverse::const_iterator, std::vector<map_pointer_t>::const_iterator, pkgCache::PkgIterator>
  64. {
  65. pkgCache * const Cache;
  66. protected:
  67. inline virtual pkgCache::PkgIterator getType(void) const APT_OVERRIDE
  68. {
  69. if (*_iter == 0) return pkgCache::PkgIterator(*Cache);
  70. return pkgCache::PkgIterator(*Cache, Cache->PkgP + *_iter);
  71. }
  72. public:
  73. explicit const_iterator(pkgCache * const Owner, std::vector<map_pointer_t>::const_iterator i):
  74. Container_iterator_base<APT::PackageContainerInterface, SortedPackageUniverse, SortedPackageUniverse::const_iterator, std::vector<map_pointer_t>::const_iterator, pkgCache::PkgIterator>(i), Cache(Owner) {}
  75. };
  76. typedef const_iterator iterator;
  77. APT_PUBLIC const_iterator begin() const { LazyInit(); return const_iterator(data(), List.begin()); }
  78. APT_PUBLIC const_iterator end() const { LazyInit(); return const_iterator(data(), List.end()); }
  79. APT_PUBLIC const_iterator cbegin() const { LazyInit(); return const_iterator(data(), List.begin()); }
  80. APT_PUBLIC const_iterator cend() const { LazyInit(); return const_iterator(data(), List.end()); }
  81. APT_PUBLIC iterator begin() { LazyInit(); return iterator(data(), List.begin()); }
  82. APT_PUBLIC iterator end() { LazyInit(); return iterator(data(), List.end()); }
  83. };
  84. #endif