]> git.saurik.com Git - apt.git/blame - apt-pkg/cacheiterators.h
performance tuning
[apt.git] / apt-pkg / cacheiterators.h
CommitLineData
578bfd0a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
f9eec0e7 3// $Id: cacheiterators.h,v 1.13 1999/02/23 06:46:24 jgg Exp $
578bfd0a
AL
4/* ######################################################################
5
6 Cache Iterators - Iterators for navigating the cache structure
7
8 The iterators all provides ++,==,!=,->,* and end for their type.
9 The end function can be used to tell if the list has been fully
10 traversed.
11
12 Unlike STL iterators these contain helper functions to access the data
13 that is being iterated over. This is because the data structures can't
14 be formed in a manner that is intuitive to use and also mmapable.
15
16 For each variable in the target structure that would need a translation
17 to be accessed correctly a translating function of the same name is
18 present in the iterator. If applicable the translating function will
19 return an iterator.
20
21 The DepIterator can iterate over two lists, a list of 'version depends'
22 or a list of 'package reverse depends'. The type is determined by the
23 structure passed to the constructor, which should be the structure
6c139d6e
AL
24 that has the depends pointer as a member. The provide iterator has the
25 same system.
578bfd0a 26
094a497d 27 This header is not user includable, please use apt-pkg/pkgcache.h
578bfd0a
AL
28
29 ##################################################################### */
30 /*}}}*/
31// Header section: pkglib
32#ifndef PKGLIB_CACHEITERATORS_H
33#define PKGLIB_CACHEITERATORS_H
34
6c139d6e 35#ifdef __GNUG__
094a497d 36#pragma interface "apt-pkg/cacheiterators.h"
6c139d6e
AL
37#endif
38
578bfd0a
AL
39// Package Iterator
40class pkgCache::PkgIterator
41{
42 Package *Pkg;
43 pkgCache *Owner;
44 long HashIndex;
45
46 public:
47
48 enum OkState {NeedsNothing,NeedsUnpack,NeedsConfigure};
49
50 // Iteration
51 void operator ++(int);
52 inline void operator ++() {operator ++(0);};
53 inline bool end() const {return Owner == 0 || Pkg == Owner->PkgP?true:false;};
54
55 // Comparison
56 inline bool operator ==(const PkgIterator &B) const {return Pkg == B.Pkg;};
57 inline bool operator !=(const PkgIterator &B) const {return Pkg != B.Pkg;};
58
59 // Accessors
60 inline Package *operator ->() {return Pkg;};
61 inline Package const *operator ->() const {return Pkg;};
62 inline Package const &operator *() const {return *Pkg;};
63 inline operator Package *() {return Pkg == Owner->PkgP?0:Pkg;};
64 inline operator Package const *() const {return Pkg == Owner->PkgP?0:Pkg;};
6c139d6e 65
578bfd0a
AL
66 inline const char *Name() const {return Pkg->Name == 0?0:Owner->StrP + Pkg->Name;};
67 inline const char *Section() const {return Pkg->Section == 0?0:Owner->StrP + Pkg->Section;};
68 inline const char *TargetDist() const {return Pkg->TargetDist == 0?0:Owner->StrP + Pkg->TargetDist;};
69 inline VerIterator VersionList() const;
70 inline VerIterator TargetVer() const;
71 inline VerIterator CurrentVer() const;
72 inline DepIterator RevDependsList() const;
73 inline PrvIterator ProvidesList() const;
f55a958f 74 inline unsigned long Index() const {return Pkg - Owner->PkgP;};
578bfd0a
AL
75 OkState State() const;
76
77 // Constructors
78 inline PkgIterator(pkgCache &Owner) : Owner(&Owner), HashIndex(-1)
79 {
80 Pkg = Owner.PkgP;
81 operator ++(0);
82 };
83 inline PkgIterator(pkgCache &Owner,Package *Trg) : Pkg(Trg), Owner(&Owner),
84 HashIndex(0)
85 {
86 if (Pkg == 0)
87 Pkg = Owner.PkgP;
88 };
89 inline PkgIterator() : Pkg(0), Owner(0), HashIndex(0) {};
90};
91
92// Version Iterator
93class pkgCache::VerIterator
94{
95 Version *Ver;
f9eec0e7 96 pkgCache *Owner;
578bfd0a
AL
97
98 void _dummy();
99
100 public:
101
102 // Iteration
f9eec0e7 103 void operator ++(int) {if (Ver != Owner->VerP) Ver = Owner->VerP + Ver->NextVer;};
578bfd0a 104 inline void operator ++() {operator ++(0);};
f9eec0e7
AL
105 inline bool end() const {return Ver == Owner->VerP?true:false;};
106 inline void operator =(const VerIterator &B) {Ver = B.Ver; Owner = B.Owner;};
578bfd0a
AL
107
108 // Comparison
109 inline bool operator ==(const VerIterator &B) const {return Ver == B.Ver;};
110 inline bool operator !=(const VerIterator &B) const {return Ver != B.Ver;};
111 int CompareVer(const VerIterator &B) const;
112
113 // Accessors
114 inline Version *operator ->() {return Ver;};
115 inline Version const *operator ->() const {return Ver;};
116 inline Version &operator *() {return *Ver;};
117 inline Version const &operator *() const {return *Ver;};
f9eec0e7
AL
118 inline operator Version *() {return Ver == Owner->VerP?0:Ver;};
119 inline operator Version const *() const {return Ver == Owner->VerP?0:Ver;};
c9807169 120
f9eec0e7
AL
121 inline const char *VerStr() const {return Ver->VerStr == 0?0:Owner->StrP + Ver->VerStr;};
122 inline const char *Section() const {return Ver->Section == 0?0:Owner->StrP + Ver->Section;};
123 inline const char *Arch() const {return Ver->Arch == 0?0:Owner->StrP + Ver->Arch;};
124 inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + Ver->ParentPkg);};
578bfd0a
AL
125 inline DepIterator DependsList() const;
126 inline PrvIterator ProvidesList() const;
dcb79bae 127 inline VerFileIterator FileList() const;
f9eec0e7 128 inline unsigned long Index() const {return Ver - Owner->VerP;};
b518cca6 129 bool Downloadable() const;
c9807169 130 const char *PriorityType();
3c124dde
AL
131
132 bool Automatic() const;
133 VerFileIterator NewestFile() const;
f9eec0e7
AL
134
135 inline VerIterator() : Ver(0), Owner(0) {};
136 inline VerIterator(pkgCache &Owner,Version *Trg = 0) : Ver(Trg),
137 Owner(&Owner)
578bfd0a
AL
138 {
139 if (Ver == 0)
140 Ver = Owner.VerP;
141 };
142};
143
144// Dependency iterator
145class pkgCache::DepIterator
146{
147 Dependency *Dep;
148 enum {DepVer, DepRev} Type;
149 pkgCache *Owner;
150
151 void _dummy();
152
153 public:
154
155 // Iteration
156 void operator ++(int) {if (Dep != Owner->DepP) Dep = Owner->DepP +
157 (Type == DepVer?Dep->NextDepends:Dep->NextRevDepends);};
158 inline void operator ++() {operator ++(0);};
159 inline bool end() const {return Owner == 0 || Dep == Owner->DepP?true:false;};
160
161 // Comparison
162 inline bool operator ==(const DepIterator &B) const {return Dep == B.Dep;};
163 inline bool operator !=(const DepIterator &B) const {return Dep != B.Dep;};
164
165 // Accessors
166 inline Dependency *operator ->() {return Dep;};
167 inline Dependency const *operator ->() const {return Dep;};
168 inline Dependency &operator *() {return *Dep;};
169 inline Dependency const &operator *() const {return *Dep;};
170 inline operator Dependency *() {return Dep == Owner->DepP?0:Dep;};
171 inline operator Dependency const *() const {return Dep == Owner->DepP?0:Dep;};
6c139d6e 172
578bfd0a
AL
173 inline const char *TargetVer() const {return Dep->Version == 0?0:Owner->StrP + Dep->Version;};
174 inline PkgIterator TargetPkg() {return PkgIterator(*Owner,Owner->PkgP + Dep->Package);};
578bfd0a
AL
175 inline PkgIterator SmartTargetPkg() {PkgIterator R(*Owner);SmartTargetPkg(R);return R;};
176 inline VerIterator ParentVer() {return VerIterator(*Owner,Owner->VerP + Dep->ParentVer);};
177 inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Dep->ParentVer].ParentPkg);};
578bfd0a 178 inline bool Reverse() {return Type == DepRev;};
f55a958f 179 inline unsigned long Index() const {return Dep - Owner->DepP;};
6c139d6e 180 bool IsCritical();
43d017d6 181 void GlobOr(DepIterator &Start,DepIterator &End);
6c139d6e
AL
182 Version **AllTargets();
183 bool SmartTargetPkg(PkgIterator &Result);
0a8e3465 184 const char *CompType();
43d017d6 185 const char *DepType();
0a8e3465 186
578bfd0a
AL
187 inline DepIterator(pkgCache &Owner,Dependency *Trg,Version * = 0) :
188 Dep(Trg), Type(DepVer), Owner(&Owner)
189 {
190 if (Dep == 0)
191 Dep = Owner.DepP;
192 };
193 inline DepIterator(pkgCache &Owner,Dependency *Trg,Package *) :
194 Dep(Trg), Type(DepRev), Owner(&Owner)
195 {
196 if (Dep == 0)
197 Dep = Owner.DepP;
198 };
199 inline DepIterator() : Dep(0), Type(DepVer), Owner(0) {};
200};
201
202// Provides iterator
203class pkgCache::PrvIterator
204{
205 Provides *Prv;
206 enum {PrvVer, PrvPkg} Type;
207 pkgCache *Owner;
208
209 void _dummy();
210
211 public:
212
213 // Iteration
214 void operator ++(int) {if (Prv != Owner->ProvideP) Prv = Owner->ProvideP +
215 (Type == PrvVer?Prv->NextPkgProv:Prv->NextProvides);};
216 inline void operator ++() {operator ++(0);};
217 inline bool end() const {return Prv == Owner->ProvideP?true:false;};
218
219 // Comparison
220 inline bool operator ==(const PrvIterator &B) const {return Prv == B.Prv;};
221 inline bool operator !=(const PrvIterator &B) const {return Prv != B.Prv;};
222
223 // Accessors
224 inline Provides *operator ->() {return Prv;};
225 inline Provides const *operator ->() const {return Prv;};
226 inline Provides &operator *() {return *Prv;};
227 inline Provides const &operator *() const {return *Prv;};
228 inline operator Provides *() {return Prv == Owner->ProvideP?0:Prv;};
229 inline operator Provides const *() const {return Prv == Owner->ProvideP?0:Prv;};
6c139d6e 230
578bfd0a
AL
231 inline const char *Name() const {return Owner->StrP + Owner->PkgP[Prv->ParentPkg].Name;};
232 inline const char *ProvideVersion() const {return Prv->ProvideVersion == 0?0:Owner->StrP + Prv->ProvideVersion;};
233 inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Prv->ParentPkg);};
234 inline VerIterator OwnerVer() {return VerIterator(*Owner,Owner->VerP + Prv->Version);};
235 inline PkgIterator OwnerPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Prv->Version].ParentPkg);};
f55a958f 236 inline unsigned long Index() const {return Prv - Owner->ProvideP;};
578bfd0a
AL
237
238 inline PrvIterator(pkgCache &Owner,Provides *Trg,Version *) :
239 Prv(Trg), Type(PrvVer), Owner(&Owner)
240 {
241 if (Prv == 0)
242 Prv = Owner.ProvideP;
243 };
244 inline PrvIterator(pkgCache &Owner,Provides *Trg,Package *) :
245 Prv(Trg), Type(PrvPkg), Owner(&Owner)
246 {
247 if (Prv == 0)
248 Prv = Owner.ProvideP;
249 };
250};
251
252// Package file
253class pkgCache::PkgFileIterator
254{
255 pkgCache *Owner;
256 PackageFile *File;
257
258 public:
259
260 // Iteration
261 void operator ++(int) {if (File!= Owner->PkgFileP) File = Owner->PkgFileP + File->NextFile;};
262 inline void operator ++() {operator ++(0);};
263 inline bool end() const {return File == Owner->PkgFileP?true:false;};
264
265 // Comparison
266 inline bool operator ==(const PkgFileIterator &B) const {return File == B.File;};
267 inline bool operator !=(const PkgFileIterator &B) const {return File != B.File;};
268
269 // Accessors
270 inline PackageFile *operator ->() {return File;};
271 inline PackageFile const *operator ->() const {return File;};
272 inline PackageFile const &operator *() const {return *File;};
273 inline operator PackageFile *() {return File == Owner->PkgFileP?0:File;};
274 inline operator PackageFile const *() const {return File == Owner->PkgFileP?0:File;};
275
276 inline const char *FileName() const {return File->FileName == 0?0:Owner->StrP + File->FileName;};
b0b4efb9
AL
277 inline const char *Archive() const {return File->Archive == 0?0:Owner->StrP + File->Archive;};
278 inline const char *Component() const {return File->Component == 0?0:Owner->StrP + File->Component;};
578bfd0a 279 inline const char *Version() const {return File->Version == 0?0:Owner->StrP + File->Version;};
b0b4efb9
AL
280 inline const char *Origin() const {return File->Origin == 0?0:Owner->StrP + File->Origin;};
281 inline const char *Label() const {return File->Origin == 0?0:Owner->StrP + File->Label;};
282 inline const char *Architecture() const {return File->Origin == 0?0:Owner->StrP + File->Architecture;};
283
f55a958f 284 inline unsigned long Index() const {return File - Owner->PkgFileP;};
578bfd0a
AL
285
286 bool IsOk();
287
288 // Constructors
289 inline PkgFileIterator(pkgCache &Owner) : Owner(&Owner), File(Owner.PkgFileP + Owner.Head().FileList) {};
290 inline PkgFileIterator(pkgCache &Owner,PackageFile *Trg) : Owner(&Owner), File(Trg) {};
291};
292
dcb79bae
AL
293// Version File
294class pkgCache::VerFileIterator
295{
296 pkgCache *Owner;
297 VerFile *FileP;
298
299 public:
300
301 // Iteration
302 void operator ++(int) {if (FileP != Owner->VerFileP) FileP = Owner->VerFileP + FileP->NextFile;};
303 inline void operator ++() {operator ++(0);};
304 inline bool end() const {return FileP == Owner->VerFileP?true:false;};
305
306 // Comparison
307 inline bool operator ==(const VerFileIterator &B) const {return FileP == B.FileP;};
308 inline bool operator !=(const VerFileIterator &B) const {return FileP != B.FileP;};
309
310 // Accessors
311 inline VerFile *operator ->() {return FileP;};
312 inline VerFile const *operator ->() const {return FileP;};
313 inline VerFile const &operator *() const {return *FileP;};
314 inline operator VerFile *() {return FileP == Owner->VerFileP?0:FileP;};
315 inline operator VerFile const *() const {return FileP == Owner->VerFileP?0:FileP;};
316
317 inline PkgFileIterator File() const {return PkgFileIterator(*Owner,FileP->File + Owner->PkgFileP);};
318 inline unsigned long Index() const {return FileP - Owner->VerFileP;};
b518cca6 319
dcb79bae
AL
320 inline VerFileIterator(pkgCache &Owner,VerFile *Trg) : Owner(&Owner), FileP(Trg) {};
321};
322
578bfd0a
AL
323// Inlined Begin functions cant be in the class because of order problems
324inline pkgCache::VerIterator pkgCache::PkgIterator::VersionList() const
325 {return VerIterator(*Owner,Owner->VerP + Pkg->VersionList);};
326inline pkgCache::VerIterator pkgCache::PkgIterator::CurrentVer() const
327 {return VerIterator(*Owner,Owner->VerP + Pkg->CurrentVer);};
328inline pkgCache::VerIterator pkgCache::PkgIterator::TargetVer() const
329 {return VerIterator(*Owner,Owner->VerP + Pkg->TargetVer);};
330inline pkgCache::DepIterator pkgCache::PkgIterator::RevDependsList() const
331 {return DepIterator(*Owner,Owner->DepP + Pkg->RevDepends,Pkg);};
332inline pkgCache::PrvIterator pkgCache::PkgIterator::ProvidesList() const
333 {return PrvIterator(*Owner,Owner->ProvideP + Pkg->ProvidesList,Pkg);};
334inline pkgCache::PrvIterator pkgCache::VerIterator::ProvidesList() const
f9eec0e7 335 {return PrvIterator(*Owner,Owner->ProvideP + Ver->ProvidesList,Ver);};
578bfd0a 336inline pkgCache::DepIterator pkgCache::VerIterator::DependsList() const
f9eec0e7 337 {return DepIterator(*Owner,Owner->DepP + Ver->DependsList,Ver);};
dcb79bae 338inline pkgCache::VerFileIterator pkgCache::VerIterator::FileList() const
f9eec0e7 339 {return VerFileIterator(*Owner,Owner->VerFileP + Ver->FileList);};
578bfd0a
AL
340
341#endif