]> git.saurik.com Git - apt.git/blame_incremental - apt-pkg/depcache.h
Fixed some typos and outofdateness
[apt.git] / apt-pkg / depcache.h
... / ...
CommitLineData
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3// $Id: depcache.h,v 1.2 1998/07/12 01:26:01 jgg Exp $
4/* ######################################################################
5
6 DepCache - Dependency Extension data for the cache
7
8 This class stores the cache data and a set of extension structures for
9 monitoring the current state of all the packages. It also generates and
10 caches the 'install' state of many things. This refers to the state of the
11 package after an install has been run.
12
13 The StateCache::State field can be -1,0,1,2 which is <,=,>,no current.
14 StateCache::Mode is which of the 3 fields is active.
15
16 This structure is important to support the readonly status of the cache
17 file. When the data is saved the cache will be refereshed from our
18 internal rep and written to disk. Then the actual persistant data
19 files will be put on the disk.
20
21 Each dependency is compared against 3 target versions to produce to
22 3 dependency results.
23 Now - Compared using the Currently install version
24 Install - Compared using the install version (final state)
25 CVer - (Candidate Verion) Compared using the Candidate Version
26 The candidate and now results are used to decide wheather a package
27 should be automatically installed or if it should be left alone.
28
29 Remember, the Candidate Version is selected based on the distribution
30 settings for the Package. The Install Version is selected based on the
31 state (Delete, Keep, Install) field and can be either the Current Version
32 or the Candidate version.
33
34 The Candidate version is what is shown the 'Install Version' field.
35
36 ##################################################################### */
37 /*}}}*/
38// Header section: pkglib
39#ifndef PKGLIB_DEPCACHE_H
40#define PKGLIB_DEPCACHE_H
41
42#ifdef __GNUG__
43#pragma interface "pkglib/depcache.h"
44#endif
45
46#include <pkglib/pkgcache.h>
47
48class pkgDepCache : public pkgCache
49{
50 public:
51
52 // These flags are used in DepState
53 enum DepFlags {DepNow = (1 << 0),DepInstall = (1 << 1),DepCVer = (1 << 2),
54 DepGNow = (1 << 3),DepGInstall = (1 << 4),DepGCVer = (1 << 5)};
55
56 // These flags are used in StateCache::DepState
57 enum DepStateFlags {DepNowPolicy = (1 << 0), DepNowMin = (1 << 1),
58 DepInstPolicy = (1 << 2), DepInstMin = (1 << 3),
59 DepCandPolicy = (1 << 4), DepCandMin = (1 << 5)};
60
61 // These flags are used in StateCache::iFlags
62 enum InternalFlags {AutoKept = (1 << 0)};
63
64 enum VersionTypes {NowVersion, InstallVersion, CandidateVersion};
65 enum ModeList {ModeDelete = 0, ModeKeep = 1, ModeInstall = 2};
66 struct StateCache
67 {
68 // Epoch stripped text versions of the two version fields
69 const char *CandVersion;
70 const char *CurVersion;
71
72 // Pointer to the candidate install version.
73 Version *CandidateVer;
74
75 // Pointer to the install version.
76 Version *InstallVer;
77
78 // Various tree indicators
79 signed char Status; // -1,0,1,2
80 unsigned char Mode; // ModeList
81 unsigned char DepState; // DepState Flags
82
83 // Copy of Package::Flags
84 unsigned short Flags;
85 unsigned short iFlags; // Internal flags
86
87 // Update of candidate version
88 const char *StripEpoch(const char *Ver);
89 void Update(PkgIterator Pkg,pkgCache &Cache);
90
91 // Various test members for the current status of the package
92 inline bool NewInstall() const {return Status == 2 && Mode == ModeInstall;};
93 inline bool Delete() const {return Mode == ModeDelete;};
94 inline bool Keep() const {return Mode == ModeKeep;};
95 inline bool Upgrade() const {return Status > 0 && Mode == ModeInstall;};
96 inline bool Upgradable() const {return Status == 1;};
97 inline bool Downgrade() const {return Status < 0;};
98 inline bool Held() const {return Status != 0 && Keep();};
99 inline bool NowBroken() const {return (DepState & DepNowMin) != DepNowMin;};
100 inline bool InstBroken() const {return (DepState & DepInstMin) != DepInstMin;};
101 inline bool Install() const {return Mode == ModeInstall;};
102 inline VerIterator InstVerIter(pkgCache &Cache)
103 {return VerIterator(Cache,InstallVer);};
104 inline VerIterator CandidateVerIter(pkgCache &Cache)
105 {return VerIterator(Cache,CandidateVer);};
106 };
107
108 // Helper functions
109 void BuildGroupOrs(VerIterator const &V);
110 void UpdateVerState(PkgIterator Pkg);
111
112 bool Init();
113
114 protected:
115
116 // State information
117 StateCache *PkgState;
118 unsigned char *DepState;
119
120 long iUsrSize;
121 long iDownloadSize;
122 long iInstCount;
123 long iDelCount;
124 long iKeepCount;
125 long iBrokenCount;
126 long iBadCount;
127
128 // Check for a matching provides
129 bool CheckDep(DepIterator Dep,int Type,PkgIterator &Res);
130 inline bool CheckDep(DepIterator Dep,int Type)
131 {
132 PkgIterator Res(*this);
133 return CheckDep(Dep,Type,Res);
134 }
135
136 // Computes state information for deps and versions (w/o storing)
137 unsigned char DependencyState(DepIterator &D);
138 unsigned char VersionState(DepIterator D,unsigned char Check,
139 unsigned char SetMin,
140 unsigned char SetPolicy);
141
142 // Recalculates various portions of the cache, call after changing something
143 void Update(DepIterator Dep); // Mostly internal
144 void Update(PkgIterator const &P);
145
146 // Count manipulators
147 void AddSizes(const PkgIterator &Pkg,long Mult = 1);
148 inline void RemoveSizes(const PkgIterator &Pkg) {AddSizes(Pkg,-1);};
149 void AddStates(const PkgIterator &Pkg,int Add = 1);
150 inline void RemoveStates(const PkgIterator &Pkg) {AddStates(Pkg,-1);};
151
152 public:
153
154 // Policy implementation
155 virtual VerIterator GetCandidateVer(PkgIterator Pkg);
156 virtual bool IsImportantDep(DepIterator Dep);
157
158 // Accessors
159 inline StateCache &operator [](PkgIterator const &I) {return PkgState[I->ID];};
160 inline unsigned char &operator [](DepIterator const &I) {return DepState[I->ID];};
161
162 // Manipulators
163 void MarkKeep(PkgIterator const &Pkg,bool Soft = false);
164 void MarkDelete(PkgIterator const &Pkg);
165 void MarkInstall(PkgIterator const &Pkg,bool AutoInst = true);
166
167 // This is for debuging
168 void Update();
169
170 // Hook to keep the extra data in sync
171 virtual bool ReMap();
172
173 // Size queries
174 inline long UsrSize() {return iUsrSize;};
175 inline long DebSize() {return iDownloadSize;};
176 inline long DelCount() {return iDelCount;};
177 inline long KeepCount() {return iKeepCount;};
178 inline long InstCount() {return iInstCount;};
179 inline long BrokenCount() {return iBrokenCount;};
180 inline long BadCount() {return iBadCount;};
181
182 pkgDepCache(MMap &Map);
183 virtual ~pkgDepCache();
184};
185
186#endif