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