]> git.saurik.com Git - apt.git/blob - apt-pkg/cacheiterators.h
* fix various -Wall warnings
[apt.git] / apt-pkg / cacheiterators.h
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 *Section() const {return Pkg->Section == 0?0:Owner->StrP + Pkg->Section;};
75 inline bool Purge() const {return Pkg->CurrentState == pkgCache::State::Purge ||
76 (Pkg->CurrentVer == 0 && Pkg->CurrentState == pkgCache::State::NotInstalled);};
77 inline VerIterator VersionList() const;
78 inline VerIterator CurrentVer() const;
79 inline DepIterator RevDependsList() const;
80 inline PrvIterator ProvidesList() const;
81 inline unsigned long Index() const {return Pkg - Owner->PkgP;};
82 OkState State() const;
83
84 // Constructors
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
95 class pkgCache::VerIterator
96 {
97 Version *Ver;
98 pkgCache *Owner;
99
100 void _dummy();
101
102 public:
103
104 // Iteration
105 void operator ++(int) {if (Ver != Owner->VerP) Ver = Owner->VerP + Ver->NextVer;};
106 inline void operator ++() {operator ++(0);};
107 inline bool end() const {return Owner == NULL || (Ver == Owner->VerP?true:false);};
108 inline void operator =(const VerIterator &B) {Ver = B.Ver; Owner = B.Owner;};
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;};
120 inline operator Version *() {return Ver == Owner->VerP?0:Ver;};
121 inline operator Version const *() const {return Ver == Owner->VerP?0:Ver;};
122 inline pkgCache *Cache() {return Owner;};
123
124 inline const char *VerStr() const {return Ver->VerStr == 0?0:Owner->StrP + Ver->VerStr;};
125 inline const char *Section() const {return Ver->Section == 0?0:Owner->StrP + Ver->Section;};
126 inline const char *Arch() const {return Ver->Arch == 0?0:Owner->StrP + Ver->Arch;};
127 inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + Ver->ParentPkg);};
128 inline DescIterator DescriptionList() const;
129 DescIterator TranslatedDescription() const;
130 inline DepIterator DependsList() const;
131 inline PrvIterator ProvidesList() const;
132 inline VerFileIterator FileList() const;
133 inline unsigned long Index() const {return Ver - Owner->VerP;};
134 bool Downloadable() const;
135 inline const char *PriorityType() {return Owner->Priority(Ver->Priority);};
136 string RelStr();
137
138 bool Automatic() const;
139 VerFileIterator NewestFile() const;
140
141 inline VerIterator() : Ver(0), Owner(0) {};
142 inline VerIterator(pkgCache &Owner,Version *Trg = 0) : Ver(Trg),
143 Owner(&Owner)
144 {
145 if (Ver == 0)
146 Ver = Owner.VerP;
147 };
148 };
149
150 // Description Iterator
151 class pkgCache::DescIterator
152 {
153 Description *Desc;
154 pkgCache *Owner;
155
156 void _dummy();
157
158 public:
159
160 // Iteration
161 void operator ++(int) {if (Desc != Owner->DescP) Desc = Owner->DescP + Desc->NextDesc;};
162 inline void operator ++() {operator ++(0);};
163 inline bool end() const {return Desc == Owner->DescP?true:false;};
164 inline void operator =(const DescIterator &B) {Desc = B.Desc; Owner = B.Owner;};
165
166 // Comparison
167 inline bool operator ==(const DescIterator &B) const {return Desc == B.Desc;};
168 inline bool operator !=(const DescIterator &B) const {return Desc != B.Desc;};
169 int CompareDesc(const DescIterator &B) const;
170
171 // Accessors
172 inline Description *operator ->() {return Desc;};
173 inline Description const *operator ->() const {return Desc;};
174 inline Description &operator *() {return *Desc;};
175 inline Description const &operator *() const {return *Desc;};
176 inline operator Description *() {return Desc == Owner->DescP?0:Desc;};
177 inline operator Description const *() const {return Desc == Owner->DescP?0:Desc;};
178 inline pkgCache *Cache() {return Owner;};
179
180 inline const char *LanguageCode() const {return Owner->StrP + Desc->language_code;};
181 inline const char *md5() const {return Owner->StrP + Desc->md5sum;};
182 inline DescFileIterator FileList() const;
183 inline unsigned long Index() const {return Desc - Owner->DescP;};
184
185 inline DescIterator() : Desc(0), Owner(0) {};
186 inline DescIterator(pkgCache &Owner,Description *Trg = 0) : Desc(Trg),
187 Owner(&Owner)
188 {
189 if (Desc == 0)
190 Desc = Owner.DescP;
191 };
192 };
193
194 // Dependency iterator
195 class pkgCache::DepIterator
196 {
197 Dependency *Dep;
198 enum {DepVer, DepRev} Type;
199 pkgCache *Owner;
200
201 void _dummy();
202
203 public:
204
205 // Iteration
206 void operator ++(int) {if (Dep != Owner->DepP) Dep = Owner->DepP +
207 (Type == DepVer?Dep->NextDepends:Dep->NextRevDepends);};
208 inline void operator ++() {operator ++(0);};
209 inline bool end() const {return Owner == 0 || Dep == Owner->DepP?true:false;};
210
211 // Comparison
212 inline bool operator ==(const DepIterator &B) const {return Dep == B.Dep;};
213 inline bool operator !=(const DepIterator &B) const {return Dep != B.Dep;};
214
215 // Accessors
216 inline Dependency *operator ->() {return Dep;};
217 inline Dependency const *operator ->() const {return Dep;};
218 inline Dependency &operator *() {return *Dep;};
219 inline Dependency const &operator *() const {return *Dep;};
220 inline operator Dependency *() {return Dep == Owner->DepP?0:Dep;};
221 inline operator Dependency const *() const {return Dep == Owner->DepP?0:Dep;};
222 inline pkgCache *Cache() {return Owner;};
223
224 inline const char *TargetVer() const {return Dep->Version == 0?0:Owner->StrP + Dep->Version;};
225 inline PkgIterator TargetPkg() {return PkgIterator(*Owner,Owner->PkgP + Dep->Package);};
226 inline PkgIterator SmartTargetPkg() {PkgIterator R(*Owner,0);SmartTargetPkg(R);return R;};
227 inline VerIterator ParentVer() {return VerIterator(*Owner,Owner->VerP + Dep->ParentVer);};
228 inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Dep->ParentVer].ParentPkg);};
229 inline bool Reverse() {return Type == DepRev;};
230 inline unsigned long Index() const {return Dep - Owner->DepP;};
231 bool IsCritical();
232 void GlobOr(DepIterator &Start,DepIterator &End);
233 Version **AllTargets();
234 bool SmartTargetPkg(PkgIterator &Result);
235 inline const char *CompType() {return Owner->CompType(Dep->CompareOp);};
236 inline const char *DepType() {return Owner->DepType(Dep->Type);};
237
238 inline DepIterator(pkgCache &Owner,Dependency *Trg,Version * = 0) :
239 Dep(Trg), Type(DepVer), Owner(&Owner)
240 {
241 if (Dep == 0)
242 Dep = Owner.DepP;
243 };
244 inline DepIterator(pkgCache &Owner,Dependency *Trg,Package *) :
245 Dep(Trg), Type(DepRev), Owner(&Owner)
246 {
247 if (Dep == 0)
248 Dep = Owner.DepP;
249 };
250 inline DepIterator() : Dep(0), Type(DepVer), Owner(0) {};
251 };
252
253 // Provides iterator
254 class pkgCache::PrvIterator
255 {
256 Provides *Prv;
257 enum {PrvVer, PrvPkg} Type;
258 pkgCache *Owner;
259
260 void _dummy();
261
262 public:
263
264 // Iteration
265 void operator ++(int) {if (Prv != Owner->ProvideP) Prv = Owner->ProvideP +
266 (Type == PrvVer?Prv->NextPkgProv:Prv->NextProvides);};
267 inline void operator ++() {operator ++(0);};
268 inline bool end() const {return Owner == 0 || Prv == Owner->ProvideP?true:false;};
269
270 // Comparison
271 inline bool operator ==(const PrvIterator &B) const {return Prv == B.Prv;};
272 inline bool operator !=(const PrvIterator &B) const {return Prv != B.Prv;};
273
274 // Accessors
275 inline Provides *operator ->() {return Prv;};
276 inline Provides const *operator ->() const {return Prv;};
277 inline Provides &operator *() {return *Prv;};
278 inline Provides const &operator *() const {return *Prv;};
279 inline operator Provides *() {return Prv == Owner->ProvideP?0:Prv;};
280 inline operator Provides const *() const {return Prv == Owner->ProvideP?0:Prv;};
281 inline pkgCache *Cache() {return Owner;};
282
283 inline const char *Name() const {return Owner->StrP + Owner->PkgP[Prv->ParentPkg].Name;};
284 inline const char *ProvideVersion() const {return Prv->ProvideVersion == 0?0:Owner->StrP + Prv->ProvideVersion;};
285 inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Prv->ParentPkg);};
286 inline VerIterator OwnerVer() {return VerIterator(*Owner,Owner->VerP + Prv->Version);};
287 inline PkgIterator OwnerPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Prv->Version].ParentPkg);};
288 inline unsigned long Index() const {return Prv - Owner->ProvideP;};
289
290 inline PrvIterator() : Prv(0), Type(PrvVer), Owner(0) {};
291
292 inline PrvIterator(pkgCache &Owner,Provides *Trg,Version *) :
293 Prv(Trg), Type(PrvVer), Owner(&Owner)
294 {
295 if (Prv == 0)
296 Prv = Owner.ProvideP;
297 };
298 inline PrvIterator(pkgCache &Owner,Provides *Trg,Package *) :
299 Prv(Trg), Type(PrvPkg), Owner(&Owner)
300 {
301 if (Prv == 0)
302 Prv = Owner.ProvideP;
303 };
304 };
305
306 // Package file
307 class pkgCache::PkgFileIterator
308 {
309 pkgCache *Owner;
310 PackageFile *File;
311
312 public:
313
314 // Iteration
315 void operator ++(int) {if (File!= Owner->PkgFileP) File = Owner->PkgFileP + File->NextFile;};
316 inline void operator ++() {operator ++(0);};
317 inline bool end() const {return File == Owner->PkgFileP?true:false;};
318
319 // Comparison
320 inline bool operator ==(const PkgFileIterator &B) const {return File == B.File;};
321 inline bool operator !=(const PkgFileIterator &B) const {return File != B.File;};
322
323 // Accessors
324 inline PackageFile *operator ->() {return File;};
325 inline PackageFile const *operator ->() const {return File;};
326 inline PackageFile const &operator *() const {return *File;};
327 inline operator PackageFile *() {return File == Owner->PkgFileP?0:File;};
328 inline operator PackageFile const *() const {return File == Owner->PkgFileP?0:File;};
329 inline pkgCache *Cache() {return Owner;};
330
331 inline const char *FileName() const {return File->FileName == 0?0:Owner->StrP + File->FileName;};
332 inline const char *Archive() const {return File->Archive == 0?0:Owner->StrP + File->Archive;};
333 inline const char *Component() const {return File->Component == 0?0:Owner->StrP + File->Component;};
334 inline const char *Version() const {return File->Version == 0?0:Owner->StrP + File->Version;};
335 inline const char *Origin() const {return File->Origin == 0?0:Owner->StrP + File->Origin;};
336 inline const char *Label() const {return File->Label == 0?0:Owner->StrP + File->Label;};
337 inline const char *Site() const {return File->Site == 0?0:Owner->StrP + File->Site;};
338 inline const char *Architecture() const {return File->Architecture == 0?0:Owner->StrP + File->Architecture;};
339 inline const char *IndexType() const {return File->IndexType == 0?0:Owner->StrP + File->IndexType;};
340
341 inline unsigned long Index() const {return File - Owner->PkgFileP;};
342
343 bool IsOk();
344 string RelStr();
345
346 // Constructors
347 inline PkgFileIterator() : Owner(0), File(0) {};
348 inline PkgFileIterator(pkgCache &Owner) : Owner(&Owner), File(Owner.PkgFileP) {};
349 inline PkgFileIterator(pkgCache &Owner,PackageFile *Trg) : Owner(&Owner), File(Trg) {};
350 };
351
352 // Version File
353 class pkgCache::VerFileIterator
354 {
355 pkgCache *Owner;
356 VerFile *FileP;
357
358 public:
359
360 // Iteration
361 void operator ++(int) {if (FileP != Owner->VerFileP) FileP = Owner->VerFileP + FileP->NextFile;};
362 inline void operator ++() {operator ++(0);};
363 inline bool end() const {return FileP == Owner->VerFileP?true:false;};
364
365 // Comparison
366 inline bool operator ==(const VerFileIterator &B) const {return FileP == B.FileP;};
367 inline bool operator !=(const VerFileIterator &B) const {return FileP != B.FileP;};
368
369 // Accessors
370 inline VerFile *operator ->() {return FileP;};
371 inline VerFile const *operator ->() const {return FileP;};
372 inline VerFile const &operator *() const {return *FileP;};
373 inline operator VerFile *() {return FileP == Owner->VerFileP?0:FileP;};
374 inline operator VerFile const *() const {return FileP == Owner->VerFileP?0:FileP;};
375 inline pkgCache *Cache() {return Owner;};
376
377 inline PkgFileIterator File() const {return PkgFileIterator(*Owner,FileP->File + Owner->PkgFileP);};
378 inline unsigned long Index() const {return FileP - Owner->VerFileP;};
379
380 inline VerFileIterator() : Owner(0), FileP(0) {};
381 inline VerFileIterator(pkgCache &Owner,VerFile *Trg) : Owner(&Owner), FileP(Trg) {};
382 };
383
384 // Description File
385 class pkgCache::DescFileIterator
386 {
387 pkgCache *Owner;
388 DescFile *FileP;
389
390 public:
391
392 // Iteration
393 void operator ++(int) {if (FileP != Owner->DescFileP) FileP = Owner->DescFileP + FileP->NextFile;};
394 inline void operator ++() {operator ++(0);};
395 inline bool end() const {return FileP == Owner->DescFileP?true:false;};
396
397 // Comparison
398 inline bool operator ==(const DescFileIterator &B) const {return FileP == B.FileP;};
399 inline bool operator !=(const DescFileIterator &B) const {return FileP != B.FileP;};
400
401 // Accessors
402 inline DescFile *operator ->() {return FileP;};
403 inline DescFile const *operator ->() const {return FileP;};
404 inline DescFile const &operator *() const {return *FileP;};
405 inline operator DescFile *() {return FileP == Owner->DescFileP?0:FileP;};
406 inline operator DescFile const *() const {return FileP == Owner->DescFileP?0:FileP;};
407 inline pkgCache *Cache() {return Owner;};
408
409 inline PkgFileIterator File() const {return PkgFileIterator(*Owner,FileP->File + Owner->PkgFileP);};
410 inline unsigned long Index() const {return FileP - Owner->DescFileP;};
411
412 inline DescFileIterator() : Owner(0), FileP(0) {};
413 inline DescFileIterator(pkgCache &Owner,DescFile *Trg) : Owner(&Owner), FileP(Trg) {};
414 };
415
416 // Inlined Begin functions cant be in the class because of order problems
417 inline pkgCache::VerIterator pkgCache::PkgIterator::VersionList() const
418 {return VerIterator(*Owner,Owner->VerP + Pkg->VersionList);};
419 inline pkgCache::VerIterator pkgCache::PkgIterator::CurrentVer() const
420 {return VerIterator(*Owner,Owner->VerP + Pkg->CurrentVer);};
421 inline pkgCache::DepIterator pkgCache::PkgIterator::RevDependsList() const
422 {return DepIterator(*Owner,Owner->DepP + Pkg->RevDepends,Pkg);};
423 inline pkgCache::PrvIterator pkgCache::PkgIterator::ProvidesList() const
424 {return PrvIterator(*Owner,Owner->ProvideP + Pkg->ProvidesList,Pkg);};
425 inline pkgCache::DescIterator pkgCache::VerIterator::DescriptionList() const
426 {return DescIterator(*Owner,Owner->DescP + Ver->DescriptionList);};
427 inline pkgCache::PrvIterator pkgCache::VerIterator::ProvidesList() const
428 {return PrvIterator(*Owner,Owner->ProvideP + Ver->ProvidesList,Ver);};
429 inline pkgCache::DepIterator pkgCache::VerIterator::DependsList() const
430 {return DepIterator(*Owner,Owner->DepP + Ver->DependsList,Ver);};
431 inline pkgCache::VerFileIterator pkgCache::VerIterator::FileList() const
432 {return VerFileIterator(*Owner,Owner->VerFileP + Ver->FileList);};
433 inline pkgCache::DescFileIterator pkgCache::DescIterator::FileList() const
434 {return DescFileIterator(*Owner,Owner->DescFileP + Desc->FileList);};
435
436 #endif