apt @VERSION@

policy.h

00001 // -*- mode: cpp; mode: fold -*-
00002 // Description                                                          /*{{{*/
00003 // $Id: policy.h,v 1.4 2001/05/07 04:24:08 jgg Exp $
00004 /* ######################################################################
00005 
00006    Package Version Policy implementation
00007 
00008    This implements the more advanced 'Version 4' APT policy engine. The
00009    standard 'Version 0' engine is included inside the DepCache which is
00010    it's historical location.
00011    
00012    The V4 engine allows the user to completly control all aspects of
00013    version selection. There are three primary means to choose a version
00014     * Selection by version match
00015     * Selection by Release file match
00016     * Selection by origin server
00017    
00018    Each package may be 'pinned' with a single criteria, which will ultimately
00019    result in the selection of a single version, or no version, for each
00020    package.
00021    
00022    Furthermore, the default selection can be influenced by specifying
00023    the ordering of package files. The order is derived by reading the
00024    package file preferences and assigning a priority to each package 
00025    file.
00026    
00027    A special flag may be set to indicate if no version should be returned
00028    if no matching versions are found, otherwise the default matching
00029    rules are used to locate a hit.
00030    
00031    ##################################################################### */
00032                                                                         /*}}}*/
00033 #ifndef PKGLIB_POLICY_H
00034 #define PKGLIB_POLICY_H
00035 
00036 
00037 #include <apt-pkg/depcache.h>
00038 #include <apt-pkg/versionmatch.h>
00039 #include <vector>
00040 
00041 using std::vector;
00042 
00043 class pkgPolicy : public pkgDepCache::Policy
00044 {
00045    protected:
00046 
00047    struct Pin
00048    {
00049       pkgVersionMatch::MatchType Type;
00050       string Data;
00051       signed short Priority;
00052       Pin() : Type(pkgVersionMatch::None), Priority(0) {};
00053    };
00054 
00055    struct PkgPin : Pin
00056    {
00057       string Pkg;
00058    };
00059    
00060    Pin *Pins;
00061    signed short *PFPriority;
00062    vector<Pin> Defaults;
00063    vector<PkgPin> Unmatched;
00064    pkgCache *Cache;
00065    bool StatusOverride;
00066    
00067    public:
00068 
00069    // Things for manipulating pins
00070    void CreatePin(pkgVersionMatch::MatchType Type,string Pkg,
00071                   string Data,signed short Priority);
00072    inline signed short GetPriority(pkgCache::PkgFileIterator const &File) 
00073        {return PFPriority[File->ID];};
00074    signed short GetPriority(pkgCache::PkgIterator const &Pkg);
00075    pkgCache::VerIterator GetMatch(pkgCache::PkgIterator const &Pkg);
00076 
00077    // Things for the cache interface.
00078    virtual pkgCache::VerIterator GetCandidateVer(pkgCache::PkgIterator const &Pkg);
00079    virtual bool IsImportantDep(pkgCache::DepIterator const &Dep) {return pkgDepCache::Policy::IsImportantDep(Dep);};
00080    bool InitDefaults();
00081    
00082    pkgPolicy(pkgCache *Owner);
00083    virtual ~pkgPolicy() {delete [] PFPriority; delete [] Pins;};
00084 };
00085 
00086 bool ReadPinFile(pkgPolicy &Plcy,string File = "");
00087 bool ReadPinDir(pkgPolicy &Plcy,string Dir = "");
00088 
00089 #endif