private-cachefile.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 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. public:
  67. inline pkgCache::PkgIterator getType(void) const
  68. {
  69. if (*_iter == 0) return pkgCache::PkgIterator(*Cache);
  70. return pkgCache::PkgIterator(*Cache, Cache->PkgP + *_iter);
  71. }
  72. explicit const_iterator(pkgCache * const Owner, std::vector<map_pointer_t>::const_iterator i):
  73. Container_iterator_base<APT::PackageContainerInterface, SortedPackageUniverse, SortedPackageUniverse::const_iterator, std::vector<map_pointer_t>::const_iterator, pkgCache::PkgIterator>(i), Cache(Owner) {}
  74. };
  75. typedef const_iterator iterator;
  76. const_iterator begin() const { LazyInit(); return const_iterator(data(), List.begin()); }
  77. const_iterator end() const { LazyInit(); return const_iterator(data(), List.end()); }
  78. const_iterator cbegin() const { LazyInit(); return const_iterator(data(), List.begin()); }
  79. const_iterator cend() const { LazyInit(); return const_iterator(data(), List.end()); }
  80. iterator begin() { LazyInit(); return iterator(data(), List.begin()); }
  81. iterator end() { LazyInit(); return iterator(data(), List.end()); }
  82. };
  83. #endif