home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 February / PCWorld_2000-02_cd.bin / live / usr / include / apt-pkg / pkgcache.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-21  |  7.9 KB  |  287 lines

  1. // -*- mode: cpp; mode: fold -*-
  2. // Description                                /*{{{*/
  3. // $Id: pkgcache.h,v 1.20 1999/05/23 22:55:54 jgg Exp $
  4. /* ######################################################################
  5.    
  6.    Cache - Structure definitions for the cache file
  7.    
  8.    Please see doc/apt-pkg/cache.sgml for a more detailed description of 
  9.    this format. Also be sure to keep that file up-to-date!!
  10.    
  11.    Clients should always use the CacheIterators classes for access to the
  12.    cache. They provide a simple STL-like method for traversing the links
  13.    of the datastructure.
  14.    
  15.    See pkgcachegen.h for information about generating cache structures.
  16.    
  17.    ##################################################################### */
  18.                                     /*}}}*/
  19. // Header section: pkglib
  20. #ifndef PKGLIB_PKGCACHE_H
  21. #define PKGLIB_PKGCACHE_H
  22.  
  23. #ifdef __GNUG__
  24. #pragma interface "apt-pkg/pkgcache.h"
  25. #endif 
  26.  
  27. #include <string>
  28. #include <time.h>
  29. #include <apt-pkg/mmap.h>
  30.  
  31. /* This should be a 32 bit type, larger tyes use too much ram and smaller
  32.    types are too small. Where ever possible 'unsigned long' should be used
  33.    instead of this internal type */
  34. typedef unsigned int __apt_ptrloc;
  35.  
  36. class pkgCache
  37. {
  38.    public:
  39.    // Cache element predeclarations
  40.    struct Header;
  41.    struct Package;
  42.    struct PackageFile;
  43.    struct Version;
  44.    struct Provides;
  45.    struct Dependency;
  46.    struct StringItem;
  47.    struct VerFile;
  48.    
  49.    // Iterators
  50.    class PkgIterator;
  51.    class VerIterator;
  52.    class DepIterator;
  53.    class PrvIterator;
  54.    class PkgFileIterator;
  55.    class VerFileIterator;
  56.    friend PkgIterator;
  57.    friend VerIterator;
  58.    friend DepIterator;
  59.    friend PrvIterator;
  60.    friend PkgFileIterator;
  61.    friend VerFileIterator;
  62.    
  63.    // These are all the constants used in the cache structures
  64.    struct Dep
  65.    {
  66.       enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
  67.      Conflicts=5,Replaces=6};
  68.       enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
  69.      Greater=0x4,Equals=0x5,NotEquals=0x6};
  70.    };
  71.    
  72.    struct State
  73.    {
  74.       enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
  75.       enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
  76.       enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
  77.       enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
  78.      UnInstalled=3,HalfInstalled=4,ConfigFiles=5,Installed=6};
  79.    };
  80.    
  81.    struct Flag
  82.    {
  83.       enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
  84.       enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)};
  85.    };
  86.    
  87.    protected:
  88.    
  89.    // Memory mapped cache file
  90.    string CacheFile;
  91.    MMap ⤅
  92.  
  93.    unsigned long sHash(string S) const;
  94.    unsigned long sHash(const char *S) const;
  95.    
  96.    public:
  97.    
  98.    // Pointers to the arrays of items
  99.    Header *HeaderP;
  100.    Package *PkgP;
  101.    VerFile *VerFileP;
  102.    PackageFile *PkgFileP;
  103.    Version *VerP;
  104.    Provides *ProvideP;
  105.    Dependency *DepP;
  106.    StringItem *StringItemP;
  107.    char *StrP;
  108.  
  109.    virtual bool ReMap();
  110.    inline bool Sync() {return Map.Sync();};
  111.    inline MMap &GetMap() {return Map;};
  112.    
  113.    // String hashing function (512 range)
  114.    inline unsigned long Hash(string S) const {return sHash(S);};
  115.    inline unsigned long Hash(const char *S) const {return sHash(S);};
  116.  
  117.    // Usefull transformation things
  118.    const char *Priority(unsigned char Priority);
  119.    
  120.    // Accessors
  121.    PkgIterator FindPkg(string Name);
  122.    Header &Head() {return *HeaderP;};
  123.    inline PkgIterator PkgBegin();
  124.    inline PkgIterator PkgEnd();
  125.    inline PkgFileIterator FileBegin();
  126.    inline PkgFileIterator FileEnd();
  127.    VerIterator GetCandidateVer(PkgIterator Pkg,bool AllowCurrent = true);
  128.    
  129.    pkgCache(MMap &Map);
  130.    virtual ~pkgCache() {};
  131. };
  132.  
  133. // Header structure
  134. struct pkgCache::Header
  135. {
  136.    // Signature information
  137.    unsigned long Signature;
  138.    short MajorVersion;
  139.    short MinorVersion;
  140.    bool Dirty;
  141.    
  142.    // Size of structure values
  143.    unsigned short HeaderSz;
  144.    unsigned short PackageSz;
  145.    unsigned short PackageFileSz;
  146.    unsigned short VersionSz;
  147.    unsigned short DependencySz;
  148.    unsigned short ProvidesSz;
  149.    unsigned short VerFileSz;
  150.    
  151.    // Structure counts
  152.    unsigned long PackageCount;
  153.    unsigned long VersionCount;
  154.    unsigned long DependsCount;
  155.    unsigned long PackageFileCount;
  156.    unsigned long VerFileCount;
  157.    unsigned long ProvidesCount;
  158.    
  159.    // Offsets
  160.    __apt_ptrloc FileList;              // struct PackageFile
  161.    __apt_ptrloc StringList;            // struct StringItem
  162.    unsigned long MaxVerFileSize;
  163.  
  164.    /* Allocation pools, there should be one of these for each structure
  165.       excluding the header */
  166.    DynamicMMap::Pool Pools[7];
  167.    
  168.    // Rapid package name lookup
  169.    __apt_ptrloc HashTable[2*1048];
  170.  
  171.    bool CheckSizes(Header &Against) const;
  172.    Header();
  173. };
  174.  
  175. struct pkgCache::Package
  176. {
  177.    // Pointers
  178.    __apt_ptrloc Name;              // Stringtable
  179.    __apt_ptrloc VersionList;       // Version
  180.    __apt_ptrloc TargetVer;         // Version
  181.    __apt_ptrloc CurrentVer;        // Version
  182.    __apt_ptrloc TargetDist;        // StringTable (StringItem)
  183.    __apt_ptrloc Section;           // StringTable (StringItem)
  184.       
  185.    // Linked list 
  186.    __apt_ptrloc NextPackage;       // Package
  187.    __apt_ptrloc RevDepends;        // Dependency
  188.    __apt_ptrloc ProvidesList;      // Provides
  189.    
  190.    // Install/Remove/Purge etc
  191.    unsigned char SelectedState;     // What
  192.    unsigned char InstState;         // Flags
  193.    unsigned char CurrentState;      // State
  194.    
  195.    unsigned short ID;
  196.    unsigned long Flags;
  197. };
  198.  
  199. struct pkgCache::PackageFile
  200. {
  201.    // Names
  202.    __apt_ptrloc FileName;        // Stringtable
  203.    __apt_ptrloc Archive;         // Stringtable
  204.    __apt_ptrloc Component;       // Stringtable
  205.    __apt_ptrloc Version;         // Stringtable
  206.    __apt_ptrloc Origin;          // Stringtable
  207.    __apt_ptrloc Label;           // Stringtable
  208.    __apt_ptrloc Architecture;    // Stringtable
  209.    unsigned long Size;            
  210.    unsigned long Flags;
  211.    
  212.    // Linked list
  213.    __apt_ptrloc NextFile;        // PackageFile
  214.    unsigned short ID;
  215.    time_t mtime;                  // Modification time for the file
  216. };
  217.  
  218. struct pkgCache::VerFile
  219. {
  220.    __apt_ptrloc File;           // PackageFile
  221.    __apt_ptrloc NextFile;       // PkgVerFile
  222.    __apt_ptrloc Offset;         // File offset
  223.    unsigned short Size;
  224. };
  225.  
  226. struct pkgCache::Version
  227. {
  228.    __apt_ptrloc VerStr;            // Stringtable
  229.    __apt_ptrloc Section;           // StringTable (StringItem)
  230.    __apt_ptrloc Arch;              // StringTable
  231.       
  232.    // Lists
  233.    __apt_ptrloc FileList;          // VerFile
  234.    __apt_ptrloc NextVer;           // Version
  235.    __apt_ptrloc DependsList;       // Dependency
  236.    __apt_ptrloc ParentPkg;         // Package
  237.    __apt_ptrloc ProvidesList;      // Provides
  238.    
  239.    __apt_ptrloc Size;              // These are the .deb size
  240.    __apt_ptrloc InstalledSize;
  241.    unsigned short Hash;
  242.    unsigned short ID;
  243.    unsigned char Priority;
  244. };
  245.  
  246. struct pkgCache::Dependency
  247. {
  248.    __apt_ptrloc Version;         // Stringtable
  249.    __apt_ptrloc Package;         // Package
  250.    __apt_ptrloc NextDepends;     // Dependency
  251.    __apt_ptrloc NextRevDepends;  // Dependency
  252.    __apt_ptrloc ParentVer;       // Version
  253.    
  254.    // Specific types of depends
  255.    unsigned char Type;
  256.    unsigned char CompareOp;
  257.    unsigned short ID;
  258. };
  259.  
  260. struct pkgCache::Provides
  261. {
  262.    __apt_ptrloc ParentPkg;        // Pacakge
  263.    __apt_ptrloc Version;          // Version
  264.    __apt_ptrloc ProvideVersion;   // Stringtable
  265.    __apt_ptrloc NextProvides;     // Provides
  266.    __apt_ptrloc NextPkgProv;      // Provides
  267. };
  268.  
  269. struct pkgCache::StringItem
  270. {
  271.    __apt_ptrloc String;        // Stringtable
  272.    __apt_ptrloc NextItem;      // StringItem
  273. };
  274.  
  275. #include <apt-pkg/cacheiterators.h>
  276.  
  277. inline pkgCache::PkgIterator pkgCache::PkgBegin() 
  278.        {return PkgIterator(*this);};
  279. inline pkgCache::PkgIterator pkgCache::PkgEnd() 
  280.        {return PkgIterator(*this,PkgP);};
  281. inline pkgCache::PkgFileIterator pkgCache::FileBegin()
  282.        {return PkgFileIterator(*this);};
  283. inline pkgCache::PkgFileIterator pkgCache::FileEnd()
  284.        {return PkgFileIterator(*this,PkgFileP);};
  285.  
  286. #endif
  287.