Res initialize glitch
[ntk/apt.git] / apt-pkg / cacheiterators.h
CommitLineData
578bfd0a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
dcb79bae 3// $Id: cacheiterators.h,v 1.3 1998/07/05 05:33:52 jgg 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
24 that has the depends pointer as a member.
25
26 This header is not user includable, please use pkglib/pkgcache.h
27
28 ##################################################################### */
29 /*}}}*/
30// Header section: pkglib
31#ifndef PKGLIB_CACHEITERATORS_H
32#define PKGLIB_CACHEITERATORS_H
33
34// Package Iterator
35class pkgCache::PkgIterator
36{
37 Package *Pkg;
38 pkgCache *Owner;
39 long HashIndex;
40
41 public:
42
43 enum OkState {NeedsNothing,NeedsUnpack,NeedsConfigure};
44
45 // Iteration
46 void operator ++(int);
47 inline void operator ++() {operator ++(0);};
48 inline bool end() const {return Owner == 0 || Pkg == Owner->PkgP?true:false;};
49
50 // Comparison
51 inline bool operator ==(const PkgIterator &B) const {return Pkg == B.Pkg;};
52 inline bool operator !=(const PkgIterator &B) const {return Pkg != B.Pkg;};
53
54 // Accessors
55 inline Package *operator ->() {return Pkg;};
56 inline Package const *operator ->() const {return Pkg;};
57 inline Package const &operator *() const {return *Pkg;};
58 inline operator Package *() {return Pkg == Owner->PkgP?0:Pkg;};
59 inline operator Package const *() const {return Pkg == Owner->PkgP?0:Pkg;};
60 inline const char *Name() const {return Pkg->Name == 0?0:Owner->StrP + Pkg->Name;};
61 inline const char *Section() const {return Pkg->Section == 0?0:Owner->StrP + Pkg->Section;};
62 inline const char *TargetDist() const {return Pkg->TargetDist == 0?0:Owner->StrP + Pkg->TargetDist;};
63 inline VerIterator VersionList() const;
64 inline VerIterator TargetVer() const;
65 inline VerIterator CurrentVer() const;
66 inline DepIterator RevDependsList() const;
67 inline PrvIterator ProvidesList() const;
f55a958f 68 inline unsigned long Index() const {return Pkg - Owner->PkgP;};
578bfd0a
AL
69 OkState State() const;
70
71 // Constructors
72 inline PkgIterator(pkgCache &Owner) : Owner(&Owner), HashIndex(-1)
73 {
74 Pkg = Owner.PkgP;
75 operator ++(0);
76 };
77 inline PkgIterator(pkgCache &Owner,Package *Trg) : Pkg(Trg), Owner(&Owner),
78 HashIndex(0)
79 {
80 if (Pkg == 0)
81 Pkg = Owner.PkgP;
82 };
83 inline PkgIterator() : Pkg(0), Owner(0), HashIndex(0) {};
84};
85
86// Version Iterator
87class pkgCache::VerIterator
88{
89 Version *Ver;
90 pkgCache &Owner;
91
92 void _dummy();
93
94 public:
95
96 // Iteration
97 void operator ++(int) {if (Ver != Owner.VerP) Ver = Owner.VerP + Ver->NextVer;};
98 inline void operator ++() {operator ++(0);};
99 inline bool end() const {return Ver == Owner.VerP?true:false;};
100 inline void operator =(const VerIterator &B) {Ver = B.Ver;};
101
102 // Comparison
103 inline bool operator ==(const VerIterator &B) const {return Ver == B.Ver;};
104 inline bool operator !=(const VerIterator &B) const {return Ver != B.Ver;};
105 int CompareVer(const VerIterator &B) const;
106
107 // Accessors
108 inline Version *operator ->() {return Ver;};
109 inline Version const *operator ->() const {return Ver;};
110 inline Version &operator *() {return *Ver;};
111 inline Version const &operator *() const {return *Ver;};
112 inline operator Version *() {return Ver == Owner.VerP?0:Ver;};
113 inline operator Version const *() const {return Ver == Owner.VerP?0:Ver;};
114 inline const char *VerStr() const {return Ver->VerStr == 0?0:Owner.StrP + Ver->VerStr;};
115 inline const char *Section() const {return Ver->Section == 0?0:Owner.StrP + Ver->Section;};
578bfd0a
AL
116 inline PkgIterator ParentPkg() const {return PkgIterator(Owner,Owner.PkgP + Ver->ParentPkg);};
117 inline DepIterator DependsList() const;
118 inline PrvIterator ProvidesList() const;
f55a958f 119 inline unsigned long Index() const {return Ver - Owner.VerP;};
dcb79bae 120 inline VerFileIterator FileList() const;
578bfd0a 121
f55a958f 122 inline VerIterator(pkgCache &Owner,Version *Trg = 0) : Ver(Trg), Owner(Owner)
578bfd0a
AL
123 {
124 if (Ver == 0)
125 Ver = Owner.VerP;
126 };
127};
128
129// Dependency iterator
130class pkgCache::DepIterator
131{
132 Dependency *Dep;
133 enum {DepVer, DepRev} Type;
134 pkgCache *Owner;
135
136 void _dummy();
137
138 public:
139
140 // Iteration
141 void operator ++(int) {if (Dep != Owner->DepP) Dep = Owner->DepP +
142 (Type == DepVer?Dep->NextDepends:Dep->NextRevDepends);};
143 inline void operator ++() {operator ++(0);};
144 inline bool end() const {return Owner == 0 || Dep == Owner->DepP?true:false;};
145
146 // Comparison
147 inline bool operator ==(const DepIterator &B) const {return Dep == B.Dep;};
148 inline bool operator !=(const DepIterator &B) const {return Dep != B.Dep;};
149
150 // Accessors
151 inline Dependency *operator ->() {return Dep;};
152 inline Dependency const *operator ->() const {return Dep;};
153 inline Dependency &operator *() {return *Dep;};
154 inline Dependency const &operator *() const {return *Dep;};
155 inline operator Dependency *() {return Dep == Owner->DepP?0:Dep;};
156 inline operator Dependency const *() const {return Dep == Owner->DepP?0:Dep;};
157 inline const char *TargetVer() const {return Dep->Version == 0?0:Owner->StrP + Dep->Version;};
158 inline PkgIterator TargetPkg() {return PkgIterator(*Owner,Owner->PkgP + Dep->Package);};
159 Version **AllTargets();
160 bool SmartTargetPkg(PkgIterator &Result);
161 inline PkgIterator SmartTargetPkg() {PkgIterator R(*Owner);SmartTargetPkg(R);return R;};
162 inline VerIterator ParentVer() {return VerIterator(*Owner,Owner->VerP + Dep->ParentVer);};
163 inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Dep->ParentVer].ParentPkg);};
164 bool IsCritical();
165 inline bool Reverse() {return Type == DepRev;};
f55a958f 166 inline unsigned long Index() const {return Dep - Owner->DepP;};
578bfd0a
AL
167
168 inline DepIterator(pkgCache &Owner,Dependency *Trg,Version * = 0) :
169 Dep(Trg), Type(DepVer), Owner(&Owner)
170 {
171 if (Dep == 0)
172 Dep = Owner.DepP;
173 };
174 inline DepIterator(pkgCache &Owner,Dependency *Trg,Package *) :
175 Dep(Trg), Type(DepRev), Owner(&Owner)
176 {
177 if (Dep == 0)
178 Dep = Owner.DepP;
179 };
180 inline DepIterator() : Dep(0), Type(DepVer), Owner(0) {};
181};
182
183// Provides iterator
184class pkgCache::PrvIterator
185{
186 Provides *Prv;
187 enum {PrvVer, PrvPkg} Type;
188 pkgCache *Owner;
189
190 void _dummy();
191
192 public:
193
194 // Iteration
195 void operator ++(int) {if (Prv != Owner->ProvideP) Prv = Owner->ProvideP +
196 (Type == PrvVer?Prv->NextPkgProv:Prv->NextProvides);};
197 inline void operator ++() {operator ++(0);};
198 inline bool end() const {return Prv == Owner->ProvideP?true:false;};
199
200 // Comparison
201 inline bool operator ==(const PrvIterator &B) const {return Prv == B.Prv;};
202 inline bool operator !=(const PrvIterator &B) const {return Prv != B.Prv;};
203
204 // Accessors
205 inline Provides *operator ->() {return Prv;};
206 inline Provides const *operator ->() const {return Prv;};
207 inline Provides &operator *() {return *Prv;};
208 inline Provides const &operator *() const {return *Prv;};
209 inline operator Provides *() {return Prv == Owner->ProvideP?0:Prv;};
210 inline operator Provides const *() const {return Prv == Owner->ProvideP?0:Prv;};
211 inline const char *Name() const {return Owner->StrP + Owner->PkgP[Prv->ParentPkg].Name;};
212 inline const char *ProvideVersion() const {return Prv->ProvideVersion == 0?0:Owner->StrP + Prv->ProvideVersion;};
213 inline PkgIterator ParentPkg() {return PkgIterator(*Owner,Owner->PkgP + Prv->ParentPkg);};
214 inline VerIterator OwnerVer() {return VerIterator(*Owner,Owner->VerP + Prv->Version);};
215 inline PkgIterator OwnerPkg() {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[Prv->Version].ParentPkg);};
f55a958f 216 inline unsigned long Index() const {return Prv - Owner->ProvideP;};
578bfd0a
AL
217
218 inline PrvIterator(pkgCache &Owner,Provides *Trg,Version *) :
219 Prv(Trg), Type(PrvVer), Owner(&Owner)
220 {
221 if (Prv == 0)
222 Prv = Owner.ProvideP;
223 };
224 inline PrvIterator(pkgCache &Owner,Provides *Trg,Package *) :
225 Prv(Trg), Type(PrvPkg), Owner(&Owner)
226 {
227 if (Prv == 0)
228 Prv = Owner.ProvideP;
229 };
230};
231
232// Package file
233class pkgCache::PkgFileIterator
234{
235 pkgCache *Owner;
236 PackageFile *File;
237
238 public:
239
240 // Iteration
241 void operator ++(int) {if (File!= Owner->PkgFileP) File = Owner->PkgFileP + File->NextFile;};
242 inline void operator ++() {operator ++(0);};
243 inline bool end() const {return File == Owner->PkgFileP?true:false;};
244
245 // Comparison
246 inline bool operator ==(const PkgFileIterator &B) const {return File == B.File;};
247 inline bool operator !=(const PkgFileIterator &B) const {return File != B.File;};
248
249 // Accessors
250 inline PackageFile *operator ->() {return File;};
251 inline PackageFile const *operator ->() const {return File;};
252 inline PackageFile const &operator *() const {return *File;};
253 inline operator PackageFile *() {return File == Owner->PkgFileP?0:File;};
254 inline operator PackageFile const *() const {return File == Owner->PkgFileP?0:File;};
255
256 inline const char *FileName() const {return File->FileName == 0?0:Owner->StrP + File->FileName;};
257 inline const char *Version() const {return File->Version == 0?0:Owner->StrP + File->Version;};
258 inline const char *Distribution() const {return File->Distribution == 0?0:Owner->StrP + File->Distribution;};
f55a958f 259 inline unsigned long Index() const {return File - Owner->PkgFileP;};
578bfd0a
AL
260
261 bool IsOk();
262
263 // Constructors
264 inline PkgFileIterator(pkgCache &Owner) : Owner(&Owner), File(Owner.PkgFileP + Owner.Head().FileList) {};
265 inline PkgFileIterator(pkgCache &Owner,PackageFile *Trg) : Owner(&Owner), File(Trg) {};
266};
267
dcb79bae
AL
268// Version File
269class pkgCache::VerFileIterator
270{
271 pkgCache *Owner;
272 VerFile *FileP;
273
274 public:
275
276 // Iteration
277 void operator ++(int) {if (FileP != Owner->VerFileP) FileP = Owner->VerFileP + FileP->NextFile;};
278 inline void operator ++() {operator ++(0);};
279 inline bool end() const {return FileP == Owner->VerFileP?true:false;};
280
281 // Comparison
282 inline bool operator ==(const VerFileIterator &B) const {return FileP == B.FileP;};
283 inline bool operator !=(const VerFileIterator &B) const {return FileP != B.FileP;};
284
285 // Accessors
286 inline VerFile *operator ->() {return FileP;};
287 inline VerFile const *operator ->() const {return FileP;};
288 inline VerFile const &operator *() const {return *FileP;};
289 inline operator VerFile *() {return FileP == Owner->VerFileP?0:FileP;};
290 inline operator VerFile const *() const {return FileP == Owner->VerFileP?0:FileP;};
291
292 inline PkgFileIterator File() const {return PkgFileIterator(*Owner,FileP->File + Owner->PkgFileP);};
293 inline unsigned long Index() const {return FileP - Owner->VerFileP;};
294
295 inline VerFileIterator(pkgCache &Owner,VerFile *Trg) : Owner(&Owner), FileP(Trg) {};
296};
297
578bfd0a
AL
298// Inlined Begin functions cant be in the class because of order problems
299inline pkgCache::VerIterator pkgCache::PkgIterator::VersionList() const
300 {return VerIterator(*Owner,Owner->VerP + Pkg->VersionList);};
301inline pkgCache::VerIterator pkgCache::PkgIterator::CurrentVer() const
302 {return VerIterator(*Owner,Owner->VerP + Pkg->CurrentVer);};
303inline pkgCache::VerIterator pkgCache::PkgIterator::TargetVer() const
304 {return VerIterator(*Owner,Owner->VerP + Pkg->TargetVer);};
305inline pkgCache::DepIterator pkgCache::PkgIterator::RevDependsList() const
306 {return DepIterator(*Owner,Owner->DepP + Pkg->RevDepends,Pkg);};
307inline pkgCache::PrvIterator pkgCache::PkgIterator::ProvidesList() const
308 {return PrvIterator(*Owner,Owner->ProvideP + Pkg->ProvidesList,Pkg);};
309inline pkgCache::PrvIterator pkgCache::VerIterator::ProvidesList() const
310 {return PrvIterator(Owner,Owner.ProvideP + Ver->ProvidesList,Ver);};
311inline pkgCache::DepIterator pkgCache::VerIterator::DependsList() const
312 {return DepIterator(Owner,Owner.DepP + Ver->DependsList,Ver);};
dcb79bae
AL
313inline pkgCache::VerFileIterator pkgCache::VerIterator::FileList() const
314 {return VerFileIterator(Owner,Owner.VerFileP + Ver->FileList);};
578bfd0a
AL
315
316#endif