]> git.saurik.com Git - apt.git/blame - apt-pkg/cacheiterators.h
More fixes
[apt.git] / apt-pkg / cacheiterators.h
CommitLineData
578bfd0a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
e3bf76d1 3// $Id: cacheiterators.h,v 1.15 1999/07/30 04:08:42 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;};
e3bf76d1
AL
69 inline bool Purge() const {return Pkg->CurrentState == pkgCache::State::Purge ||
70 (Pkg->CurrentVer == 0 && Pkg->CurrentState == pkgCache::State::NotInstalled);};
578bfd0a
AL
71 inline VerIterator VersionList() const;
72 inline VerIterator TargetVer() const;
73 inline VerIterator CurrentVer() const;
74 inline DepIterator RevDependsList() const;
75 inline PrvIterator ProvidesList() const;
f55a958f 76 inline unsigned long Index() const {return Pkg - Owner->PkgP;};
578bfd0a
AL
77 OkState State() const;
78
79 // Constructors
80 inline PkgIterator(pkgCache &Owner) : Owner(&Owner), HashIndex(-1)
81 {
82 Pkg = Owner.PkgP;
83 operator ++(0);
84 };
85 inline PkgIterator(pkgCache &Owner,Package *Trg) : Pkg(Trg), Owner(&Owner),
86 HashIndex(0)
87 {
88 if (Pkg == 0)
89 Pkg = Owner.PkgP;
90 };
91 inline PkgIterator() : Pkg(0), Owner(0), HashIndex(0) {};
92};
93
94// Version Iterator
95class pkgCache::VerIterator
96{
97 Version *Ver;
f9eec0e7 98 pkgCache *Owner;
578bfd0a
AL
99
100 void _dummy();
101
102 public:
103
104 // Iteration
f9eec0e7 105 void operator ++(int) {if (Ver != Owner->VerP) Ver = Owner->VerP + Ver->NextVer;};
578bfd0a 106 inline void operator ++() {operator ++(0);};
f9eec0e7
AL
107 inline bool end() const {return Ver == Owner->VerP?true:false;};
108 inline void operator =(const VerIterator &B) {Ver = B.Ver; Owner = B.Owner;};
578bfd0a
AL
109
110 // Comparison
111 inline bool operator ==(const VerIterator &B) const {return Ver == B.Ver;};
112 inline bool operator !=(const VerIterator &B) const {return Ver != B.Ver;};
113 int CompareVer(const VerIterator &B) const;
114
115 // Accessors
116 inline Version *operator ->() {return Ver;};
117 inline Version const *operator ->() const {return Ver;};
118 inline Version &operator *() {return *Ver;};
119 inline Version const &operator *() const {return *Ver;};
f9eec0e7
AL
120 inline operator Version *() {return Ver == Owner->VerP?0:Ver;};
121 inline operator Version const *() const {return Ver == Owner->VerP?0:Ver;};
c9807169 122
f9eec0e7
AL
123 inline const char *VerStr() const {return Ver->VerStr == 0?0:Owner->StrP + Ver->VerStr;};
124 inline const char *Section() const {return Ver->Section == 0?0:Owner->StrP + Ver->Section;};
125 inline const char *Arch() const {return Ver->Arch == 0?0:Owner->StrP + Ver->Arch;};
126 inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + Ver->ParentPkg);};
578bfd0a
AL
127 inline DepIterator DependsList() const;
128 inline PrvIterator ProvidesList() const;
dcb79bae 129 inline VerFileIterator FileList() const;
f9eec0e7 130 inline unsigned long Index() const {return Ver - Owner->VerP;};
b518cca6 131 bool Downloadable() const;
c9807169 132 const char *PriorityType();
3c124dde
AL
133
134 bool Automatic() const;
135 VerFileIterator NewestFile() const;
f9eec0e7
AL
136
137 inline VerIterator() : Ver(0), Owner(0) {};
138 inline VerIterator(pkgCache &Owner,Version *Trg = 0) : Ver(Trg),
139 Owner(&Owner)
578bfd0a
AL
140 {
141 if (Ver == 0)
142 Ver = Owner.VerP;
143 };
144};
145
146// Dependency iterator
147class pkgCache::DepIterator
148{
149 Dependency *Dep;
150 enum {DepVer, DepRev} Type;
151 pkgCache *Owner;
152
153 void _dummy();
154
155 public:
156
157 // Iteration
158 void operator ++(int) {if (Dep != Owner->DepP) Dep = Owner->DepP +
159 (Type == DepVer?Dep->NextDepends:Dep->NextRevDepends);};
160 inline void operator ++() {operator ++(0);};
161 inline bool end() const {return Owner == 0 || Dep == Owner->DepP?true:false;};
162
163 // Comparison
164 inline bool operator ==(const DepIterator &B) const {return Dep == B.Dep;};
165 inline bool operator !=(const DepIterator &B) const {return Dep != B.Dep;};
166
167 // Accessors
168 inline Dependency *operator ->() {return Dep;};
169 inline Dependency const *operator ->() const {return Dep;};
170 inline Dependency &operator *() {return *Dep;};
171 inline Dependency const &operator *() const {return *Dep;};
172 inline operator Dependency *() {return Dep == Owner->DepP?0:Dep;};
173 inline operator Dependency const *() const {return Dep == Owner->DepP?0:Dep;};
6c139d6e 174
578bfd0a
AL
175 inline const char *TargetVer() const {return Dep->Version == 0?0:Owner->StrP + Dep->Version;};
176 inline PkgIterator TargetPkg() {return PkgIterator(*Owner,Owner->PkgP + Dep->Package);};
578bfd0a
AL
177 inline PkgIterator SmartTargetPkg() {PkgIterator R(*Owner);SmartTargetPkg(R);return R;};
178 inline VerIterator ParentVer() {return VerIterator(*Owner,Owner->VerP + Dep->ParentVer);};
179 inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Dep->ParentVer].ParentPkg);};
578bfd0a 180 inline bool Reverse() {return Type == DepRev;};
f55a958f 181 inline unsigned long Index() const {return Dep - Owner->DepP;};
6c139d6e 182 bool IsCritical();
43d017d6 183 void GlobOr(DepIterator &Start,DepIterator &End);
6c139d6e
AL
184 Version **AllTargets();
185 bool SmartTargetPkg(PkgIterator &Result);
0a8e3465 186 const char *CompType();
43d017d6 187 const char *DepType();
0a8e3465 188
578bfd0a
AL
189 inline DepIterator(pkgCache &Owner,Dependency *Trg,Version * = 0) :
190 Dep(Trg), Type(DepVer), Owner(&Owner)
191 {
192 if (Dep == 0)
193 Dep = Owner.DepP;
194 };
195 inline DepIterator(pkgCache &Owner,Dependency *Trg,Package *) :
196 Dep(Trg), Type(DepRev), Owner(&Owner)
197 {
198 if (Dep == 0)
199 Dep = Owner.DepP;
200 };
201 inline DepIterator() : Dep(0), Type(DepVer), Owner(0) {};
202};
203
204// Provides iterator
205class pkgCache::PrvIterator
206{
207 Provides *Prv;
208 enum {PrvVer, PrvPkg} Type;
209 pkgCache *Owner;
210
211 void _dummy();
212
213 public:
214
215 // Iteration
216 void operator ++(int) {if (Prv != Owner->ProvideP) Prv = Owner->ProvideP +
217 (Type == PrvVer?Prv->NextPkgProv:Prv->NextProvides);};
218 inline void operator ++() {operator ++(0);};
219 inline bool end() const {return Prv == Owner->ProvideP?true:false;};
220
221 // Comparison
222 inline bool operator ==(const PrvIterator &B) const {return Prv == B.Prv;};
223 inline bool operator !=(const PrvIterator &B) const {return Prv != B.Prv;};
224
225 // Accessors
226 inline Provides *operator ->() {return Prv;};
227 inline Provides const *operator ->() const {return Prv;};
228 inline Provides &operator *() {return *Prv;};
229 inline Provides const &operator *() const {return *Prv;};
230 inline operator Provides *() {return Prv == Owner->ProvideP?0:Prv;};
231 inline operator Provides const *() const {return Prv == Owner->ProvideP?0:Prv;};
6c139d6e 232
578bfd0a
AL
233 inline const char *Name() const {return Owner->StrP + Owner->PkgP[Prv->ParentPkg].Name;};
234 inline const char *ProvideVersion() const {return Prv->ProvideVersion == 0?0:Owner->StrP + Prv->ProvideVersion;};
235 inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Prv->ParentPkg);};
236 inline VerIterator OwnerVer() {return VerIterator(*Owner,Owner->VerP + Prv->Version);};
237 inline PkgIterator OwnerPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Prv->Version].ParentPkg);};
f55a958f 238 inline unsigned long Index() const {return Prv - Owner->ProvideP;};
578bfd0a
AL
239
240 inline PrvIterator(pkgCache &Owner,Provides *Trg,Version *) :
241 Prv(Trg), Type(PrvVer), Owner(&Owner)
242 {
243 if (Prv == 0)
244 Prv = Owner.ProvideP;
245 };
246 inline PrvIterator(pkgCache &Owner,Provides *Trg,Package *) :
247 Prv(Trg), Type(PrvPkg), Owner(&Owner)
248 {
249 if (Prv == 0)
250 Prv = Owner.ProvideP;
251 };
252};
253
254// Package file
255class pkgCache::PkgFileIterator
256{
257 pkgCache *Owner;
258 PackageFile *File;
259
260 public:
261
262 // Iteration
263 void operator ++(int) {if (File!= Owner->PkgFileP) File = Owner->PkgFileP + File->NextFile;};
264 inline void operator ++() {operator ++(0);};
265 inline bool end() const {return File == Owner->PkgFileP?true:false;};
266
267 // Comparison
268 inline bool operator ==(const PkgFileIterator &B) const {return File == B.File;};
269 inline bool operator !=(const PkgFileIterator &B) const {return File != B.File;};
270
271 // Accessors
272 inline PackageFile *operator ->() {return File;};
273 inline PackageFile const *operator ->() const {return File;};
274 inline PackageFile const &operator *() const {return *File;};
275 inline operator PackageFile *() {return File == Owner->PkgFileP?0:File;};
276 inline operator PackageFile const *() const {return File == Owner->PkgFileP?0:File;};
277
278 inline const char *FileName() const {return File->FileName == 0?0:Owner->StrP + File->FileName;};
b0b4efb9
AL
279 inline const char *Archive() const {return File->Archive == 0?0:Owner->StrP + File->Archive;};
280 inline const char *Component() const {return File->Component == 0?0:Owner->StrP + File->Component;};
578bfd0a 281 inline const char *Version() const {return File->Version == 0?0:Owner->StrP + File->Version;};
b0b4efb9
AL
282 inline const char *Origin() const {return File->Origin == 0?0:Owner->StrP + File->Origin;};
283 inline const char *Label() const {return File->Origin == 0?0:Owner->StrP + File->Label;};
284 inline const char *Architecture() const {return File->Origin == 0?0:Owner->StrP + File->Architecture;};
285
f55a958f 286 inline unsigned long Index() const {return File - Owner->PkgFileP;};
578bfd0a
AL
287
288 bool IsOk();
289
290 // Constructors
291 inline PkgFileIterator(pkgCache &Owner) : Owner(&Owner), File(Owner.PkgFileP + Owner.Head().FileList) {};
292 inline PkgFileIterator(pkgCache &Owner,PackageFile *Trg) : Owner(&Owner), File(Trg) {};
293};
294
dcb79bae
AL
295// Version File
296class pkgCache::VerFileIterator
297{
298 pkgCache *Owner;
299 VerFile *FileP;
300
301 public:
302
303 // Iteration
304 void operator ++(int) {if (FileP != Owner->VerFileP) FileP = Owner->VerFileP + FileP->NextFile;};
305 inline void operator ++() {operator ++(0);};
306 inline bool end() const {return FileP == Owner->VerFileP?true:false;};
307
308 // Comparison
309 inline bool operator ==(const VerFileIterator &B) const {return FileP == B.FileP;};
310 inline bool operator !=(const VerFileIterator &B) const {return FileP != B.FileP;};
311
312 // Accessors
313 inline VerFile *operator ->() {return FileP;};
314 inline VerFile const *operator ->() const {return FileP;};
315 inline VerFile const &operator *() const {return *FileP;};
316 inline operator VerFile *() {return FileP == Owner->VerFileP?0:FileP;};
317 inline operator VerFile const *() const {return FileP == Owner->VerFileP?0:FileP;};
318
319 inline PkgFileIterator File() const {return PkgFileIterator(*Owner,FileP->File + Owner->PkgFileP);};
320 inline unsigned long Index() const {return FileP - Owner->VerFileP;};
b518cca6 321
dcb79bae
AL
322 inline VerFileIterator(pkgCache &Owner,VerFile *Trg) : Owner(&Owner), FileP(Trg) {};
323};
324
578bfd0a
AL
325// Inlined Begin functions cant be in the class because of order problems
326inline pkgCache::VerIterator pkgCache::PkgIterator::VersionList() const
327 {return VerIterator(*Owner,Owner->VerP + Pkg->VersionList);};
328inline pkgCache::VerIterator pkgCache::PkgIterator::CurrentVer() const
329 {return VerIterator(*Owner,Owner->VerP + Pkg->CurrentVer);};
330inline pkgCache::VerIterator pkgCache::PkgIterator::TargetVer() const
331 {return VerIterator(*Owner,Owner->VerP + Pkg->TargetVer);};
332inline pkgCache::DepIterator pkgCache::PkgIterator::RevDependsList() const
333 {return DepIterator(*Owner,Owner->DepP + Pkg->RevDepends,Pkg);};
334inline pkgCache::PrvIterator pkgCache::PkgIterator::ProvidesList() const
335 {return PrvIterator(*Owner,Owner->ProvideP + Pkg->ProvidesList,Pkg);};
336inline pkgCache::PrvIterator pkgCache::VerIterator::ProvidesList() const
f9eec0e7 337 {return PrvIterator(*Owner,Owner->ProvideP + Ver->ProvidesList,Ver);};
578bfd0a 338inline pkgCache::DepIterator pkgCache::VerIterator::DependsList() const
f9eec0e7 339 {return DepIterator(*Owner,Owner->DepP + Ver->DependsList,Ver);};
dcb79bae 340inline pkgCache::VerFileIterator pkgCache::VerIterator::FileList() const
f9eec0e7 341 {return VerFileIterator(*Owner,Owner->VerFileP + Ver->FileList);};
578bfd0a
AL
342
343#endif