]> git.saurik.com Git - apt.git/blob - apt-pkg/policy.h
c4b1cbaddf3caa285e6a58c2e2774f26423be2e9
[apt.git] / apt-pkg / policy.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 /* ######################################################################
4
5 Package Version Policy implementation
6
7 This implements the more advanced 'Version 4' APT policy engine. The
8 standard 'Version 0' engine is included inside the DepCache which is
9 it's historical location.
10
11 The V4 engine allows the user to completly control all aspects of
12 version selection. There are three primary means to choose a version
13 * Selection by version match
14 * Selection by Release file match
15 * Selection by origin server
16
17 Each package may be 'pinned' with a single criteria, which will ultimately
18 result in the selection of a single version, or no version, for each
19 package.
20
21 Furthermore, the default selection can be influenced by specifying
22 the ordering of package files. The order is derived by reading the
23 package file preferences and assigning a priority to each package
24 file.
25
26 A special flag may be set to indicate if no version should be returned
27 if no matching versions are found, otherwise the default matching
28 rules are used to locate a hit.
29
30 ##################################################################### */
31 /*}}}*/
32 #ifndef PKGLIB_POLICY_H
33 #define PKGLIB_POLICY_H
34
35 #include <apt-pkg/depcache.h>
36 #include <apt-pkg/pkgcache.h>
37 #include <apt-pkg/cacheiterators.h>
38 #include <apt-pkg/versionmatch.h>
39
40 #include <vector>
41 #include <string>
42
43 #ifndef APT_8_CLEANER_HEADERS
44 using std::vector;
45 #endif
46
47 class pkgPolicy : public pkgDepCache::Policy
48 {
49 protected:
50
51 struct Pin
52 {
53 pkgVersionMatch::MatchType Type;
54 std::string Data;
55 signed short Priority;
56 Pin() : Type(pkgVersionMatch::None), Priority(0) {};
57 };
58
59 struct PkgPin : Pin
60 {
61 std::string Pkg;
62 PkgPin(std::string const &Pkg) : Pin(), Pkg(Pkg) {};
63 };
64
65 Pin *Pins;
66 signed short *PFPriority;
67 std::vector<Pin> Defaults;
68 std::vector<PkgPin> Unmatched;
69 pkgCache *Cache;
70 bool StatusOverride;
71
72 public:
73
74 // Things for manipulating pins
75 void CreatePin(pkgVersionMatch::MatchType Type,std::string Pkg,
76 std::string Data,signed short Priority);
77 pkgCache::VerIterator GetMatch(pkgCache::PkgIterator const &Pkg);
78
79 // Things for the cache interface.
80 virtual pkgCache::VerIterator GetCandidateVer(pkgCache::PkgIterator const &Pkg);
81 virtual signed short GetPriority(pkgCache::PkgIterator const &Pkg);
82 virtual signed short GetPriority(pkgCache::PkgFileIterator const &File);
83
84 bool InitDefaults();
85
86 pkgPolicy(pkgCache *Owner);
87 virtual ~pkgPolicy();
88 private:
89 void *d;
90 };
91
92 bool ReadPinFile(pkgPolicy &Plcy, std::string File = "");
93 bool ReadPinDir(pkgPolicy &Plcy, std::string Dir = "");
94
95 #endif