]>
git.saurik.com Git - apt.git/blob - apt-pkg/cacheiterators.h
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: cacheiterators.h,v 1.12 1999/02/01 02:22:11 jgg Exp $
4 /* ######################################################################
6 Cache Iterators - Iterators for navigating the cache structure
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
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.
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
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
24 that has the depends pointer as a member. The provide iterator has the
27 This header is not user includable, please use apt-pkg/pkgcache.h
29 ##################################################################### */
31 // Header section: pkglib
32 #ifndef PKGLIB_CACHEITERATORS_H
33 #define PKGLIB_CACHEITERATORS_H
36 #pragma interface "apt-pkg/cacheiterators.h"
40 class pkgCache::PkgIterator
48 enum OkState
{NeedsNothing
,NeedsUnpack
,NeedsConfigure
};
51 void operator ++(int);
52 inline void operator ++() {operator ++(0);};
53 inline bool end() const {return Owner
== 0 || Pkg
== Owner
->PkgP
?true:false;};
56 inline bool operator ==(const PkgIterator
&B
) const {return Pkg
== B
.Pkg
;};
57 inline bool operator !=(const PkgIterator
&B
) const {return Pkg
!= B
.Pkg
;};
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
;};
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;
74 inline unsigned long Index() const {return Pkg
- Owner
->PkgP
;};
75 OkState
State() const;
78 inline PkgIterator(pkgCache
&Owner
) : Owner(&Owner
), HashIndex(-1)
83 inline PkgIterator(pkgCache
&Owner
,Package
*Trg
) : Pkg(Trg
), Owner(&Owner
),
89 inline PkgIterator() : Pkg(0), Owner(0), HashIndex(0) {};
93 class pkgCache::VerIterator
103 void operator ++(int) {if (Ver
!= Owner
.VerP
) Ver
= Owner
.VerP
+ Ver
->NextVer
;};
104 inline void operator ++() {operator ++(0);};
105 inline bool end() const {return Ver
== Owner
.VerP
?true:false;};
106 inline void operator =(const VerIterator
&B
) {Ver
= B
.Ver
;};
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;
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
;};
118 inline operator Version
*() {return Ver
== Owner
.VerP
?0:Ver
;};
119 inline operator Version
const *() const {return Ver
== Owner
.VerP
?0:Ver
;};
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
);};
125 inline DepIterator
DependsList() const;
126 inline PrvIterator
ProvidesList() const;
127 inline VerFileIterator
FileList() const;
128 inline unsigned long Index() const {return Ver
- Owner
.VerP
;};
129 bool Downloadable() const;
130 const char *PriorityType();
132 bool Automatic() const;
133 VerFileIterator
NewestFile() const;
135 inline VerIterator(pkgCache
&Owner
,Version
*Trg
= 0) : Ver(Trg
), Owner(Owner
)
142 // Dependency iterator
143 class pkgCache::DepIterator
146 enum {DepVer
, DepRev
} Type
;
154 void operator ++(int) {if (Dep
!= Owner
->DepP
) Dep
= Owner
->DepP
+
155 (Type
== DepVer
?Dep
->NextDepends
:Dep
->NextRevDepends
);};
156 inline void operator ++() {operator ++(0);};
157 inline bool end() const {return Owner
== 0 || Dep
== Owner
->DepP
?true:false;};
160 inline bool operator ==(const DepIterator
&B
) const {return Dep
== B
.Dep
;};
161 inline bool operator !=(const DepIterator
&B
) const {return Dep
!= B
.Dep
;};
164 inline Dependency
*operator ->() {return Dep
;};
165 inline Dependency
const *operator ->() const {return Dep
;};
166 inline Dependency
&operator *() {return *Dep
;};
167 inline Dependency
const &operator *() const {return *Dep
;};
168 inline operator Dependency
*() {return Dep
== Owner
->DepP
?0:Dep
;};
169 inline operator Dependency
const *() const {return Dep
== Owner
->DepP
?0:Dep
;};
171 inline const char *TargetVer() const {return Dep
->Version
== 0?0:Owner
->StrP
+ Dep
->Version
;};
172 inline PkgIterator
TargetPkg() {return PkgIterator(*Owner
,Owner
->PkgP
+ Dep
->Package
);};
173 inline PkgIterator
SmartTargetPkg() {PkgIterator
R(*Owner
);SmartTargetPkg(R
);return R
;};
174 inline VerIterator
ParentVer() {return VerIterator(*Owner
,Owner
->VerP
+ Dep
->ParentVer
);};
175 inline PkgIterator
ParentPkg() {return PkgIterator(*Owner
,Owner
->PkgP
+ Owner
->VerP
[Dep
->ParentVer
].ParentPkg
);};
176 inline bool Reverse() {return Type
== DepRev
;};
177 inline unsigned long Index() const {return Dep
- Owner
->DepP
;};
179 void GlobOr(DepIterator
&Start
,DepIterator
&End
);
180 Version
**AllTargets();
181 bool SmartTargetPkg(PkgIterator
&Result
);
182 const char *CompType();
183 const char *DepType();
185 inline DepIterator(pkgCache
&Owner
,Dependency
*Trg
,Version
* = 0) :
186 Dep(Trg
), Type(DepVer
), Owner(&Owner
)
191 inline DepIterator(pkgCache
&Owner
,Dependency
*Trg
,Package
*) :
192 Dep(Trg
), Type(DepRev
), Owner(&Owner
)
197 inline DepIterator() : Dep(0), Type(DepVer
), Owner(0) {};
201 class pkgCache::PrvIterator
204 enum {PrvVer
, PrvPkg
} Type
;
212 void operator ++(int) {if (Prv
!= Owner
->ProvideP
) Prv
= Owner
->ProvideP
+
213 (Type
== PrvVer
?Prv
->NextPkgProv
:Prv
->NextProvides
);};
214 inline void operator ++() {operator ++(0);};
215 inline bool end() const {return Prv
== Owner
->ProvideP
?true:false;};
218 inline bool operator ==(const PrvIterator
&B
) const {return Prv
== B
.Prv
;};
219 inline bool operator !=(const PrvIterator
&B
) const {return Prv
!= B
.Prv
;};
222 inline Provides
*operator ->() {return Prv
;};
223 inline Provides
const *operator ->() const {return Prv
;};
224 inline Provides
&operator *() {return *Prv
;};
225 inline Provides
const &operator *() const {return *Prv
;};
226 inline operator Provides
*() {return Prv
== Owner
->ProvideP
?0:Prv
;};
227 inline operator Provides
const *() const {return Prv
== Owner
->ProvideP
?0:Prv
;};
229 inline const char *Name() const {return Owner
->StrP
+ Owner
->PkgP
[Prv
->ParentPkg
].Name
;};
230 inline const char *ProvideVersion() const {return Prv
->ProvideVersion
== 0?0:Owner
->StrP
+ Prv
->ProvideVersion
;};
231 inline PkgIterator
ParentPkg() {return PkgIterator(*Owner
,Owner
->PkgP
+ Prv
->ParentPkg
);};
232 inline VerIterator
OwnerVer() {return VerIterator(*Owner
,Owner
->VerP
+ Prv
->Version
);};
233 inline PkgIterator
OwnerPkg() {return PkgIterator(*Owner
,Owner
->PkgP
+ Owner
->VerP
[Prv
->Version
].ParentPkg
);};
234 inline unsigned long Index() const {return Prv
- Owner
->ProvideP
;};
236 inline PrvIterator(pkgCache
&Owner
,Provides
*Trg
,Version
*) :
237 Prv(Trg
), Type(PrvVer
), Owner(&Owner
)
240 Prv
= Owner
.ProvideP
;
242 inline PrvIterator(pkgCache
&Owner
,Provides
*Trg
,Package
*) :
243 Prv(Trg
), Type(PrvPkg
), Owner(&Owner
)
246 Prv
= Owner
.ProvideP
;
251 class pkgCache::PkgFileIterator
259 void operator ++(int) {if (File
!= Owner
->PkgFileP
) File
= Owner
->PkgFileP
+ File
->NextFile
;};
260 inline void operator ++() {operator ++(0);};
261 inline bool end() const {return File
== Owner
->PkgFileP
?true:false;};
264 inline bool operator ==(const PkgFileIterator
&B
) const {return File
== B
.File
;};
265 inline bool operator !=(const PkgFileIterator
&B
) const {return File
!= B
.File
;};
268 inline PackageFile
*operator ->() {return File
;};
269 inline PackageFile
const *operator ->() const {return File
;};
270 inline PackageFile
const &operator *() const {return *File
;};
271 inline operator PackageFile
*() {return File
== Owner
->PkgFileP
?0:File
;};
272 inline operator PackageFile
const *() const {return File
== Owner
->PkgFileP
?0:File
;};
274 inline const char *FileName() const {return File
->FileName
== 0?0:Owner
->StrP
+ File
->FileName
;};
275 inline const char *Archive() const {return File
->Archive
== 0?0:Owner
->StrP
+ File
->Archive
;};
276 inline const char *Component() const {return File
->Component
== 0?0:Owner
->StrP
+ File
->Component
;};
277 inline const char *Version() const {return File
->Version
== 0?0:Owner
->StrP
+ File
->Version
;};
278 inline const char *Origin() const {return File
->Origin
== 0?0:Owner
->StrP
+ File
->Origin
;};
279 inline const char *Label() const {return File
->Origin
== 0?0:Owner
->StrP
+ File
->Label
;};
280 inline const char *Architecture() const {return File
->Origin
== 0?0:Owner
->StrP
+ File
->Architecture
;};
282 inline unsigned long Index() const {return File
- Owner
->PkgFileP
;};
287 inline PkgFileIterator(pkgCache
&Owner
) : Owner(&Owner
), File(Owner
.PkgFileP
+ Owner
.Head().FileList
) {};
288 inline PkgFileIterator(pkgCache
&Owner
,PackageFile
*Trg
) : Owner(&Owner
), File(Trg
) {};
292 class pkgCache::VerFileIterator
300 void operator ++(int) {if (FileP
!= Owner
->VerFileP
) FileP
= Owner
->VerFileP
+ FileP
->NextFile
;};
301 inline void operator ++() {operator ++(0);};
302 inline bool end() const {return FileP
== Owner
->VerFileP
?true:false;};
305 inline bool operator ==(const VerFileIterator
&B
) const {return FileP
== B
.FileP
;};
306 inline bool operator !=(const VerFileIterator
&B
) const {return FileP
!= B
.FileP
;};
309 inline VerFile
*operator ->() {return FileP
;};
310 inline VerFile
const *operator ->() const {return FileP
;};
311 inline VerFile
const &operator *() const {return *FileP
;};
312 inline operator VerFile
*() {return FileP
== Owner
->VerFileP
?0:FileP
;};
313 inline operator VerFile
const *() const {return FileP
== Owner
->VerFileP
?0:FileP
;};
315 inline PkgFileIterator
File() const {return PkgFileIterator(*Owner
,FileP
->File
+ Owner
->PkgFileP
);};
316 inline unsigned long Index() const {return FileP
- Owner
->VerFileP
;};
318 inline VerFileIterator(pkgCache
&Owner
,VerFile
*Trg
) : Owner(&Owner
), FileP(Trg
) {};
321 // Inlined Begin functions cant be in the class because of order problems
322 inline pkgCache::VerIterator
pkgCache::PkgIterator::VersionList() const
323 {return VerIterator(*Owner
,Owner
->VerP
+ Pkg
->VersionList
);};
324 inline pkgCache::VerIterator
pkgCache::PkgIterator::CurrentVer() const
325 {return VerIterator(*Owner
,Owner
->VerP
+ Pkg
->CurrentVer
);};
326 inline pkgCache::VerIterator
pkgCache::PkgIterator::TargetVer() const
327 {return VerIterator(*Owner
,Owner
->VerP
+ Pkg
->TargetVer
);};
328 inline pkgCache::DepIterator
pkgCache::PkgIterator::RevDependsList() const
329 {return DepIterator(*Owner
,Owner
->DepP
+ Pkg
->RevDepends
,Pkg
);};
330 inline pkgCache::PrvIterator
pkgCache::PkgIterator::ProvidesList() const
331 {return PrvIterator(*Owner
,Owner
->ProvideP
+ Pkg
->ProvidesList
,Pkg
);};
332 inline pkgCache::PrvIterator
pkgCache::VerIterator::ProvidesList() const
333 {return PrvIterator(Owner
,Owner
.ProvideP
+ Ver
->ProvidesList
,Ver
);};
334 inline pkgCache::DepIterator
pkgCache::VerIterator::DependsList() const
335 {return DepIterator(Owner
,Owner
.DepP
+ Ver
->DependsList
,Ver
);};
336 inline pkgCache::VerFileIterator
pkgCache::VerIterator::FileList() const
337 {return VerFileIterator(Owner
,Owner
.VerFileP
+ Ver
->FileList
);};