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 class pkgPolicy : public pkgDepCache::Policy
00042 {
00043    protected:
00044 
00045    struct Pin
00046    {
00047       pkgVersionMatch::MatchType Type;
00048       std::string Data;
00049       signed short Priority;
00050       Pin() : Type(pkgVersionMatch::None), Priority(0) {};
00051    };
00052 
00053    struct PkgPin : Pin
00054    {
00055       std::string Pkg;
00056       PkgPin(std::string const &Pkg) : Pin(), Pkg(Pkg) {};
00057    };
00058    
00059    Pin *Pins;
00060    signed short *PFPriority;
00061    std::vector<Pin> Defaults;
00062    std::vector<PkgPin> Unmatched;
00063    pkgCache *Cache;
00064    bool StatusOverride;
00065    
00066    public:
00067 
00068    // Things for manipulating pins
00069    void CreatePin(pkgVersionMatch::MatchType Type,std::string Pkg,
00070                   std::string Data,signed short Priority);
00071    pkgCache::VerIterator GetMatch(pkgCache::PkgIterator const &Pkg);
00072 
00073    // Things for the cache interface.
00074    virtual pkgCache::VerIterator GetCandidateVer(pkgCache::PkgIterator const &Pkg);
00075    virtual signed short GetPriority(pkgCache::PkgIterator const &Pkg);
00076    virtual signed short GetPriority(pkgCache::PkgFileIterator const &File);
00077 
00078    bool InitDefaults();
00079    
00080    pkgPolicy(pkgCache *Owner);
00081    virtual ~pkgPolicy() {delete [] PFPriority; delete [] Pins;};
00082 };
00083 
00084 bool ReadPinFile(pkgPolicy &Plcy, std::string File = "");
00085 bool ReadPinDir(pkgPolicy &Plcy, std::string Dir = "");
00086 
00087 #endif