]>
git.saurik.com Git - apt-legacy.git/blob - apt-pkg/cacheiterators.h
2b326bd65884d995133b2158f04848061ab839c0
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: cacheiterators.h,v 1.18.2.1 2004/05/08 22:44:27 mdz 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 #ifndef PKGLIB_CACHEITERATORS_H
32 #define PKGLIB_CACHEITERATORS_H
35 #pragma interface "apt-pkg/cacheiterators.h"
39 class pkgCache::PkgIterator
41 friend class pkgCache
;
48 // This constructor is the 'begin' constructor, never use it.
49 inline PkgIterator(pkgCache
&Owner
) : Owner(&Owner
), HashIndex(-1)
57 enum OkState
{NeedsNothing
,NeedsUnpack
,NeedsConfigure
};
60 void operator ++(int);
61 inline void operator ++() {operator ++(0);};
62 inline bool end() const {return Owner
== 0 || Pkg
== Owner
->PkgP
?true:false;};
65 inline bool operator ==(const PkgIterator
&B
) const {return Pkg
== B
.Pkg
;};
66 inline bool operator !=(const PkgIterator
&B
) const {return Pkg
!= B
.Pkg
;};
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
;};
74 inline pkgCache
*Cache() {return Owner
;};
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
;};
78 inline bool Purge() const {return Pkg
->CurrentState
== pkgCache::State::Purge
||
79 (Pkg
->CurrentVer
== 0 && Pkg
->CurrentState
== pkgCache::State::NotInstalled
);};
80 inline VerIterator
VersionList() const;
81 inline VerIterator
CurrentVer() const;
82 inline DepIterator
RevDependsList() const;
83 inline PrvIterator
ProvidesList() const;
84 inline unsigned long Index() const {return Pkg
- Owner
->PkgP
;};
85 OkState
State() const;
88 inline PkgIterator(pkgCache
&Owner
,Package
*Trg
) : Pkg(Trg
), Owner(&Owner
),
94 inline PkgIterator() : Pkg(0), Owner(0), HashIndex(0) {};
98 class pkgCache::VerIterator
108 void operator ++(int) {if (Ver
!= Owner
->VerP
) Ver
= Owner
->VerP
+ Ver
->NextVer
;};
109 inline void operator ++() {operator ++(0);};
110 inline bool end() const {return Owner
== NULL
|| (Ver
== Owner
->VerP
?true:false);};
111 inline void operator =(const VerIterator
&B
) {Ver
= B
.Ver
; Owner
= B
.Owner
;};
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;
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
;};
123 inline operator Version
*() {return Ver
== Owner
->VerP
?0:Ver
;};
124 inline operator Version
const *() const {return Ver
== Owner
->VerP
?0:Ver
;};
125 inline pkgCache
*Cache() {return Owner
;};
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
);};
131 inline DepIterator
DependsList() const;
132 inline PrvIterator
ProvidesList() const;
133 inline VerFileIterator
FileList() const;
134 inline unsigned long Index() const {return Ver
- Owner
->VerP
;};
135 bool Downloadable() const;
136 inline const char *PriorityType() {return Owner
->Priority(Ver
->Priority
);};
139 bool Automatic() const;
140 VerFileIterator
NewestFile() const;
142 inline VerIterator() : Ver(0), Owner(0) {};
143 inline VerIterator(pkgCache
&Owner
,Version
*Trg
= 0) : Ver(Trg
),
151 // Dependency iterator
152 class pkgCache::DepIterator
155 enum {DepVer
, DepRev
} Type
;
163 void operator ++(int) {if (Dep
!= Owner
->DepP
) Dep
= Owner
->DepP
+
164 (Type
== DepVer
?Dep
->NextDepends
:Dep
->NextRevDepends
);};
165 inline void operator ++() {operator ++(0);};
166 inline bool end() const {return Owner
== 0 || Dep
== Owner
->DepP
?true:false;};
169 inline bool operator ==(const DepIterator
&B
) const {return Dep
== B
.Dep
;};
170 inline bool operator !=(const DepIterator
&B
) const {return Dep
!= B
.Dep
;};
173 inline Dependency
*operator ->() {return Dep
;};
174 inline Dependency
const *operator ->() const {return Dep
;};
175 inline Dependency
&operator *() {return *Dep
;};
176 inline Dependency
const &operator *() const {return *Dep
;};
177 inline operator Dependency
*() {return Dep
== Owner
->DepP
?0:Dep
;};
178 inline operator Dependency
const *() const {return Dep
== Owner
->DepP
?0:Dep
;};
179 inline pkgCache
*Cache() {return Owner
;};
181 inline const char *TargetVer() const {return Dep
->Version
== 0?0:Owner
->StrP
+ Dep
->Version
;};
182 inline PkgIterator
TargetPkg() {return PkgIterator(*Owner
,Owner
->PkgP
+ Dep
->Package
);};
183 inline PkgIterator
SmartTargetPkg() {PkgIterator
R(*Owner
,0);SmartTargetPkg(R
);return R
;};
184 inline VerIterator
ParentVer() {return VerIterator(*Owner
,Owner
->VerP
+ Dep
->ParentVer
);};
185 inline PkgIterator
ParentPkg() {return PkgIterator(*Owner
,Owner
->PkgP
+ Owner
->VerP
[Dep
->ParentVer
].ParentPkg
);};
186 inline bool Reverse() {return Type
== DepRev
;};
187 inline unsigned long Index() const {return Dep
- Owner
->DepP
;};
189 void GlobOr(DepIterator
&Start
,DepIterator
&End
);
190 Version
**AllTargets();
191 bool SmartTargetPkg(PkgIterator
&Result
);
192 inline const char *CompType() {return Owner
->CompType(Dep
->CompareOp
);};
193 inline const char *DepType() {return Owner
->DepType(Dep
->Type
);};
195 inline DepIterator(pkgCache
&Owner
,Dependency
*Trg
,Version
* = 0) :
196 Dep(Trg
), Type(DepVer
), Owner(&Owner
)
201 inline DepIterator(pkgCache
&Owner
,Dependency
*Trg
,Package
*) :
202 Dep(Trg
), Type(DepRev
), Owner(&Owner
)
207 inline DepIterator() : Dep(0), Type(DepVer
), Owner(0) {};
211 class pkgCache::PrvIterator
214 enum {PrvVer
, PrvPkg
} Type
;
222 void operator ++(int) {if (Prv
!= Owner
->ProvideP
) Prv
= Owner
->ProvideP
+
223 (Type
== PrvVer
?Prv
->NextPkgProv
:Prv
->NextProvides
);};
224 inline void operator ++() {operator ++(0);};
225 inline bool end() const {return Owner
== 0 || Prv
== Owner
->ProvideP
?true:false;};
228 inline bool operator ==(const PrvIterator
&B
) const {return Prv
== B
.Prv
;};
229 inline bool operator !=(const PrvIterator
&B
) const {return Prv
!= B
.Prv
;};
232 inline Provides
*operator ->() {return Prv
;};
233 inline Provides
const *operator ->() const {return Prv
;};
234 inline Provides
&operator *() {return *Prv
;};
235 inline Provides
const &operator *() const {return *Prv
;};
236 inline operator Provides
*() {return Prv
== Owner
->ProvideP
?0:Prv
;};
237 inline operator Provides
const *() const {return Prv
== Owner
->ProvideP
?0:Prv
;};
238 inline pkgCache
*Cache() {return Owner
;};
240 inline const char *Name() const {return Owner
->StrP
+ Owner
->PkgP
[Prv
->ParentPkg
].Name
;};
241 inline const char *ProvideVersion() const {return Prv
->ProvideVersion
== 0?0:Owner
->StrP
+ Prv
->ProvideVersion
;};
242 inline PkgIterator
ParentPkg() {return PkgIterator(*Owner
,Owner
->PkgP
+ Prv
->ParentPkg
);};
243 inline VerIterator
OwnerVer() {return VerIterator(*Owner
,Owner
->VerP
+ Prv
->Version
);};
244 inline PkgIterator
OwnerPkg() {return PkgIterator(*Owner
,Owner
->PkgP
+ Owner
->VerP
[Prv
->Version
].ParentPkg
);};
245 inline unsigned long Index() const {return Prv
- Owner
->ProvideP
;};
247 inline PrvIterator() : Prv(0), Type(PrvVer
), Owner(0) {};
249 inline PrvIterator(pkgCache
&Owner
,Provides
*Trg
,Version
*) :
250 Prv(Trg
), Type(PrvVer
), Owner(&Owner
)
253 Prv
= Owner
.ProvideP
;
255 inline PrvIterator(pkgCache
&Owner
,Provides
*Trg
,Package
*) :
256 Prv(Trg
), Type(PrvPkg
), Owner(&Owner
)
259 Prv
= Owner
.ProvideP
;
264 class pkgCache::PkgFileIterator
272 void operator ++(int) {if (File
!= Owner
->PkgFileP
) File
= Owner
->PkgFileP
+ File
->NextFile
;};
273 inline void operator ++() {operator ++(0);};
274 inline bool end() const {return File
== Owner
->PkgFileP
?true:false;};
277 inline bool operator ==(const PkgFileIterator
&B
) const {return File
== B
.File
;};
278 inline bool operator !=(const PkgFileIterator
&B
) const {return File
!= B
.File
;};
281 inline PackageFile
*operator ->() {return File
;};
282 inline PackageFile
const *operator ->() const {return File
;};
283 inline PackageFile
const &operator *() const {return *File
;};
284 inline operator PackageFile
*() {return File
== Owner
->PkgFileP
?0:File
;};
285 inline operator PackageFile
const *() const {return File
== Owner
->PkgFileP
?0:File
;};
286 inline pkgCache
*Cache() {return Owner
;};
288 inline const char *FileName() const {return File
->FileName
== 0?0:Owner
->StrP
+ File
->FileName
;};
289 inline const char *Archive() const {return File
->Archive
== 0?0:Owner
->StrP
+ File
->Archive
;};
290 inline const char *Component() const {return File
->Component
== 0?0:Owner
->StrP
+ File
->Component
;};
291 inline const char *Version() const {return File
->Version
== 0?0:Owner
->StrP
+ File
->Version
;};
292 inline const char *Origin() const {return File
->Origin
== 0?0:Owner
->StrP
+ File
->Origin
;};
293 inline const char *Label() const {return File
->Label
== 0?0:Owner
->StrP
+ File
->Label
;};
294 inline const char *Site() const {return File
->Site
== 0?0:Owner
->StrP
+ File
->Site
;};
295 inline const char *Architecture() const {return File
->Architecture
== 0?0:Owner
->StrP
+ File
->Architecture
;};
296 inline const char *IndexType() const {return File
->IndexType
== 0?0:Owner
->StrP
+ File
->IndexType
;};
298 inline unsigned long Index() const {return File
- Owner
->PkgFileP
;};
304 inline PkgFileIterator() : Owner(0), File(0) {};
305 inline PkgFileIterator(pkgCache
&Owner
) : Owner(&Owner
), File(Owner
.PkgFileP
) {};
306 inline PkgFileIterator(pkgCache
&Owner
,PackageFile
*Trg
) : Owner(&Owner
), File(Trg
) {};
310 class pkgCache::VerFileIterator
318 void operator ++(int) {if (FileP
!= Owner
->VerFileP
) FileP
= Owner
->VerFileP
+ FileP
->NextFile
;};
319 inline void operator ++() {operator ++(0);};
320 inline bool end() const {return FileP
== Owner
->VerFileP
?true:false;};
323 inline bool operator ==(const VerFileIterator
&B
) const {return FileP
== B
.FileP
;};
324 inline bool operator !=(const VerFileIterator
&B
) const {return FileP
!= B
.FileP
;};
327 inline VerFile
*operator ->() {return FileP
;};
328 inline VerFile
const *operator ->() const {return FileP
;};
329 inline VerFile
const &operator *() const {return *FileP
;};
330 inline operator VerFile
*() {return FileP
== Owner
->VerFileP
?0:FileP
;};
331 inline operator VerFile
const *() const {return FileP
== Owner
->VerFileP
?0:FileP
;};
332 inline pkgCache
*Cache() {return Owner
;};
334 inline PkgFileIterator
File() const {return PkgFileIterator(*Owner
,FileP
->File
+ Owner
->PkgFileP
);};
335 inline unsigned long Index() const {return FileP
- Owner
->VerFileP
;};
337 inline VerFileIterator() : Owner(0), FileP(0) {};
338 inline VerFileIterator(pkgCache
&Owner
,VerFile
*Trg
) : Owner(&Owner
), FileP(Trg
) {};
341 // Inlined Begin functions cant be in the class because of order problems
342 inline pkgCache::VerIterator
pkgCache::PkgIterator::VersionList() const
343 {return VerIterator(*Owner
,Owner
->VerP
+ Pkg
->VersionList
);};
344 inline pkgCache::VerIterator
pkgCache::PkgIterator::CurrentVer() const
345 {return VerIterator(*Owner
,Owner
->VerP
+ Pkg
->CurrentVer
);};
346 inline pkgCache::DepIterator
pkgCache::PkgIterator::RevDependsList() const
347 {return DepIterator(*Owner
,Owner
->DepP
+ Pkg
->RevDepends
,Pkg
);};
348 inline pkgCache::PrvIterator
pkgCache::PkgIterator::ProvidesList() const
349 {return PrvIterator(*Owner
,Owner
->ProvideP
+ Pkg
->ProvidesList
,Pkg
);};
350 inline pkgCache::PrvIterator
pkgCache::VerIterator::ProvidesList() const
351 {return PrvIterator(*Owner
,Owner
->ProvideP
+ Ver
->ProvidesList
,Ver
);};
352 inline pkgCache::DepIterator
pkgCache::VerIterator::DependsList() const
353 {return DepIterator(*Owner
,Owner
->DepP
+ Ver
->DependsList
,Ver
);};
354 inline pkgCache::VerFileIterator
pkgCache::VerIterator::FileList() const
355 {return VerFileIterator(*Owner
,Owner
->VerFileP
+ Ver
->FileList
);};