cachefile.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. CacheFile - Simple wrapper class for opening, generating and whatnot
  5. This class implements a simple 2 line mechanism to open various sorts
  6. of caches. It can operate as root, as not root, show progress and so on,
  7. it transparently handles everything necessary.
  8. This means it can rebuild caches from the source list and instantiates
  9. and prepares the standard policy mechanism.
  10. ##################################################################### */
  11. /*}}}*/
  12. #ifndef PKGLIB_CACHEFILE_H
  13. #define PKGLIB_CACHEFILE_H
  14. #include <stddef.h>
  15. #include <apt-pkg/depcache.h>
  16. #include <apt-pkg/macros.h>
  17. #include <apt-pkg/pkgcache.h>
  18. #include <apt-pkg/cacheiterators.h>
  19. #ifndef APT_8_CLEANER_HEADERS
  20. #include <apt-pkg/acquire.h>
  21. #include <apt-pkg/policy.h>
  22. #include <apt-pkg/sourcelist.h>
  23. #endif
  24. class MMap;
  25. class pkgPolicy;
  26. class pkgSourceList;
  27. class pkgIndexFile;
  28. class OpProgress;
  29. class pkgCacheFile
  30. {
  31. /** \brief dpointer placeholder (for later in case we need it) */
  32. void * const d;
  33. bool ExternOwner;
  34. protected:
  35. MMap *Map;
  36. pkgCache *Cache;
  37. pkgDepCache *DCache;
  38. pkgSourceList *SrcList;
  39. public:
  40. pkgPolicy *Policy;
  41. // We look pretty much exactly like a pointer to a dep cache
  42. inline operator pkgCache &() const {return *Cache;};
  43. inline operator pkgCache *() const {return Cache;};
  44. inline operator pkgDepCache &() const {return *DCache;};
  45. inline operator pkgDepCache *() const {return DCache;};
  46. inline operator pkgPolicy &() const {return *Policy;};
  47. inline operator pkgPolicy *() const {return Policy;};
  48. inline operator pkgSourceList &() const {return *SrcList;};
  49. inline operator pkgSourceList *() const {return SrcList;};
  50. inline pkgDepCache *operator ->() const {return DCache;};
  51. inline pkgDepCache &operator *() const {return *DCache;};
  52. inline pkgDepCache::StateCache &operator [](pkgCache::PkgIterator const &I) const {return (*DCache)[I];};
  53. inline unsigned char &operator [](pkgCache::DepIterator const &I) const {return (*DCache)[I];};
  54. bool BuildCaches(OpProgress *Progress = NULL,bool WithLock = true);
  55. APT_DEPRECATED_MSG("Pass Progress in as a pointer") bool BuildCaches(OpProgress &Progress,bool const &WithLock = true) { return BuildCaches(&Progress, WithLock); };
  56. bool BuildSourceList(OpProgress *Progress = NULL);
  57. bool BuildPolicy(OpProgress *Progress = NULL);
  58. bool BuildDepCache(OpProgress *Progress = NULL);
  59. bool Open(OpProgress *Progress = NULL, bool WithLock = true);
  60. inline bool ReadOnlyOpen(OpProgress *Progress = NULL) { return Open(Progress, false); };
  61. APT_DEPRECATED_MSG("Pass Progress in as a pointer") bool Open(OpProgress &Progress,bool const &WithLock = true) { return Open(&Progress, WithLock); };
  62. static void RemoveCaches();
  63. void Close();
  64. bool AddIndexFile(pkgIndexFile * const File);
  65. inline pkgCache* GetPkgCache() { BuildCaches(NULL, false); return Cache; };
  66. inline pkgDepCache* GetDepCache() { BuildDepCache(); return DCache; };
  67. inline pkgPolicy* GetPolicy() { BuildPolicy(); return Policy; };
  68. inline pkgSourceList* GetSourceList() { BuildSourceList(); return SrcList; };
  69. inline bool IsPkgCacheBuilt() const { return (Cache != NULL); };
  70. inline bool IsDepCacheBuilt() const { return (DCache != NULL); };
  71. inline bool IsPolicyBuilt() const { return (Policy != NULL); };
  72. inline bool IsSrcListBuilt() const { return (SrcList != NULL); };
  73. pkgCacheFile();
  74. explicit pkgCacheFile(pkgDepCache * const Owner);
  75. virtual ~pkgCacheFile();
  76. };
  77. #endif