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