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