]> git.saurik.com Git - apt.git/blob - apt-pkg/cachefile.h
merged from david
[apt.git] / apt-pkg / cachefile.h
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 #ifndef APT_8_CLEANER_HEADERS
24 #include <apt-pkg/acquire.h>
25 #include <apt-pkg/policy.h>
26 #include <apt-pkg/sourcelist.h>
27 #endif
28
29 class pkgPolicy;
30 class pkgSourceList;
31 class OpProgress;
32
33 class pkgCacheFile
34 {
35 /** \brief dpointer placeholder (for later in case we need it) */
36 void *d;
37
38 protected:
39
40 MMap *Map;
41 pkgCache *Cache;
42 pkgDepCache *DCache;
43 pkgSourceList *SrcList;
44
45 public:
46 pkgPolicy *Policy;
47
48 // We look pretty much exactly like a pointer to a dep cache
49 inline operator pkgCache &() {return *Cache;};
50 inline operator pkgCache *() {return Cache;};
51 inline operator pkgDepCache &() {return *DCache;};
52 inline operator pkgDepCache *() {return DCache;};
53 inline operator pkgPolicy &() {return *Policy;};
54 inline operator pkgPolicy *() {return Policy;};
55 inline operator pkgSourceList &() {return *SrcList;};
56 inline operator pkgSourceList *() {return SrcList;};
57 inline pkgDepCache *operator ->() {return DCache;};
58 inline pkgDepCache &operator *() {return *DCache;};
59 inline pkgDepCache::StateCache &operator [](pkgCache::PkgIterator const &I) {return (*DCache)[I];};
60 inline unsigned char &operator [](pkgCache::DepIterator const &I) {return (*DCache)[I];};
61
62 bool BuildCaches(OpProgress *Progress = NULL,bool WithLock = true);
63 __deprecated bool BuildCaches(OpProgress &Progress,bool const &WithLock = true) { return BuildCaches(&Progress, WithLock); };
64 bool BuildSourceList(OpProgress *Progress = NULL);
65 bool BuildPolicy(OpProgress *Progress = NULL);
66 bool BuildDepCache(OpProgress *Progress = NULL);
67 bool Open(OpProgress *Progress = NULL, bool WithLock = true);
68 inline bool ReadOnlyOpen(OpProgress *Progress = NULL) { return Open(Progress, false); };
69 __deprecated bool Open(OpProgress &Progress,bool const &WithLock = true) { return Open(&Progress, WithLock); };
70 static void RemoveCaches();
71 void Close();
72
73 inline pkgCache* GetPkgCache() { BuildCaches(NULL, false); return Cache; };
74 inline pkgDepCache* GetDepCache() { BuildDepCache(); return DCache; };
75 inline pkgPolicy* GetPolicy() { BuildPolicy(); return Policy; };
76 inline pkgSourceList* GetSourceList() { BuildSourceList(); return SrcList; };
77
78 inline bool IsPkgCacheBuilt() const { return (Cache != NULL); };
79 inline bool IsDepCacheBuilt() const { return (DCache != NULL); };
80 inline bool IsPolicyBuilt() const { return (Policy != NULL); };
81 inline bool IsSrcListBuilt() const { return (SrcList != NULL); };
82
83 pkgCacheFile();
84 virtual ~pkgCacheFile();
85 };
86
87 #endif