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 {
00028    protected:
00029    
00030    MMap *Map;
00031    pkgCache *Cache;
00032    pkgDepCache *DCache;
00033    pkgSourceList *SrcList;
00034 
00035    public:
00036    pkgPolicy *Policy;
00037 
00038    // We look pretty much exactly like a pointer to a dep cache
00039    inline operator pkgCache &() {return *Cache;};
00040    inline operator pkgCache *() {return Cache;};
00041    inline operator pkgDepCache &() {return *DCache;};
00042    inline operator pkgDepCache *() {return DCache;};
00043    inline operator pkgPolicy &() {return *Policy;};
00044    inline operator pkgPolicy *() {return Policy;};
00045    inline operator pkgSourceList &() {return *SrcList;};
00046    inline operator pkgSourceList *() {return SrcList;};
00047    inline pkgDepCache *operator ->() {return DCache;};
00048    inline pkgDepCache &operator *() {return *DCache;};
00049    inline pkgDepCache::StateCache &operator [](pkgCache::PkgIterator const &I) {return (*DCache)[I];};
00050    inline unsigned char &operator [](pkgCache::DepIterator const &I) {return (*DCache)[I];};
00051 
00052    bool BuildCaches(OpProgress *Progress = NULL,bool WithLock = true);
00053    __deprecated bool BuildCaches(OpProgress &Progress,bool const &WithLock = true) { return BuildCaches(&Progress, WithLock); };
00054    bool BuildSourceList(OpProgress *Progress = NULL);
00055    bool BuildPolicy(OpProgress *Progress = NULL);
00056    bool BuildDepCache(OpProgress *Progress = NULL);
00057    bool Open(OpProgress *Progress = NULL, bool WithLock = true);
00058    inline bool ReadOnlyOpen(OpProgress *Progress = NULL) { return Open(Progress, false); };
00059    __deprecated bool Open(OpProgress &Progress,bool const &WithLock = true) { return Open(&Progress, WithLock); };
00060    void Close();
00061 
00062    inline pkgCache* GetPkgCache() { BuildCaches(NULL, false); return Cache; };
00063    inline pkgDepCache* GetDepCache() { BuildDepCache(); return DCache; };
00064    inline pkgPolicy* GetPolicy() { BuildPolicy(); return Policy; };
00065    inline pkgSourceList* GetSourceList() { BuildSourceList(); return SrcList; };
00066 
00067    inline bool IsPkgCacheBuilt() const { return (Cache != NULL); };
00068    inline bool IsDepCacheBuilt() const { return (DCache != NULL); };
00069    inline bool IsPolicyBuilt() const { return (Policy != NULL); };
00070    inline bool IsSrcListBuilt() const { return (SrcList != NULL); };
00071 
00072    pkgCacheFile();
00073    virtual ~pkgCacheFile();
00074 };
00075 
00076 #endif