2 Apt is copyright 1997, 1998, 1999 Jason Gunthorpe and others.
3 Apt is currently developed by APT Development Team <deity@lists.debian.org>.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 See /usr/share/common-licenses/GPL-2, or
22 <http://www.gnu.org/copyleft/gpl.txt> for the terms of the latest version
23 of the GNU General Public License.
26 // -*- mode: cpp; mode: fold -*-
27 // Description /*{{{*/
28 // $Id: cacheiterators.h,v 1.18.2.1 2004/05/08 22:44:27 mdz Exp $
29 /* ######################################################################
31 Cache Iterators - Iterators for navigating the cache structure
33 The iterators all provides ++,==,!=,->,* and end for their type.
34 The end function can be used to tell if the list has been fully
37 Unlike STL iterators these contain helper functions to access the data
38 that is being iterated over. This is because the data structures can't
39 be formed in a manner that is intuitive to use and also mmapable.
41 For each variable in the target structure that would need a translation
42 to be accessed correctly a translating function of the same name is
43 present in the iterator. If applicable the translating function will
46 The DepIterator can iterate over two lists, a list of 'version depends'
47 or a list of 'package reverse depends'. The type is determined by the
48 structure passed to the constructor, which should be the structure
49 that has the depends pointer as a member. The provide iterator has the
52 This header is not user includable, please use apt-pkg/pkgcache.h
54 ##################################################################### */
56 #ifndef PKGLIB_CACHEITERATORS_H
57 #define PKGLIB_CACHEITERATORS_H
61 class pkgCache::PkgIterator
63 friend class pkgCache;
70 // This constructor is the 'begin' constructor, never use it.
71 inline PkgIterator(pkgCache &Owner) : Owner(&Owner), HashIndex(-1)
79 enum OkState {NeedsNothing,NeedsUnpack,NeedsConfigure};
82 void operator ++(int);
83 inline void operator ++() {operator ++(0);};
84 inline bool end() const {return Owner == 0 || Pkg == Owner->PkgP?true:false;};
87 inline bool operator ==(const PkgIterator &B) const {return Pkg == B.Pkg;};
88 inline bool operator !=(const PkgIterator &B) const {return Pkg != B.Pkg;};
91 inline Package *operator ->() {return Pkg;};
92 inline Package const *operator ->() const {return Pkg;};
93 inline Package const &operator *() const {return *Pkg;};
94 inline operator Package *() {return Pkg == Owner->PkgP?0:Pkg;};
95 inline operator Package const *() const {return Pkg == Owner->PkgP?0:Pkg;};
96 inline pkgCache *Cache() {return Owner;};
98 inline const char *Name() const {return Pkg->Name == 0?0:Owner->StrP + Pkg->Name;};
99 inline const char *Section() const {return Pkg->Section == 0?0:Owner->StrP + Pkg->Section;};
100 inline bool Purge() const {return Pkg->CurrentState == pkgCache::State::Purge ||
101 (Pkg->CurrentVer == 0 && Pkg->CurrentState == pkgCache::State::NotInstalled);};
102 inline VerIterator VersionList() const;
103 inline VerIterator CurrentVer() const;
104 inline DepIterator RevDependsList() const;
105 inline PrvIterator ProvidesList() const;
106 inline unsigned long Index() const {return Pkg - Owner->PkgP;};
107 OkState State() const;
110 inline PkgIterator(pkgCache &Owner,Package *Trg) : Pkg(Trg), Owner(&Owner),
116 inline PkgIterator() : Pkg(0), Owner(0), HashIndex(0) {};
120 class pkgCache::VerIterator
130 void operator ++(int) {if (Ver != Owner->VerP) Ver = Owner->VerP + Ver->NextVer;};
131 inline void operator ++() {operator ++(0);};
132 inline bool end() const {return Owner == NULL || (Ver == Owner->VerP?true:false);};
133 inline void operator =(const VerIterator &B) {Ver = B.Ver; Owner = B.Owner;};
136 inline bool operator ==(const VerIterator &B) const {return Ver == B.Ver;};
137 inline bool operator !=(const VerIterator &B) const {return Ver != B.Ver;};
138 int CompareVer(const VerIterator &B) const;
141 inline Version *operator ->() {return Ver;};
142 inline Version const *operator ->() const {return Ver;};
143 inline Version &operator *() {return *Ver;};
144 inline Version const &operator *() const {return *Ver;};
145 inline operator Version *() {return Ver == Owner->VerP?0:Ver;};
146 inline operator Version const *() const {return Ver == Owner->VerP?0:Ver;};
147 inline pkgCache *Cache() {return Owner;};
149 inline const char *VerStr() const {return Ver->VerStr == 0?0:Owner->StrP + Ver->VerStr;};
150 inline const char *Section() const {return Ver->Section == 0?0:Owner->StrP + Ver->Section;};
151 inline const char *Arch() const {return Ver->Arch == 0?0:Owner->StrP + Ver->Arch;};
152 inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + Ver->ParentPkg);};
153 inline DescIterator DescriptionList() const;
154 DescIterator TranslatedDescription() const;
155 inline DepIterator DependsList() const;
156 inline PrvIterator ProvidesList() const;
157 inline VerFileIterator FileList() const;
158 inline unsigned long Index() const {return Ver - Owner->VerP;};
159 bool Downloadable() const;
160 inline const char *PriorityType() {return Owner->Priority(Ver->Priority);};
163 bool Automatic() const;
164 VerFileIterator NewestFile() const;
166 inline VerIterator() : Ver(0), Owner(0) {};
167 inline VerIterator(pkgCache &Owner,Version *Trg = 0) : Ver(Trg),
175 // Description Iterator
176 class pkgCache::DescIterator
186 void operator ++(int) {if (Desc != Owner->DescP) Desc = Owner->DescP + Desc->NextDesc;};
187 inline void operator ++() {operator ++(0);};
188 inline bool end() const {return Desc == Owner->DescP?true:false;};
189 inline void operator =(const DescIterator &B) {Desc = B.Desc; Owner = B.Owner;};
192 inline bool operator ==(const DescIterator &B) const {return Desc == B.Desc;};
193 inline bool operator !=(const DescIterator &B) const {return Desc != B.Desc;};
194 int CompareDesc(const DescIterator &B) const;
197 inline Description *operator ->() {return Desc;};
198 inline Description const *operator ->() const {return Desc;};
199 inline Description &operator *() {return *Desc;};
200 inline Description const &operator *() const {return *Desc;};
201 inline operator Description *() {return Desc == Owner->DescP?0:Desc;};
202 inline operator Description const *() const {return Desc == Owner->DescP?0:Desc;};
203 inline pkgCache *Cache() {return Owner;};
205 inline const char *LanguageCode() const {return Owner->StrP + Desc->language_code;};
206 inline const char *md5() const {return Owner->StrP + Desc->md5sum;};
207 inline DescFileIterator FileList() const;
208 inline unsigned long Index() const {return Desc - Owner->DescP;};
210 inline DescIterator() : Desc(0), Owner(0) {};
211 inline DescIterator(pkgCache &Owner,Description *Trg = 0) : Desc(Trg),
219 // Dependency iterator
220 class pkgCache::DepIterator
223 enum {DepVer, DepRev} Type;
231 void operator ++(int) {if (Dep != Owner->DepP) Dep = Owner->DepP +
232 (Type == DepVer?Dep->NextDepends:Dep->NextRevDepends);};
233 inline void operator ++() {operator ++(0);};
234 inline bool end() const {return Owner == 0 || Dep == Owner->DepP?true:false;};
237 inline bool operator ==(const DepIterator &B) const {return Dep == B.Dep;};
238 inline bool operator !=(const DepIterator &B) const {return Dep != B.Dep;};
241 inline Dependency *operator ->() {return Dep;};
242 inline Dependency const *operator ->() const {return Dep;};
243 inline Dependency &operator *() {return *Dep;};
244 inline Dependency const &operator *() const {return *Dep;};
245 inline operator Dependency *() {return Dep == Owner->DepP?0:Dep;};
246 inline operator Dependency const *() const {return Dep == Owner->DepP?0:Dep;};
247 inline pkgCache *Cache() {return Owner;};
249 inline const char *TargetVer() const {return Dep->Version == 0?0:Owner->StrP + Dep->Version;};
250 inline PkgIterator TargetPkg() {return PkgIterator(*Owner,Owner->PkgP + Dep->Package);};
251 inline PkgIterator SmartTargetPkg() {PkgIterator R(*Owner,0);SmartTargetPkg(R);return R;};
252 inline VerIterator ParentVer() {return VerIterator(*Owner,Owner->VerP + Dep->ParentVer);};
253 inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Dep->ParentVer].ParentPkg);};
254 inline bool Reverse() {return Type == DepRev;};
255 inline unsigned long Index() const {return Dep - Owner->DepP;};
257 void GlobOr(DepIterator &Start,DepIterator &End);
258 Version **AllTargets();
259 bool SmartTargetPkg(PkgIterator &Result);
260 inline const char *CompType() {return Owner->CompType(Dep->CompareOp);};
261 inline const char *DepType() {return Owner->DepType(Dep->Type);};
263 inline DepIterator(pkgCache &Owner,Dependency *Trg,Version * = 0) :
264 Dep(Trg), Type(DepVer), Owner(&Owner)
269 inline DepIterator(pkgCache &Owner,Dependency *Trg,Package *) :
270 Dep(Trg), Type(DepRev), Owner(&Owner)
275 inline DepIterator() : Dep(0), Type(DepVer), Owner(0) {};
279 class pkgCache::PrvIterator
282 enum {PrvVer, PrvPkg} Type;
290 void operator ++(int) {if (Prv != Owner->ProvideP) Prv = Owner->ProvideP +
291 (Type == PrvVer?Prv->NextPkgProv:Prv->NextProvides);};
292 inline void operator ++() {operator ++(0);};
293 inline bool end() const {return Owner == 0 || Prv == Owner->ProvideP?true:false;};
296 inline bool operator ==(const PrvIterator &B) const {return Prv == B.Prv;};
297 inline bool operator !=(const PrvIterator &B) const {return Prv != B.Prv;};
300 inline Provides *operator ->() {return Prv;};
301 inline Provides const *operator ->() const {return Prv;};
302 inline Provides &operator *() {return *Prv;};
303 inline Provides const &operator *() const {return *Prv;};
304 inline operator Provides *() {return Prv == Owner->ProvideP?0:Prv;};
305 inline operator Provides const *() const {return Prv == Owner->ProvideP?0:Prv;};
306 inline pkgCache *Cache() {return Owner;};
308 inline const char *Name() const {return Owner->StrP + Owner->PkgP[Prv->ParentPkg].Name;};
309 inline const char *ProvideVersion() const {return Prv->ProvideVersion == 0?0:Owner->StrP + Prv->ProvideVersion;};
310 inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Prv->ParentPkg);};
311 inline VerIterator OwnerVer() {return VerIterator(*Owner,Owner->VerP + Prv->Version);};
312 inline PkgIterator OwnerPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Prv->Version].ParentPkg);};
313 inline unsigned long Index() const {return Prv - Owner->ProvideP;};
315 inline PrvIterator() : Prv(0), Type(PrvVer), Owner(0) {};
317 inline PrvIterator(pkgCache &Owner,Provides *Trg,Version *) :
318 Prv(Trg), Type(PrvVer), Owner(&Owner)
321 Prv = Owner.ProvideP;
323 inline PrvIterator(pkgCache &Owner,Provides *Trg,Package *) :
324 Prv(Trg), Type(PrvPkg), Owner(&Owner)
327 Prv = Owner.ProvideP;
332 class pkgCache::PkgFileIterator
340 void operator ++(int) {if (File!= Owner->PkgFileP) File = Owner->PkgFileP + File->NextFile;};
341 inline void operator ++() {operator ++(0);};
342 inline bool end() const {return File == Owner->PkgFileP?true:false;};
345 inline bool operator ==(const PkgFileIterator &B) const {return File == B.File;};
346 inline bool operator !=(const PkgFileIterator &B) const {return File != B.File;};
349 inline PackageFile *operator ->() {return File;};
350 inline PackageFile const *operator ->() const {return File;};
351 inline PackageFile const &operator *() const {return *File;};
352 inline operator PackageFile *() {return File == Owner->PkgFileP?0:File;};
353 inline operator PackageFile const *() const {return File == Owner->PkgFileP?0:File;};
354 inline pkgCache *Cache() {return Owner;};
356 inline const char *FileName() const {return File->FileName == 0?0:Owner->StrP + File->FileName;};
357 inline const char *Archive() const {return File->Archive == 0?0:Owner->StrP + File->Archive;};
358 inline const char *Component() const {return File->Component == 0?0:Owner->StrP + File->Component;};
359 inline const char *Version() const {return File->Version == 0?0:Owner->StrP + File->Version;};
360 inline const char *Origin() const {return File->Origin == 0?0:Owner->StrP + File->Origin;};
361 inline const char *Label() const {return File->Label == 0?0:Owner->StrP + File->Label;};
362 inline const char *Site() const {return File->Site == 0?0:Owner->StrP + File->Site;};
363 inline const char *Architecture() const {return File->Architecture == 0?0:Owner->StrP + File->Architecture;};
364 inline const char *IndexType() const {return File->IndexType == 0?0:Owner->StrP + File->IndexType;};
366 inline unsigned long Index() const {return File - Owner->PkgFileP;};
372 inline PkgFileIterator() : Owner(0), File(0) {};
373 inline PkgFileIterator(pkgCache &Owner) : Owner(&Owner), File(Owner.PkgFileP) {};
374 inline PkgFileIterator(pkgCache &Owner,PackageFile *Trg) : Owner(&Owner), File(Trg) {};
378 class pkgCache::VerFileIterator
386 void operator ++(int) {if (FileP != Owner->VerFileP) FileP = Owner->VerFileP + FileP->NextFile;};
387 inline void operator ++() {operator ++(0);};
388 inline bool end() const {return FileP == Owner->VerFileP?true:false;};
391 inline bool operator ==(const VerFileIterator &B) const {return FileP == B.FileP;};
392 inline bool operator !=(const VerFileIterator &B) const {return FileP != B.FileP;};
395 inline VerFile *operator ->() {return FileP;};
396 inline VerFile const *operator ->() const {return FileP;};
397 inline VerFile const &operator *() const {return *FileP;};
398 inline operator VerFile *() {return FileP == Owner->VerFileP?0:FileP;};
399 inline operator VerFile const *() const {return FileP == Owner->VerFileP?0:FileP;};
400 inline pkgCache *Cache() {return Owner;};
402 inline PkgFileIterator File() const {return PkgFileIterator(*Owner,FileP->File + Owner->PkgFileP);};
403 inline unsigned long Index() const {return FileP - Owner->VerFileP;};
405 inline VerFileIterator() : Owner(0), FileP(0) {};
406 inline VerFileIterator(pkgCache &Owner,VerFile *Trg) : Owner(&Owner), FileP(Trg) {};
410 class pkgCache::DescFileIterator
418 void operator ++(int) {if (FileP != Owner->DescFileP) FileP = Owner->DescFileP + FileP->NextFile;};
419 inline void operator ++() {operator ++(0);};
420 inline bool end() const {return FileP == Owner->DescFileP?true:false;};
423 inline bool operator ==(const DescFileIterator &B) const {return FileP == B.FileP;};
424 inline bool operator !=(const DescFileIterator &B) const {return FileP != B.FileP;};
427 inline DescFile *operator ->() {return FileP;};
428 inline DescFile const *operator ->() const {return FileP;};
429 inline DescFile const &operator *() const {return *FileP;};
430 inline operator DescFile *() {return FileP == Owner->DescFileP?0:FileP;};
431 inline operator DescFile const *() const {return FileP == Owner->DescFileP?0:FileP;};
432 inline pkgCache *Cache() {return Owner;};
434 inline PkgFileIterator File() const {return PkgFileIterator(*Owner,FileP->File + Owner->PkgFileP);};
435 inline unsigned long Index() const {return FileP - Owner->DescFileP;};
437 inline DescFileIterator() : Owner(0), FileP(0) {};
438 inline DescFileIterator(pkgCache &Owner,DescFile *Trg) : Owner(&Owner), FileP(Trg) {};
441 // Inlined Begin functions cant be in the class because of order problems
442 inline pkgCache::VerIterator pkgCache::PkgIterator::VersionList() const
443 {return VerIterator(*Owner,Owner->VerP + Pkg->VersionList);};
444 inline pkgCache::VerIterator pkgCache::PkgIterator::CurrentVer() const
445 {return VerIterator(*Owner,Owner->VerP + Pkg->CurrentVer);};
446 inline pkgCache::DepIterator pkgCache::PkgIterator::RevDependsList() const
447 {return DepIterator(*Owner,Owner->DepP + Pkg->RevDepends,Pkg);};
448 inline pkgCache::PrvIterator pkgCache::PkgIterator::ProvidesList() const
449 {return PrvIterator(*Owner,Owner->ProvideP + Pkg->ProvidesList,Pkg);};
450 inline pkgCache::DescIterator pkgCache::VerIterator::DescriptionList() const
451 {return DescIterator(*Owner,Owner->DescP + Ver->DescriptionList);};
452 inline pkgCache::PrvIterator pkgCache::VerIterator::ProvidesList() const
453 {return PrvIterator(*Owner,Owner->ProvideP + Ver->ProvidesList,Ver);};
454 inline pkgCache::DepIterator pkgCache::VerIterator::DependsList() const
455 {return DepIterator(*Owner,Owner->DepP + Ver->DependsList,Ver);};
456 inline pkgCache::VerFileIterator pkgCache::VerIterator::FileList() const
457 {return VerFileIterator(*Owner,Owner->VerFileP + Ver->FileList);};
458 inline pkgCache::DescFileIterator pkgCache::DescIterator::FileList() const
459 {return DescFileIterator(*Owner,Owner->DescFileP + Desc->FileList);};