]> git.saurik.com Git - apt.git/blob - apt-pkg/orderlist.h
g++- works
[apt.git] / apt-pkg / orderlist.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: orderlist.h,v 1.4 1999/07/04 23:22:53 jgg Exp $
4 /* ######################################################################
5
6 Order List - Represents and Manipulates an ordered list of packages.
7
8 A list of packages can be ordered by a number of conflicting criteria
9 each given a specific priority. Each package also has a set of flags
10 indicating some usefull things about it that are derived in the
11 course of sorting. The pkgPackageManager class uses this class for
12 all of it's installation ordering needs.
13
14 ##################################################################### */
15 /*}}}*/
16 // Header section: pkglib
17 #ifndef PKGLIB_ORDERLIST_H
18 #define PKGLIB_ORDERLIST_H
19
20 #ifdef __GNUG__
21 #pragma interface "apt-pkg/orderlist.h"
22 #endif
23
24 #include <apt-pkg/pkgcache.h>
25
26 class pkgDepCache;
27 class pkgOrderList
28 {
29 protected:
30
31 pkgDepCache &Cache;
32
33 // Bring some usefull types into the local scope
34 typedef pkgCache::PkgIterator PkgIterator;
35 typedef pkgCache::VerIterator VerIterator;
36 typedef pkgCache::DepIterator DepIterator;
37 typedef pkgCache::PrvIterator PrvIterator;
38 typedef pkgCache::Package Package;
39 typedef pkgCache::Version Version;
40 typedef bool (pkgOrderList::*DepFunc)(DepIterator D);
41
42 // These are the currently selected ordering functions
43 DepFunc Primary;
44 DepFunc Secondary;
45 DepFunc RevDepends;
46 DepFunc Remove;
47
48 // State
49 Package **End;
50 Package **List;
51 string *FileList;
52 DepIterator Loops[20];
53 int LoopCount;
54 int Depth;
55 unsigned char *Flags;
56
57 // Main visit function
58 bool VisitNode(PkgIterator Pkg);
59 bool VisitDeps(DepFunc F,PkgIterator Pkg);
60 bool VisitRDeps(DepFunc F,PkgIterator Pkg);
61 bool VisitRProvides(DepFunc F,VerIterator Ver);
62 bool VisitProvides(DepIterator Pkg);
63
64 // Dependency checking functions.
65 bool DepUnPackCrit(DepIterator D);
66 bool DepUnPackPreD(DepIterator D);
67 bool DepUnPackPre(DepIterator D);
68 bool DepUnPackDep(DepIterator D);
69 bool DepConfigure(DepIterator D);
70 bool DepRemove(DepIterator D);
71
72 // Analysis helpers
73 bool AddLoop(DepIterator D);
74 bool CheckDep(DepIterator D);
75 bool DoRun();
76
77 // For pre sorting
78 static pkgOrderList *Me;
79 static int OrderCompareA(const void *a, const void *b);
80 static int OrderCompareB(const void *a, const void *b);
81 int FileCmp(PkgIterator A,PkgIterator B);
82
83 public:
84
85 typedef Package **iterator;
86
87 // State flags
88 enum Flags {Added = (1 << 0), AddPending = (1 << 1),
89 Immediate = (1 << 2), Loop = (1 << 3),
90 UnPacked = (1 << 4), Configured = (1 << 5),
91 Removed = (1 << 6),
92 InList = (1 << 7),
93 States = (UnPacked | Configured | Removed)};
94
95 // Flag manipulators
96 inline bool IsFlag(PkgIterator Pkg,unsigned long F) {return (Flags[Pkg->ID] & F) == F;};
97 inline bool IsFlag(Package *Pkg,unsigned long F) {return (Flags[Pkg->ID] & F) == F;};
98 void Flag(PkgIterator Pkg,unsigned long State, unsigned long F) {Flags[Pkg->ID] = (Flags[Pkg->ID] & (~F)) | State;};
99 inline void Flag(PkgIterator Pkg,unsigned long F) {Flags[Pkg->ID] |= F;};
100 inline void Flag(Package *Pkg,unsigned long F) {Flags[Pkg->ID] |= F;};
101 inline bool IsNow(PkgIterator Pkg) {return (Flags[Pkg->ID] & States) == 0;};
102 bool IsMissing(PkgIterator Pkg);
103 void WipeFlags(unsigned long F);
104 void SetFileList(string *FileList) {this->FileList = FileList;};
105
106 // Accessors
107 inline iterator begin() {return List;};
108 inline iterator end() {return End;};
109 inline void push_back(Package *Pkg) {*(End++) = Pkg;};
110 inline void push_back(PkgIterator Pkg) {*(End++) = Pkg;};
111 inline void pop_back() {End--;};
112 inline bool empty() {return End == List;};
113 inline unsigned int size() {return End - List;};
114
115 // Ordering modes
116 bool OrderCritical();
117 bool OrderUnpack(string *FileList = 0);
118 bool OrderConfigure();
119
120 int Score(PkgIterator Pkg);
121
122 pkgOrderList(pkgDepCache &Cache);
123 ~pkgOrderList();
124 };
125
126 #endif