]> git.saurik.com Git - apt.git/blame - apt-pkg/orderlist.h
Merge commit 'e2073b0276226b625897ef475f225bf8f508719e' as 'triehash'
[apt.git] / apt-pkg / orderlist.h
CommitLineData
6c139d6e
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
6c139d6e
AL
3/* ######################################################################
4
5 Order List - Represents and Manipulates an ordered list of packages.
6
7 A list of packages can be ordered by a number of conflicting criteria
8 each given a specific priority. Each package also has a set of flags
b2e465d6 9 indicating some useful things about it that are derived in the
6c139d6e
AL
10 course of sorting. The pkgPackageManager class uses this class for
11 all of it's installation ordering needs.
12
13 ##################################################################### */
14 /*}}}*/
6c139d6e
AL
15#ifndef PKGLIB_ORDERLIST_H
16#define PKGLIB_ORDERLIST_H
17
094a497d 18#include <apt-pkg/pkgcache.h>
453b82a3 19#include <apt-pkg/cacheiterators.h>
3b8d1773 20#include <apt-pkg/macros.h>
6c139d6e 21
453b82a3
DK
22#include <string>
23
6c139d6e 24class pkgDepCache;
b2e465d6 25class pkgOrderList : protected pkgCache::Namespace
6c139d6e 26{
6c55f07a 27 void * const d;
6c139d6e
AL
28 protected:
29
b2e465d6 30 pkgDepCache &Cache;
6c139d6e
AL
31 typedef bool (pkgOrderList::*DepFunc)(DepIterator D);
32
33 // These are the currently selected ordering functions
34 DepFunc Primary;
35 DepFunc Secondary;
36 DepFunc RevDepends;
37 DepFunc Remove;
38
39 // State
40 Package **End;
41 Package **List;
63d3141a 42 Package **AfterEnd;
8f3ba4e8 43 std::string *FileList;
6c139d6e
AL
44 DepIterator Loops[20];
45 int LoopCount;
46 int Depth;
63d3141a 47 unsigned short *Flags;
b2e465d6 48 bool Debug;
6c139d6e
AL
49
50 // Main visit function
5dd00edb 51 APT_DEPRECATED_MSG("Add a unique calling identifier as parameter for debugging output") bool VisitNode(PkgIterator Pkg) { return VisitNode(Pkg, "UNKNOWN"); };
3b8d1773 52 bool VisitNode(PkgIterator Pkg, char const* from);
6c139d6e
AL
53 bool VisitDeps(DepFunc F,PkgIterator Pkg);
54 bool VisitRDeps(DepFunc F,PkgIterator Pkg);
55 bool VisitRProvides(DepFunc F,VerIterator Ver);
3fb5f4e4 56 bool VisitProvides(DepIterator Pkg,bool Critical);
6c139d6e
AL
57
58 // Dependency checking functions.
59 bool DepUnPackCrit(DepIterator D);
60 bool DepUnPackPreD(DepIterator D);
61 bool DepUnPackPre(DepIterator D);
62 bool DepUnPackDep(DepIterator D);
63 bool DepConfigure(DepIterator D);
64 bool DepRemove(DepIterator D);
65
66 // Analysis helpers
67 bool AddLoop(DepIterator D);
68 bool CheckDep(DepIterator D);
69 bool DoRun();
70
71 // For pre sorting
7d70f799
JAK
72 int OrderCompareA(Package *a, Package *b) APT_PURE;
73 int OrderCompareB(Package *a, Package *b) APT_PURE;
a02db58f 74 int FileCmp(PkgIterator A,PkgIterator B) APT_PURE;
6c139d6e
AL
75
76 public:
77
78 typedef Package **iterator;
79
e7ecc218
CB
80 /* State flags
81 The Loop flag can be set on a package that is currently being processed by either SmartConfigure or
82 SmartUnPack. This allows the package manager to tell when a loop has been formed as it will try to
83 SmartUnPack or SmartConfigure a package with the Loop flag set. It will then either stop (as it knows
84 that the operation is unnecessary as its already in process), or in the case of the conflicts resolution
85 in SmartUnPack, use EarlyRemove to resolve the situation. */
6c139d6e
AL
86 enum Flags {Added = (1 << 0), AddPending = (1 << 1),
87 Immediate = (1 << 2), Loop = (1 << 3),
88 UnPacked = (1 << 4), Configured = (1 << 5),
9d4c8f67 89 Removed = (1 << 6), // Early Remove
6c139d6e 90 InList = (1 << 7),
63d3141a 91 After = (1 << 8),
6c139d6e
AL
92 States = (UnPacked | Configured | Removed)};
93
94 // Flag manipulators
95 inline bool IsFlag(PkgIterator Pkg,unsigned long F) {return (Flags[Pkg->ID] & F) == F;};
96 inline bool IsFlag(Package *Pkg,unsigned long F) {return (Flags[Pkg->ID] & F) == F;};
97 void Flag(PkgIterator Pkg,unsigned long State, unsigned long F) {Flags[Pkg->ID] = (Flags[Pkg->ID] & (~F)) | State;};
98 inline void Flag(PkgIterator Pkg,unsigned long F) {Flags[Pkg->ID] |= F;};
99 inline void Flag(Package *Pkg,unsigned long F) {Flags[Pkg->ID] |= F;};
cbea0578
CB
100 // RmFlag removes a flag from a package
101 inline void RmFlag(Package *Pkg,unsigned long F) {Flags[Pkg->ID] &= ~F;};
e7ecc218 102 // IsNow will return true if the Pkg has been not been either configured or unpacked
9d4c8f67 103 inline bool IsNow(PkgIterator Pkg) {return (Flags[Pkg->ID] & (States & (~Removed))) == 0;};
a02db58f 104 bool IsMissing(PkgIterator Pkg) APT_PURE;
6c139d6e 105 void WipeFlags(unsigned long F);
8f3ba4e8 106 void SetFileList(std::string *FileList) {this->FileList = FileList;};
bdae53f1 107
6c139d6e
AL
108 // Accessors
109 inline iterator begin() {return List;};
110 inline iterator end() {return End;};
111 inline void push_back(Package *Pkg) {*(End++) = Pkg;};
112 inline void push_back(PkgIterator Pkg) {*(End++) = Pkg;};
113 inline void pop_back() {End--;};
114 inline bool empty() {return End == List;};
115 inline unsigned int size() {return End - List;};
116
117 // Ordering modes
118 bool OrderCritical();
8f3ba4e8 119 bool OrderUnpack(std::string *FileList = 0);
6c139d6e
AL
120 bool OrderConfigure();
121
122 int Score(PkgIterator Pkg);
123
e8afd168 124 explicit pkgOrderList(pkgDepCache *Cache);
c8a4ce6c 125 virtual ~pkgOrderList();
6c139d6e
AL
126};
127
128#endif