]> git.saurik.com Git - apt.git/blame - apt-pkg/cacheiterators.h
* apt-pkg/indexfile.cc:
[apt.git] / apt-pkg / cacheiterators.h
CommitLineData
578bfd0a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
7db98ffc 3// $Id: cacheiterators.h,v 1.18.2.1 2004/05/08 22:44:27 mdz 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 /*}}}*/
578bfd0a
AL
31#ifndef PKGLIB_CACHEITERATORS_H
32#define PKGLIB_CACHEITERATORS_H
33
6c139d6e 34#ifdef __GNUG__
094a497d 35#pragma interface "apt-pkg/cacheiterators.h"
6c139d6e
AL
36#endif
37
578bfd0a
AL
38// Package Iterator
39class pkgCache::PkgIterator
40{
b2e465d6 41 friend class pkgCache;
578bfd0a
AL
42 Package *Pkg;
43 pkgCache *Owner;
44 long HashIndex;
45
b2e465d6
AL
46 protected:
47
48 // This constructor is the 'begin' constructor, never use it.
49 inline PkgIterator(pkgCache &Owner) : Owner(&Owner), HashIndex(-1)
50 {
51 Pkg = Owner.PkgP;
52 operator ++(0);
53 };
54
578bfd0a
AL
55 public:
56
57 enum OkState {NeedsNothing,NeedsUnpack,NeedsConfigure};
58
59 // Iteration
60 void operator ++(int);
61 inline void operator ++() {operator ++(0);};
62 inline bool end() const {return Owner == 0 || Pkg == Owner->PkgP?true:false;};
63
64 // Comparison
65 inline bool operator ==(const PkgIterator &B) const {return Pkg == B.Pkg;};
66 inline bool operator !=(const PkgIterator &B) const {return Pkg != B.Pkg;};
67
68 // Accessors
69 inline Package *operator ->() {return Pkg;};
70 inline Package const *operator ->() const {return Pkg;};
71 inline Package const &operator *() const {return *Pkg;};
72 inline operator Package *() {return Pkg == Owner->PkgP?0:Pkg;};
73 inline operator Package const *() const {return Pkg == Owner->PkgP?0:Pkg;};
b2e465d6 74 inline pkgCache *Cache() {return Owner;};
6c139d6e 75
578bfd0a
AL
76 inline const char *Name() const {return Pkg->Name == 0?0:Owner->StrP + Pkg->Name;};
77 inline const char *Section() const {return Pkg->Section == 0?0:Owner->StrP + Pkg->Section;};
e3bf76d1
AL
78 inline bool Purge() const {return Pkg->CurrentState == pkgCache::State::Purge ||
79 (Pkg->CurrentVer == 0 && Pkg->CurrentState == pkgCache::State::NotInstalled);};
578bfd0a 80 inline VerIterator VersionList() const;
578bfd0a
AL
81 inline VerIterator CurrentVer() const;
82 inline DepIterator RevDependsList() const;
83 inline PrvIterator ProvidesList() const;
f55a958f 84 inline unsigned long Index() const {return Pkg - Owner->PkgP;};
578bfd0a
AL
85 OkState State() const;
86
87 // Constructors
578bfd0a
AL
88 inline PkgIterator(pkgCache &Owner,Package *Trg) : Pkg(Trg), Owner(&Owner),
89 HashIndex(0)
90 {
91 if (Pkg == 0)
92 Pkg = Owner.PkgP;
93 };
94 inline PkgIterator() : Pkg(0), Owner(0), HashIndex(0) {};
95};
96
97// Version Iterator
98class pkgCache::VerIterator
99{
100 Version *Ver;
f9eec0e7 101 pkgCache *Owner;
770c32ec 102
578bfd0a
AL
103 void _dummy();
104
105 public:
106
107 // Iteration
f9eec0e7 108 void operator ++(int) {if (Ver != Owner->VerP) Ver = Owner->VerP + Ver->NextVer;};
578bfd0a 109 inline void operator ++() {operator ++(0);};
f9eec0e7
AL
110 inline bool end() const {return Ver == Owner->VerP?true:false;};
111 inline void operator =(const VerIterator &B) {Ver = B.Ver; Owner = B.Owner;};
578bfd0a
AL
112
113 // Comparison
114 inline bool operator ==(const VerIterator &B) const {return Ver == B.Ver;};
115 inline bool operator !=(const VerIterator &B) const {return Ver != B.Ver;};
116 int CompareVer(const VerIterator &B) const;
117
118 // Accessors
119 inline Version *operator ->() {return Ver;};
120 inline Version const *operator ->() const {return Ver;};
121 inline Version &operator *() {return *Ver;};
122 inline Version const &operator *() const {return *Ver;};
f9eec0e7
AL
123 inline operator Version *() {return Ver == Owner->VerP?0:Ver;};
124 inline operator Version const *() const {return Ver == Owner->VerP?0:Ver;};
b2e465d6
AL
125 inline pkgCache *Cache() {return Owner;};
126
f9eec0e7
AL
127 inline const char *VerStr() const {return Ver->VerStr == 0?0:Owner->StrP + Ver->VerStr;};
128 inline const char *Section() const {return Ver->Section == 0?0:Owner->StrP + Ver->Section;};
129 inline const char *Arch() const {return Ver->Arch == 0?0:Owner->StrP + Ver->Arch;};
130 inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + Ver->ParentPkg);};
a52f938b 131 inline DescIterator DescriptionList() const;
012b102a 132 DescIterator TranslatedDescription() const;
578bfd0a
AL
133 inline DepIterator DependsList() const;
134 inline PrvIterator ProvidesList() const;
dcb79bae 135 inline VerFileIterator FileList() const;
f9eec0e7 136 inline unsigned long Index() const {return Ver - Owner->VerP;};
b518cca6 137 bool Downloadable() const;
b2e465d6
AL
138 inline const char *PriorityType() {return Owner->Priority(Ver->Priority);};
139 string RelStr();
140
3c124dde
AL
141 bool Automatic() const;
142 VerFileIterator NewestFile() const;
f9eec0e7
AL
143
144 inline VerIterator() : Ver(0), Owner(0) {};
145 inline VerIterator(pkgCache &Owner,Version *Trg = 0) : Ver(Trg),
146 Owner(&Owner)
578bfd0a
AL
147 {
148 if (Ver == 0)
149 Ver = Owner.VerP;
150 };
151};
152
a52f938b
OS
153// Description Iterator
154class pkgCache::DescIterator
155{
156 Description *Desc;
157 pkgCache *Owner;
158
159 void _dummy();
160
161 public:
162
163 // Iteration
164 void operator ++(int) {if (Desc != Owner->DescP) Desc = Owner->DescP + Desc->NextDesc;};
165 inline void operator ++() {operator ++(0);};
166 inline bool end() const {return Desc == Owner->DescP?true:false;};
167 inline void operator =(const DescIterator &B) {Desc = B.Desc; Owner = B.Owner;};
168
169 // Comparison
170 inline bool operator ==(const DescIterator &B) const {return Desc == B.Desc;};
171 inline bool operator !=(const DescIterator &B) const {return Desc != B.Desc;};
172 int CompareDesc(const DescIterator &B) const;
173
174 // Accessors
175 inline Description *operator ->() {return Desc;};
176 inline Description const *operator ->() const {return Desc;};
177 inline Description &operator *() {return *Desc;};
178 inline Description const &operator *() const {return *Desc;};
179 inline operator Description *() {return Desc == Owner->DescP?0:Desc;};
180 inline operator Description const *() const {return Desc == Owner->DescP?0:Desc;};
181 inline pkgCache *Cache() {return Owner;};
182
183 inline const char *LanguageCode() const {return Owner->StrP + Desc->language_code;};
184 inline const char *md5() const {return Owner->StrP + Desc->md5sum;};
185 inline DescFileIterator FileList() const;
186 inline unsigned long Index() const {return Desc - Owner->DescP;};
187
188 inline DescIterator() : Desc(0), Owner(0) {};
189 inline DescIterator(pkgCache &Owner,Description *Trg = 0) : Desc(Trg),
190 Owner(&Owner)
191 {
192 if (Desc == 0)
193 Desc = Owner.DescP;
194 };
195};
196
578bfd0a
AL
197// Dependency iterator
198class pkgCache::DepIterator
199{
200 Dependency *Dep;
201 enum {DepVer, DepRev} Type;
202 pkgCache *Owner;
203
204 void _dummy();
205
206 public:
207
208 // Iteration
209 void operator ++(int) {if (Dep != Owner->DepP) Dep = Owner->DepP +
210 (Type == DepVer?Dep->NextDepends:Dep->NextRevDepends);};
211 inline void operator ++() {operator ++(0);};
212 inline bool end() const {return Owner == 0 || Dep == Owner->DepP?true:false;};
213
214 // Comparison
215 inline bool operator ==(const DepIterator &B) const {return Dep == B.Dep;};
216 inline bool operator !=(const DepIterator &B) const {return Dep != B.Dep;};
217
218 // Accessors
219 inline Dependency *operator ->() {return Dep;};
220 inline Dependency const *operator ->() const {return Dep;};
221 inline Dependency &operator *() {return *Dep;};
222 inline Dependency const &operator *() const {return *Dep;};
223 inline operator Dependency *() {return Dep == Owner->DepP?0:Dep;};
224 inline operator Dependency const *() const {return Dep == Owner->DepP?0:Dep;};
b2e465d6 225 inline pkgCache *Cache() {return Owner;};
6c139d6e 226
578bfd0a
AL
227 inline const char *TargetVer() const {return Dep->Version == 0?0:Owner->StrP + Dep->Version;};
228 inline PkgIterator TargetPkg() {return PkgIterator(*Owner,Owner->PkgP + Dep->Package);};
b2e465d6 229 inline PkgIterator SmartTargetPkg() {PkgIterator R(*Owner,0);SmartTargetPkg(R);return R;};
578bfd0a
AL
230 inline VerIterator ParentVer() {return VerIterator(*Owner,Owner->VerP + Dep->ParentVer);};
231 inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Dep->ParentVer].ParentPkg);};
578bfd0a 232 inline bool Reverse() {return Type == DepRev;};
f55a958f 233 inline unsigned long Index() const {return Dep - Owner->DepP;};
6c139d6e 234 bool IsCritical();
43d017d6 235 void GlobOr(DepIterator &Start,DepIterator &End);
6c139d6e
AL
236 Version **AllTargets();
237 bool SmartTargetPkg(PkgIterator &Result);
b2e465d6
AL
238 inline const char *CompType() {return Owner->CompType(Dep->CompareOp);};
239 inline const char *DepType() {return Owner->DepType(Dep->Type);};
0a8e3465 240
578bfd0a
AL
241 inline DepIterator(pkgCache &Owner,Dependency *Trg,Version * = 0) :
242 Dep(Trg), Type(DepVer), Owner(&Owner)
243 {
244 if (Dep == 0)
245 Dep = Owner.DepP;
246 };
247 inline DepIterator(pkgCache &Owner,Dependency *Trg,Package *) :
248 Dep(Trg), Type(DepRev), Owner(&Owner)
249 {
250 if (Dep == 0)
251 Dep = Owner.DepP;
252 };
253 inline DepIterator() : Dep(0), Type(DepVer), Owner(0) {};
254};
255
256// Provides iterator
257class pkgCache::PrvIterator
258{
259 Provides *Prv;
260 enum {PrvVer, PrvPkg} Type;
261 pkgCache *Owner;
262
263 void _dummy();
264
265 public:
266
267 // Iteration
268 void operator ++(int) {if (Prv != Owner->ProvideP) Prv = Owner->ProvideP +
269 (Type == PrvVer?Prv->NextPkgProv:Prv->NextProvides);};
270 inline void operator ++() {operator ++(0);};
13e8426f 271 inline bool end() const {return Owner == 0 || Prv == Owner->ProvideP?true:false;};
578bfd0a
AL
272
273 // Comparison
274 inline bool operator ==(const PrvIterator &B) const {return Prv == B.Prv;};
275 inline bool operator !=(const PrvIterator &B) const {return Prv != B.Prv;};
276
277 // Accessors
278 inline Provides *operator ->() {return Prv;};
279 inline Provides const *operator ->() const {return Prv;};
280 inline Provides &operator *() {return *Prv;};
281 inline Provides const &operator *() const {return *Prv;};
282 inline operator Provides *() {return Prv == Owner->ProvideP?0:Prv;};
283 inline operator Provides const *() const {return Prv == Owner->ProvideP?0:Prv;};
b2e465d6 284 inline pkgCache *Cache() {return Owner;};
6c139d6e 285
578bfd0a
AL
286 inline const char *Name() const {return Owner->StrP + Owner->PkgP[Prv->ParentPkg].Name;};
287 inline const char *ProvideVersion() const {return Prv->ProvideVersion == 0?0:Owner->StrP + Prv->ProvideVersion;};
288 inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Prv->ParentPkg);};
289 inline VerIterator OwnerVer() {return VerIterator(*Owner,Owner->VerP + Prv->Version);};
290 inline PkgIterator OwnerPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Prv->Version].ParentPkg);};
f55a958f 291 inline unsigned long Index() const {return Prv - Owner->ProvideP;};
578bfd0a 292
c320a1e6 293 inline PrvIterator() : Prv(0), Type(PrvVer), Owner(0) {};
13e8426f 294
578bfd0a
AL
295 inline PrvIterator(pkgCache &Owner,Provides *Trg,Version *) :
296 Prv(Trg), Type(PrvVer), Owner(&Owner)
297 {
298 if (Prv == 0)
299 Prv = Owner.ProvideP;
300 };
301 inline PrvIterator(pkgCache &Owner,Provides *Trg,Package *) :
302 Prv(Trg), Type(PrvPkg), Owner(&Owner)
303 {
304 if (Prv == 0)
305 Prv = Owner.ProvideP;
306 };
307};
308
309// Package file
310class pkgCache::PkgFileIterator
311{
312 pkgCache *Owner;
313 PackageFile *File;
314
315 public:
316
317 // Iteration
318 void operator ++(int) {if (File!= Owner->PkgFileP) File = Owner->PkgFileP + File->NextFile;};
319 inline void operator ++() {operator ++(0);};
320 inline bool end() const {return File == Owner->PkgFileP?true:false;};
321
322 // Comparison
323 inline bool operator ==(const PkgFileIterator &B) const {return File == B.File;};
324 inline bool operator !=(const PkgFileIterator &B) const {return File != B.File;};
325
326 // Accessors
327 inline PackageFile *operator ->() {return File;};
328 inline PackageFile const *operator ->() const {return File;};
329 inline PackageFile const &operator *() const {return *File;};
330 inline operator PackageFile *() {return File == Owner->PkgFileP?0:File;};
331 inline operator PackageFile const *() const {return File == Owner->PkgFileP?0:File;};
b2e465d6 332 inline pkgCache *Cache() {return Owner;};
578bfd0a
AL
333
334 inline const char *FileName() const {return File->FileName == 0?0:Owner->StrP + File->FileName;};
b0b4efb9
AL
335 inline const char *Archive() const {return File->Archive == 0?0:Owner->StrP + File->Archive;};
336 inline const char *Component() const {return File->Component == 0?0:Owner->StrP + File->Component;};
578bfd0a 337 inline const char *Version() const {return File->Version == 0?0:Owner->StrP + File->Version;};
b0b4efb9 338 inline const char *Origin() const {return File->Origin == 0?0:Owner->StrP + File->Origin;};
a2ec6097 339 inline const char *Label() const {return File->Label == 0?0:Owner->StrP + File->Label;};
b2e465d6
AL
340 inline const char *Site() const {return File->Site == 0?0:Owner->StrP + File->Site;};
341 inline const char *Architecture() const {return File->Architecture == 0?0:Owner->StrP + File->Architecture;};
342 inline const char *IndexType() const {return File->IndexType == 0?0:Owner->StrP + File->IndexType;};
b0b4efb9 343
f55a958f 344 inline unsigned long Index() const {return File - Owner->PkgFileP;};
578bfd0a
AL
345
346 bool IsOk();
af87ab54
AL
347 string RelStr();
348
578bfd0a 349 // Constructors
b2e465d6
AL
350 inline PkgFileIterator() : Owner(0), File(0) {};
351 inline PkgFileIterator(pkgCache &Owner) : Owner(&Owner), File(Owner.PkgFileP) {};
578bfd0a
AL
352 inline PkgFileIterator(pkgCache &Owner,PackageFile *Trg) : Owner(&Owner), File(Trg) {};
353};
354
dcb79bae
AL
355// Version File
356class pkgCache::VerFileIterator
357{
358 pkgCache *Owner;
359 VerFile *FileP;
360
361 public:
362
363 // Iteration
364 void operator ++(int) {if (FileP != Owner->VerFileP) FileP = Owner->VerFileP + FileP->NextFile;};
365 inline void operator ++() {operator ++(0);};
366 inline bool end() const {return FileP == Owner->VerFileP?true:false;};
367
368 // Comparison
369 inline bool operator ==(const VerFileIterator &B) const {return FileP == B.FileP;};
370 inline bool operator !=(const VerFileIterator &B) const {return FileP != B.FileP;};
371
372 // Accessors
373 inline VerFile *operator ->() {return FileP;};
374 inline VerFile const *operator ->() const {return FileP;};
375 inline VerFile const &operator *() const {return *FileP;};
376 inline operator VerFile *() {return FileP == Owner->VerFileP?0:FileP;};
377 inline operator VerFile const *() const {return FileP == Owner->VerFileP?0:FileP;};
b2e465d6 378 inline pkgCache *Cache() {return Owner;};
dcb79bae
AL
379
380 inline PkgFileIterator File() const {return PkgFileIterator(*Owner,FileP->File + Owner->PkgFileP);};
381 inline unsigned long Index() const {return FileP - Owner->VerFileP;};
b518cca6 382
b2e465d6 383 inline VerFileIterator() : Owner(0), FileP(0) {};
dcb79bae
AL
384 inline VerFileIterator(pkgCache &Owner,VerFile *Trg) : Owner(&Owner), FileP(Trg) {};
385};
386
a52f938b
OS
387// Description File
388class pkgCache::DescFileIterator
389{
390 pkgCache *Owner;
391 DescFile *FileP;
392
393 public:
394
395 // Iteration
396 void operator ++(int) {if (FileP != Owner->DescFileP) FileP = Owner->DescFileP + FileP->NextFile;};
397 inline void operator ++() {operator ++(0);};
398 inline bool end() const {return FileP == Owner->DescFileP?true:false;};
399
400 // Comparison
401 inline bool operator ==(const DescFileIterator &B) const {return FileP == B.FileP;};
402 inline bool operator !=(const DescFileIterator &B) const {return FileP != B.FileP;};
403
404 // Accessors
405 inline DescFile *operator ->() {return FileP;};
406 inline DescFile const *operator ->() const {return FileP;};
407 inline DescFile const &operator *() const {return *FileP;};
408 inline operator DescFile *() {return FileP == Owner->DescFileP?0:FileP;};
409 inline operator DescFile const *() const {return FileP == Owner->DescFileP?0:FileP;};
410 inline pkgCache *Cache() {return Owner;};
411
412 inline PkgFileIterator File() const {return PkgFileIterator(*Owner,FileP->File + Owner->PkgFileP);};
413 inline unsigned long Index() const {return FileP - Owner->DescFileP;};
414
415 inline DescFileIterator() : Owner(0), FileP(0) {};
416 inline DescFileIterator(pkgCache &Owner,DescFile *Trg) : Owner(&Owner), FileP(Trg) {};
417};
418
578bfd0a
AL
419// Inlined Begin functions cant be in the class because of order problems
420inline pkgCache::VerIterator pkgCache::PkgIterator::VersionList() const
421 {return VerIterator(*Owner,Owner->VerP + Pkg->VersionList);};
422inline pkgCache::VerIterator pkgCache::PkgIterator::CurrentVer() const
423 {return VerIterator(*Owner,Owner->VerP + Pkg->CurrentVer);};
578bfd0a
AL
424inline pkgCache::DepIterator pkgCache::PkgIterator::RevDependsList() const
425 {return DepIterator(*Owner,Owner->DepP + Pkg->RevDepends,Pkg);};
426inline pkgCache::PrvIterator pkgCache::PkgIterator::ProvidesList() const
427 {return PrvIterator(*Owner,Owner->ProvideP + Pkg->ProvidesList,Pkg);};
a52f938b
OS
428inline pkgCache::DescIterator pkgCache::VerIterator::DescriptionList() const
429 {return DescIterator(*Owner,Owner->DescP + Ver->DescriptionList);};
578bfd0a 430inline pkgCache::PrvIterator pkgCache::VerIterator::ProvidesList() const
f9eec0e7 431 {return PrvIterator(*Owner,Owner->ProvideP + Ver->ProvidesList,Ver);};
578bfd0a 432inline pkgCache::DepIterator pkgCache::VerIterator::DependsList() const
f9eec0e7 433 {return DepIterator(*Owner,Owner->DepP + Ver->DependsList,Ver);};
dcb79bae 434inline pkgCache::VerFileIterator pkgCache::VerIterator::FileList() const
f9eec0e7 435 {return VerFileIterator(*Owner,Owner->VerFileP + Ver->FileList);};
a52f938b
OS
436inline pkgCache::DescFileIterator pkgCache::DescIterator::FileList() const
437 {return DescFileIterator(*Owner,Owner->DescFileP + Desc->FileList);};
578bfd0a
AL
438
439#endif