Fixed or handling bug
[ntk/apt.git] / apt-pkg / orderlist.h
CommitLineData
6c139d6e
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
63d3141a 3// $Id: orderlist.h,v 1.8 2000/01/16 08:45:47 jgg Exp $
6c139d6e
AL
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__
094a497d 21#pragma interface "apt-pkg/orderlist.h"
6c139d6e
AL
22#endif
23
094a497d 24#include <apt-pkg/pkgcache.h>
6c139d6e
AL
25
26class pkgDepCache;
27class 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;
63d3141a
AL
51 Package **AfterList;
52 Package **AfterEnd;
281daf46 53 string *FileList;
6c139d6e
AL
54 DepIterator Loops[20];
55 int LoopCount;
56 int Depth;
63d3141a 57 unsigned short *Flags;
6c139d6e
AL
58
59 // Main visit function
60 bool VisitNode(PkgIterator Pkg);
61 bool VisitDeps(DepFunc F,PkgIterator Pkg);
62 bool VisitRDeps(DepFunc F,PkgIterator Pkg);
63 bool VisitRProvides(DepFunc F,VerIterator Ver);
3fb5f4e4 64 bool VisitProvides(DepIterator Pkg,bool Critical);
6c139d6e
AL
65
66 // Dependency checking functions.
67 bool DepUnPackCrit(DepIterator D);
68 bool DepUnPackPreD(DepIterator D);
69 bool DepUnPackPre(DepIterator D);
70 bool DepUnPackDep(DepIterator D);
71 bool DepConfigure(DepIterator D);
72 bool DepRemove(DepIterator D);
73
74 // Analysis helpers
75 bool AddLoop(DepIterator D);
76 bool CheckDep(DepIterator D);
77 bool DoRun();
78
79 // For pre sorting
80 static pkgOrderList *Me;
81 static int OrderCompareA(const void *a, const void *b);
82 static int OrderCompareB(const void *a, const void *b);
83 int FileCmp(PkgIterator A,PkgIterator B);
84
85 public:
86
87 typedef Package **iterator;
88
89 // State flags
90 enum Flags {Added = (1 << 0), AddPending = (1 << 1),
91 Immediate = (1 << 2), Loop = (1 << 3),
92 UnPacked = (1 << 4), Configured = (1 << 5),
9d4c8f67 93 Removed = (1 << 6), // Early Remove
6c139d6e 94 InList = (1 << 7),
63d3141a 95 After = (1 << 8),
6c139d6e
AL
96 States = (UnPacked | Configured | Removed)};
97
98 // Flag manipulators
99 inline bool IsFlag(PkgIterator Pkg,unsigned long F) {return (Flags[Pkg->ID] & F) == F;};
100 inline bool IsFlag(Package *Pkg,unsigned long F) {return (Flags[Pkg->ID] & F) == F;};
101 void Flag(PkgIterator Pkg,unsigned long State, unsigned long F) {Flags[Pkg->ID] = (Flags[Pkg->ID] & (~F)) | State;};
102 inline void Flag(PkgIterator Pkg,unsigned long F) {Flags[Pkg->ID] |= F;};
103 inline void Flag(Package *Pkg,unsigned long F) {Flags[Pkg->ID] |= F;};
9d4c8f67 104 inline bool IsNow(PkgIterator Pkg) {return (Flags[Pkg->ID] & (States & (~Removed))) == 0;};
2fd65468 105 bool IsMissing(PkgIterator Pkg);
6c139d6e 106 void WipeFlags(unsigned long F);
2fd65468 107 void SetFileList(string *FileList) {this->FileList = FileList;};
bdae53f1 108
6c139d6e
AL
109 // Accessors
110 inline iterator begin() {return List;};
111 inline iterator end() {return End;};
112 inline void push_back(Package *Pkg) {*(End++) = Pkg;};
113 inline void push_back(PkgIterator Pkg) {*(End++) = Pkg;};
114 inline void pop_back() {End--;};
115 inline bool empty() {return End == List;};
116 inline unsigned int size() {return End - List;};
117
118 // Ordering modes
119 bool OrderCritical();
281daf46 120 bool OrderUnpack(string *FileList = 0);
6c139d6e
AL
121 bool OrderConfigure();
122
123 int Score(PkgIterator Pkg);
124
125 pkgOrderList(pkgDepCache &Cache);
126 ~pkgOrderList();
127};
128
129#endif