]> git.saurik.com Git - apt-legacy.git/blob - apt-pkg/cacheiterators.h.orig
I feel... vindicated?
[apt-legacy.git] / apt-pkg / cacheiterators.h.orig
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: cacheiterators.h,v 1.18.2.1 2004/05/08 22:44:27 mdz Exp $
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
24 that has the depends pointer as a member. The provide iterator has the
25 same system.
26
27 This header is not user includable, please use apt-pkg/pkgcache.h
28
29 ##################################################################### */
30 /*}}}*/
31 #ifndef PKGLIB_CACHEITERATORS_H
32 #define PKGLIB_CACHEITERATORS_H
33
34
35 // Package Iterator
36 class pkgCache::PkgIterator
37 {
38 friend class pkgCache;
39 Package *Pkg;
40 pkgCache *Owner;
41 long HashIndex;
42
43 protected:
44
45 // This constructor is the 'begin' constructor, never use it.
46 inline PkgIterator(pkgCache &Owner) : Owner(&Owner), HashIndex(-1)
47 {
48 Pkg = Owner.PkgP;
49 operator ++(0);
50 };
51
52 public:
53
54 enum OkState {NeedsNothing,NeedsUnpack,NeedsConfigure};
55
56 // Iteration
57 void operator ++(int);
58 inline void operator ++() {operator ++(0);};
59 inline bool end() const {return Owner == 0 || Pkg == Owner->PkgP?true:false;};
60
61 // Comparison
62 inline bool operator ==(const PkgIterator &B) const {return Pkg == B.Pkg;};
63 inline bool operator !=(const PkgIterator &B) const {return Pkg != B.Pkg;};
64
65 // Accessors
66 inline Package *operator ->() {return Pkg;};
67 inline Package const *operator ->() const {return Pkg;};
68 inline Package const &operator *() const {return *Pkg;};
69 inline operator Package *() {return Pkg == Owner->PkgP?0:Pkg;};
70 inline operator Package const *() const {return Pkg == Owner->PkgP?0:Pkg;};
71 inline pkgCache *Cache() {return Owner;};
72
73 inline const char *Name() const {return Pkg->Name == 0?0:Owner->StrP + Pkg->Name;};
74 inline const char *Display() const {return Pkg->Display == 0?0:Owner->StrP + Pkg->Display;};
75 inline const char *Section() const {return Pkg->Section == 0?0:Owner->StrP + Pkg->Section;};
76 inline bool Purge() const {return Pkg->CurrentState == pkgCache::State::Purge ||
77 (Pkg->CurrentVer == 0 && Pkg->CurrentState == pkgCache::State::NotInstalled);};
78 inline VerIterator VersionList() const;
79 inline VerIterator CurrentVer() const;
80 inline DepIterator RevDependsList() const;
81 inline PrvIterator ProvidesList() const;
82 inline unsigned long Index() const {return Pkg - Owner->PkgP;};
83 OkState State() const;
84
85 // Constructors
86 inline PkgIterator(pkgCache &Owner,Package *Trg) : Pkg(Trg), Owner(&Owner),
87 HashIndex(0)
88 {
89 if (Pkg == 0)
90 Pkg = Owner.PkgP;
91 };
92 inline PkgIterator() : Pkg(0), Owner(0), HashIndex(0) {};
93 };
94
95 // Version Iterator
96 class pkgCache::VerIterator
97 {
98 Version *Ver;
99 pkgCache *Owner;
100
101 void _dummy();
102
103 public:
104
105 // Iteration
106 void operator ++(int) {if (Ver != Owner->VerP) Ver = Owner->VerP + Ver->NextVer;};
107 inline void operator ++() {operator ++(0);};
108 inline bool end() const {return Owner == NULL || (Ver == Owner->VerP?true:false);};
109 inline void operator =(const VerIterator &B) {Ver = B.Ver; Owner = B.Owner;};
110
111 // Comparison
112 inline bool operator ==(const VerIterator &B) const {return Ver == B.Ver;};
113 inline bool operator !=(const VerIterator &B) const {return Ver != B.Ver;};
114 int CompareVer(const VerIterator &B) const;
115
116 // Accessors
117 inline Version *operator ->() {return Ver;};
118 inline Version const *operator ->() const {return Ver;};
119 inline Version &operator *() {return *Ver;};
120 inline Version const &operator *() const {return *Ver;};
121 inline operator Version *() {return Ver == Owner->VerP?0:Ver;};
122 inline operator Version const *() const {return Ver == Owner->VerP?0:Ver;};
123 inline pkgCache *Cache() {return Owner;};
124
125 inline const char *VerStr() const {return Ver->VerStr == 0?0:Owner->StrP + Ver->VerStr;};
126 inline const char *Display() const {return Ver->Display == 0?0:Owner->StrP + Ver->Display;};
127 inline const char *Section() const {return Ver->Section == 0?0:Owner->StrP + Ver->Section;};
128 inline const char *Arch() const {return Ver->Arch == 0?0:Owner->StrP + Ver->Arch;};
129 inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + Ver->ParentPkg);};
130 inline DescIterator DescriptionList() const;
131 DescIterator TranslatedDescription() const;
132 inline DepIterator DependsList() const;
133 inline PrvIterator ProvidesList() const;
134 inline VerFileIterator FileList() const;
135 inline unsigned long Index() const {return Ver - Owner->VerP;};
136 bool Downloadable() const;
137 inline const char *PriorityType() {return Owner->Priority(Ver->Priority);};
138 string RelStr();
139
140 bool Automatic() const;
141 VerFileIterator NewestFile() const;
142
143 inline VerIterator() : Ver(0), Owner(0) {};
144 inline VerIterator(pkgCache &Owner,Version *Trg = 0) : Ver(Trg),
145 Owner(&Owner)
146 {
147 if (Ver == 0)
148 Ver = Owner.VerP;
149 };
150 };
151
152 // Description Iterator
153 class pkgCache::DescIterator
154 {
155 Description *Desc;
156 pkgCache *Owner;
157
158 void _dummy();
159
160 public:
161
162 // Iteration
163 void operator ++(int) {if (Desc != Owner->DescP) Desc = Owner->DescP + Desc->NextDesc;};
164 inline void operator ++() {operator ++(0);};
165 inline bool end() const {return Desc == Owner->DescP?true:false;};
166 inline void operator =(const DescIterator &B) {Desc = B.Desc; Owner = B.Owner;};
167
168 // Comparison
169 inline bool operator ==(const DescIterator &B) const {return Desc == B.Desc;};
170 inline bool operator !=(const DescIterator &B) const {return Desc != B.Desc;};
171 int CompareDesc(const DescIterator &B) const;
172
173 // Accessors
174 inline Description *operator ->() {return Desc;};
175 inline Description const *operator ->() const {return Desc;};
176 inline Description &operator *() {return *Desc;};
177 inline Description const &operator *() const {return *Desc;};
178 inline operator Description *() {return Desc == Owner->DescP?0:Desc;};
179 inline operator Description const *() const {return Desc == Owner->DescP?0:Desc;};
180 inline pkgCache *Cache() {return Owner;};
181
182 inline const char *LanguageCode() const {return Owner->StrP + Desc->language_code;};
183 inline const char *md5() const {return Owner->StrP + Desc->md5sum;};
184 inline DescFileIterator FileList() const;
185 inline unsigned long Index() const {return Desc - Owner->DescP;};
186
187 inline DescIterator() : Desc(0), Owner(0) {};
188 inline DescIterator(pkgCache &Owner,Description *Trg = 0) : Desc(Trg),
189 Owner(&Owner)
190 {
191 if (Desc == 0)
192 Desc = Owner.DescP;
193 };
194 };
195
196 // Dependency iterator
197 class pkgCache::DepIterator
198 {
199 Dependency *Dep;
200 enum {DepVer, DepRev} Type;
201 pkgCache *Owner;
202
203 void _dummy();
204
205 public:
206
207 // Iteration
208 void operator ++(int) {if (Dep != Owner->DepP) Dep = Owner->DepP +
209 (Type == DepVer?Dep->NextDepends:Dep->NextRevDepends);};
210 inline void operator ++() {operator ++(0);};
211 inline bool end() const {return Owner == 0 || Dep == Owner->DepP?true:false;};
212
213 // Comparison
214 inline bool operator ==(const DepIterator &B) const {return Dep == B.Dep;};
215 inline bool operator !=(const DepIterator &B) const {return Dep != B.Dep;};
216
217 // Accessors
218 inline Dependency *operator ->() {return Dep;};
219 inline Dependency const *operator ->() const {return Dep;};
220 inline Dependency &operator *() {return *Dep;};
221 inline Dependency const &operator *() const {return *Dep;};
222 inline operator Dependency *() {return Dep == Owner->DepP?0:Dep;};
223 inline operator Dependency const *() const {return Dep == Owner->DepP?0:Dep;};
224 inline pkgCache *Cache() {return Owner;};
225
226 inline const char *TargetVer() const {return Dep->Version == 0?0:Owner->StrP + Dep->Version;};
227 inline PkgIterator TargetPkg() {return PkgIterator(*Owner,Owner->PkgP + Dep->Package);};
228 inline PkgIterator SmartTargetPkg() {PkgIterator R(*Owner,0);SmartTargetPkg(R);return R;};
229 inline VerIterator ParentVer() {return VerIterator(*Owner,Owner->VerP + Dep->ParentVer);};
230 inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Dep->ParentVer].ParentPkg);};
231 inline bool Reverse() {return Type == DepRev;};
232 inline unsigned long Index() const {return Dep - Owner->DepP;};
233 bool IsCritical();
234 void GlobOr(DepIterator &Start,DepIterator &End);
235 Version **AllTargets();
236 bool SmartTargetPkg(PkgIterator &Result);
237 inline const char *CompType() {return Owner->CompType(Dep->CompareOp);};
238 inline const char *DepType() {return Owner->DepType(Dep->Type);};
239
240 inline DepIterator(pkgCache &Owner,Dependency *Trg,Version * = 0) :
241 Dep(Trg), Type(DepVer), Owner(&Owner)
242 {
243 if (Dep == 0)
244 Dep = Owner.DepP;
245 };
246 inline DepIterator(pkgCache &Owner,Dependency *Trg,Package *) :
247 Dep(Trg), Type(DepRev), Owner(&Owner)
248 {
249 if (Dep == 0)
250 Dep = Owner.DepP;
251 };
252 inline DepIterator() : Dep(0), Type(DepVer), Owner(0) {};
253 };
254
255 // Provides iterator
256 class pkgCache::PrvIterator
257 {
258 Provides *Prv;
259 enum {PrvVer, PrvPkg} Type;
260 pkgCache *Owner;
261
262 void _dummy();
263
264 public:
265
266 // Iteration
267 void operator ++(int) {if (Prv != Owner->ProvideP) Prv = Owner->ProvideP +
268 (Type == PrvVer?Prv->NextPkgProv:Prv->NextProvides);};
269 inline void operator ++() {operator ++(0);};
270 inline bool end() const {return Owner == 0 || Prv == Owner->ProvideP?true:false;};
271
272 // Comparison
273 inline bool operator ==(const PrvIterator &B) const {return Prv == B.Prv;};
274 inline bool operator !=(const PrvIterator &B) const {return Prv != B.Prv;};
275
276 // Accessors
277 inline Provides *operator ->() {return Prv;};
278 inline Provides const *operator ->() const {return Prv;};
279 inline Provides &operator *() {return *Prv;};
280 inline Provides const &operator *() const {return *Prv;};
281 inline operator Provides *() {return Prv == Owner->ProvideP?0:Prv;};
282 inline operator Provides const *() const {return Prv == Owner->ProvideP?0:Prv;};
283 inline pkgCache *Cache() {return Owner;};
284
285 inline const char *Name() const {return Owner->StrP + Owner->PkgP[Prv->ParentPkg].Name;};
286 inline const char *ProvideVersion() const {return Prv->ProvideVersion == 0?0:Owner->StrP + Prv->ProvideVersion;};
287 inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Prv->ParentPkg);};
288 inline VerIterator OwnerVer() {return VerIterator(*Owner,Owner->VerP + Prv->Version);};
289 inline PkgIterator OwnerPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Prv->Version].ParentPkg);};
290 inline unsigned long Index() const {return Prv - Owner->ProvideP;};
291
292 inline PrvIterator() : Prv(0), Type(PrvVer), Owner(0) {};
293
294 inline PrvIterator(pkgCache &Owner,Provides *Trg,Version *) :
295 Prv(Trg), Type(PrvVer), Owner(&Owner)
296 {
297 if (Prv == 0)
298 Prv = Owner.ProvideP;
299 };
300 inline PrvIterator(pkgCache &Owner,Provides *Trg,Package *) :
301 Prv(Trg), Type(PrvPkg), Owner(&Owner)
302 {
303 if (Prv == 0)
304 Prv = Owner.ProvideP;
305 };
306 };
307
308 // Package file
309 class pkgCache::PkgFileIterator
310 {
311 pkgCache *Owner;
312 PackageFile *File;
313
314 public:
315
316 // Iteration
317 void operator ++(int) {if (File!= Owner->PkgFileP) File = Owner->PkgFileP + File->NextFile;};
318 inline void operator ++() {operator ++(0);};
319 inline bool end() const {return File == Owner->PkgFileP?true:false;};
320
321 // Comparison
322 inline bool operator ==(const PkgFileIterator &B) const {return File == B.File;};
323 inline bool operator !=(const PkgFileIterator &B) const {return File != B.File;};
324
325 // Accessors
326 inline PackageFile *operator ->() {return File;};
327 inline PackageFile const *operator ->() const {return File;};
328 inline PackageFile const &operator *() const {return *File;};
329 inline operator PackageFile *() {return File == Owner->PkgFileP?0:File;};
330 inline operator PackageFile const *() const {return File == Owner->PkgFileP?0:File;};
331 inline pkgCache *Cache() {return Owner;};
332
333 inline const char *FileName() const {return File->FileName == 0?0:Owner->StrP + File->FileName;};
334 inline const char *Archive() const {return File->Archive == 0?0:Owner->StrP + File->Archive;};
335 inline const char *Component() const {return File->Component == 0?0:Owner->StrP + File->Component;};
336 inline const char *Version() const {return File->Version == 0?0:Owner->StrP + File->Version;};
337 inline const char *Origin() const {return File->Origin == 0?0:Owner->StrP + File->Origin;};
338 inline const char *Label() const {return File->Label == 0?0:Owner->StrP + File->Label;};
339 inline const char *Site() const {return File->Site == 0?0:Owner->StrP + File->Site;};
340 inline const char *Architecture() const {return File->Architecture == 0?0:Owner->StrP + File->Architecture;};
341 inline const char *IndexType() const {return File->IndexType == 0?0:Owner->StrP + File->IndexType;};
342
343 inline unsigned long Index() const {return File - Owner->PkgFileP;};
344
345 bool IsOk();
346 string RelStr();
347
348 // Constructors
349 inline PkgFileIterator() : Owner(0), File(0) {};
350 inline PkgFileIterator(pkgCache &Owner) : Owner(&Owner), File(Owner.PkgFileP) {};
351 inline PkgFileIterator(pkgCache &Owner,PackageFile *Trg) : Owner(&Owner), File(Trg) {};
352 };
353
354 // Version File
355 class pkgCache::VerFileIterator
356 {
357 pkgCache *Owner;
358 VerFile *FileP;
359
360 public:
361
362 // Iteration
363 void operator ++(int) {if (FileP != Owner->VerFileP) FileP = Owner->VerFileP + FileP->NextFile;};
364 inline void operator ++() {operator ++(0);};
365 inline bool end() const {return FileP == Owner->VerFileP?true:false;};
366
367 // Comparison
368 inline bool operator ==(const VerFileIterator &B) const {return FileP == B.FileP;};
369 inline bool operator !=(const VerFileIterator &B) const {return FileP != B.FileP;};
370
371 // Accessors
372 inline VerFile *operator ->() {return FileP;};
373 inline VerFile const *operator ->() const {return FileP;};
374 inline VerFile const &operator *() const {return *FileP;};
375 inline operator VerFile *() {return FileP == Owner->VerFileP?0:FileP;};
376 inline operator VerFile const *() const {return FileP == Owner->VerFileP?0:FileP;};
377 inline pkgCache *Cache() {return Owner;};
378
379 inline PkgFileIterator File() const {return PkgFileIterator(*Owner,FileP->File + Owner->PkgFileP);};
380 inline unsigned long Index() const {return FileP - Owner->VerFileP;};
381
382 inline VerFileIterator() : Owner(0), FileP(0) {};
383 inline VerFileIterator(pkgCache &Owner,VerFile *Trg) : Owner(&Owner), FileP(Trg) {};
384 };
385
386 // Description File
387 class pkgCache::DescFileIterator
388 {
389 pkgCache *Owner;
390 DescFile *FileP;
391
392 public:
393
394 // Iteration
395 void operator ++(int) {if (FileP != Owner->DescFileP) FileP = Owner->DescFileP + FileP->NextFile;};
396 inline void operator ++() {operator ++(0);};
397 inline bool end() const {return FileP == Owner->DescFileP?true:false;};
398
399 // Comparison
400 inline bool operator ==(const DescFileIterator &B) const {return FileP == B.FileP;};
401 inline bool operator !=(const DescFileIterator &B) const {return FileP != B.FileP;};
402
403 // Accessors
404 inline DescFile *operator ->() {return FileP;};
405 inline DescFile const *operator ->() const {return FileP;};
406 inline DescFile const &operator *() const {return *FileP;};
407 inline operator DescFile *() {return FileP == Owner->DescFileP?0:FileP;};
408 inline operator DescFile const *() const {return FileP == Owner->DescFileP?0:FileP;};
409 inline pkgCache *Cache() {return Owner;};
410
411 inline PkgFileIterator File() const {return PkgFileIterator(*Owner,FileP->File + Owner->PkgFileP);};
412 inline unsigned long Index() const {return FileP - Owner->DescFileP;};
413
414 inline DescFileIterator() : Owner(0), FileP(0) {};
415 inline DescFileIterator(pkgCache &Owner,DescFile *Trg) : Owner(&Owner), FileP(Trg) {};
416 };
417
418 // Inlined Begin functions cant be in the class because of order problems
419 inline pkgCache::VerIterator pkgCache::PkgIterator::VersionList() const
420 {return VerIterator(*Owner,Owner->VerP + Pkg->VersionList);};
421 inline pkgCache::VerIterator pkgCache::PkgIterator::CurrentVer() const
422 {return VerIterator(*Owner,Owner->VerP + Pkg->CurrentVer);};
423 inline pkgCache::DepIterator pkgCache::PkgIterator::RevDependsList() const
424 {return DepIterator(*Owner,Owner->DepP + Pkg->RevDepends,Pkg);};
425 inline pkgCache::PrvIterator pkgCache::PkgIterator::ProvidesList() const
426 {return PrvIterator(*Owner,Owner->ProvideP + Pkg->ProvidesList,Pkg);};
427 inline pkgCache::DescIterator pkgCache::VerIterator::DescriptionList() const
428 {return DescIterator(*Owner,Owner->DescP + Ver->DescriptionList);};
429 inline pkgCache::PrvIterator pkgCache::VerIterator::ProvidesList() const
430 {return PrvIterator(*Owner,Owner->ProvideP + Ver->ProvidesList,Ver);};
431 inline pkgCache::DepIterator pkgCache::VerIterator::DependsList() const
432 {return DepIterator(*Owner,Owner->DepP + Ver->DependsList,Ver);};
433 inline pkgCache::VerFileIterator pkgCache::VerIterator::FileList() const
434 {return VerFileIterator(*Owner,Owner->VerFileP + Ver->FileList);};
435 inline pkgCache::DescFileIterator pkgCache::DescIterator::FileList() const
436 {return DescFileIterator(*Owner,Owner->DescFileP + Desc->FileList);};
437
438 #endif