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