apt @VERSION@
cachefile.h
00001 // -*- mode: cpp; mode: fold -*-
00002 // Description                                                          /*{{{*/
00003 // $Id: cachefile.h,v 1.5 2002/04/27 04:28:04 jgg Exp $
00004 /* ######################################################################
00005    
00006    CacheFile - Simple wrapper class for opening, generating and whatnot
00007    
00008    This class implements a simple 2 line mechanism to open various sorts
00009    of caches. It can operate as root, as not root, show progress and so on,
00010    it transparently handles everything necessary.
00011    
00012    This means it can rebuild caches from the source list and instantiates
00013    and prepares the standard policy mechanism.
00014    
00015    ##################################################################### */
00016                                                                         /*}}}*/
00017 #ifndef PKGLIB_CACHEFILE_H
00018 #define PKGLIB_CACHEFILE_H
00019 
00020 
00021 #include <apt-pkg/depcache.h>
00022 #include <apt-pkg/acquire.h>
00023 #include <apt-pkg/policy.h>
00024 #include <apt-pkg/sourcelist.h>
00025 
00026 class pkgCacheFile
00027 {
00029    void *d;
00030 
00031    protected:
00032    
00033    MMap *Map;
00034    pkgCache *Cache;
00035    pkgDepCache *DCache;
00036    pkgSourceList *SrcList;
00037 
00038    public:
00039    pkgPolicy *Policy;
00040 
00041    // We look pretty much exactly like a pointer to a dep cache
00042    inline operator pkgCache &() {return *Cache;};
00043    inline operator pkgCache *() {return Cache;};
00044    inline operator pkgDepCache &() {return *DCache;};
00045    inline operator pkgDepCache *() {return DCache;};
00046    inline operator pkgPolicy &() {return *Policy;};
00047    inline operator pkgPolicy *() {return Policy;};
00048    inline operator pkgSourceList &() {return *SrcList;};
00049    inline operator pkgSourceList *() {return SrcList;};
00050    inline pkgDepCache *operator ->() {return DCache;};
00051    inline pkgDepCache &operator *() {return *DCache;};
00052    inline pkgDepCache::StateCache &operator [](pkgCache::PkgIterator const &I) {return (*DCache)[I];};
00053    inline unsigned char &operator [](pkgCache::DepIterator const &I) {return (*DCache)[I];};
00054 
00055    bool BuildCaches(OpProgress *Progress = NULL,bool WithLock = true);
00056    __deprecated bool BuildCaches(OpProgress &Progress,bool const &WithLock = true) { return BuildCaches(&Progress, WithLock); };
00057    bool BuildSourceList(OpProgress *Progress = NULL);
00058    bool BuildPolicy(OpProgress *Progress = NULL);
00059    bool BuildDepCache(OpProgress *Progress = NULL);
00060    bool Open(OpProgress *Progress = NULL, bool WithLock = true);
00061    inline bool ReadOnlyOpen(OpProgress *Progress = NULL) { return Open(Progress, false); };
00062    __deprecated bool Open(OpProgress &Progress,bool const &WithLock = true) { return Open(&Progress, WithLock); };
00063    void Close();
00064 
00065    inline pkgCache* GetPkgCache() { BuildCaches(NULL, false); return Cache; };
00066    inline pkgDepCache* GetDepCache() { BuildDepCache(); return DCache; };
00067    inline pkgPolicy* GetPolicy() { BuildPolicy(); return Policy; };
00068    inline pkgSourceList* GetSourceList() { BuildSourceList(); return SrcList; };
00069 
00070    inline bool IsPkgCacheBuilt() const { return (Cache != NULL); };
00071    inline bool IsDepCacheBuilt() const { return (DCache != NULL); };
00072    inline bool IsPolicyBuilt() const { return (Policy != NULL); };
00073    inline bool IsSrcListBuilt() const { return (SrcList != NULL); };
00074 
00075    pkgCacheFile();
00076    virtual ~pkgCacheFile();
00077 };
00078 
00079 #endif