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