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