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