cacheiterators.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. Cache Iterators - Iterators for navigating the cache structure
  5. The iterators all provides ++,==,!=,->,* and end for their type.
  6. The end function can be used to tell if the list has been fully
  7. traversed.
  8. Unlike STL iterators these contain helper functions to access the data
  9. that is being iterated over. This is because the data structures can't
  10. be formed in a manner that is intuitive to use and also mmapable.
  11. For each variable in the target structure that would need a translation
  12. to be accessed correctly a translating function of the same name is
  13. present in the iterator. If applicable the translating function will
  14. return an iterator.
  15. The DepIterator can iterate over two lists, a list of 'version depends'
  16. or a list of 'package reverse depends'. The type is determined by the
  17. structure passed to the constructor, which should be the structure
  18. that has the depends pointer as a member. The provide iterator has the
  19. same system.
  20. This header is not user includable, please use apt-pkg/pkgcache.h
  21. ##################################################################### */
  22. /*}}}*/
  23. #ifndef PKGLIB_CACHEITERATORS_H
  24. #define PKGLIB_CACHEITERATORS_H
  25. #include<apt-pkg/pkgcache.h>
  26. #include<apt-pkg/macros.h>
  27. #include<iterator>
  28. #include <iosfwd>
  29. #include <string>
  30. #include<string.h>
  31. // abstract Iterator template /*{{{*/
  32. /* This template provides the very basic iterator methods we
  33. need to have for doing some walk-over-the-cache magic */
  34. template<typename Str, typename Itr> class pkgCache::Iterator :
  35. public std::iterator<std::forward_iterator_tag, Str> {
  36. /** \brief Returns the Pointer for this struct in the owner
  37. * The implementation of this method should be pretty short
  38. * as it will only return the Pointer into the mmap stored
  39. * in the owner but the name of this pointer is different for
  40. * each structure and we want to abstract here at least for the
  41. * basic methods from the actual structure.
  42. * \return Pointer to the first structure of this type
  43. */
  44. Str* OwnerPointer() const { return static_cast<Itr const*>(this)->OwnerPointer(); }
  45. protected:
  46. Str *S;
  47. pkgCache *Owner;
  48. public:
  49. // Iteration
  50. inline bool end() const {return Owner == 0 || S == OwnerPointer();}
  51. // Comparison
  52. inline bool operator ==(const Itr &B) const {return S == B.S;}
  53. inline bool operator !=(const Itr &B) const {return S != B.S;}
  54. // Accessors
  55. inline Str *operator ->() {return S;}
  56. inline Str const *operator ->() const {return S;}
  57. inline operator Str *() {return S == OwnerPointer() ? 0 : S;}
  58. inline operator Str const *() const {return S == OwnerPointer() ? 0 : S;}
  59. inline Str &operator *() {return *S;}
  60. inline Str const &operator *() const {return *S;}
  61. inline pkgCache *Cache() const {return Owner;}
  62. // Mixed stuff
  63. inline bool IsGood() const { return S && Owner && ! end();}
  64. inline unsigned long Index() const {return S - OwnerPointer();}
  65. void ReMap(void const * const oldMap, void const * const newMap) {
  66. if (Owner == 0 || S == 0)
  67. return;
  68. S += (Str const * const)(newMap) - (Str const * const)(oldMap);
  69. }
  70. // Constructors - look out for the variable assigning
  71. inline Iterator() : S(0), Owner(0) {}
  72. inline Iterator(pkgCache &Owner,Str *T = 0) : S(T), Owner(&Owner) {}
  73. };
  74. /*}}}*/
  75. // Group Iterator /*{{{*/
  76. /* Packages with the same name are collected in a Group so someone only
  77. interest in package names can iterate easily over the names, so the
  78. different architectures can be treated as of the "same" package
  79. (apt internally treat them as totally different packages) */
  80. class pkgCache::GrpIterator: public Iterator<Group, GrpIterator> {
  81. long HashIndex;
  82. public:
  83. inline Group* OwnerPointer() const {
  84. return (Owner != 0) ? Owner->GrpP : 0;
  85. }
  86. // This constructor is the 'begin' constructor, never use it.
  87. explicit inline GrpIterator(pkgCache &Owner) : Iterator<Group, GrpIterator>(Owner), HashIndex(-1) {
  88. S = OwnerPointer();
  89. operator++();
  90. }
  91. GrpIterator& operator++();
  92. inline GrpIterator operator++(int) { GrpIterator const tmp(*this); operator++(); return tmp; }
  93. inline const char *Name() const {return S->Name == 0?0:Owner->StrP + S->Name;}
  94. inline PkgIterator PackageList() const;
  95. PkgIterator FindPkg(std::string Arch = "any") const;
  96. /** \brief find the package with the "best" architecture
  97. The best architecture is either the "native" or the first
  98. in the list of Architectures which is not an end-Pointer
  99. \param PreferNonVirtual tries to respond with a non-virtual package
  100. and only if this fails returns the best virtual package */
  101. PkgIterator FindPreferredPkg(bool const &PreferNonVirtual = true) const;
  102. PkgIterator NextPkg(PkgIterator const &Pkg) const;
  103. // Constructors
  104. inline GrpIterator(pkgCache &Owner, Group *Trg) : Iterator<Group, GrpIterator>(Owner, Trg), HashIndex(0) {
  105. if (S == 0)
  106. S = OwnerPointer();
  107. }
  108. inline GrpIterator() : Iterator<Group, GrpIterator>(), HashIndex(0) {}
  109. };
  110. /*}}}*/
  111. // Package Iterator /*{{{*/
  112. class pkgCache::PkgIterator: public Iterator<Package, PkgIterator> {
  113. long HashIndex;
  114. public:
  115. inline Package* OwnerPointer() const {
  116. return (Owner != 0) ? Owner->PkgP : 0;
  117. }
  118. // This constructor is the 'begin' constructor, never use it.
  119. explicit inline PkgIterator(pkgCache &Owner) : Iterator<Package, PkgIterator>(Owner), HashIndex(-1) {
  120. S = OwnerPointer();
  121. operator++();
  122. }
  123. PkgIterator& operator++();
  124. inline PkgIterator operator++(int) { PkgIterator const tmp(*this); operator++(); return tmp; }
  125. enum OkState {NeedsNothing,NeedsUnpack,NeedsConfigure};
  126. // Accessors
  127. inline const char *Name() const { return Group().Name(); }
  128. // Versions have sections - and packages can have different versions with different sections
  129. // so this interface is broken by design. Run as fast as you can to Version.Section().
  130. APT_DEPRECATED inline const char *Section() const {
  131. APT_IGNORE_DEPRECATED_PUSH
  132. return S->Section == 0?0:Owner->StrP + S->Section;
  133. APT_IGNORE_DEPRECATED_POP
  134. }
  135. inline bool Purge() const {return S->CurrentState == pkgCache::State::Purge ||
  136. (S->CurrentVer == 0 && S->CurrentState == pkgCache::State::NotInstalled);}
  137. inline const char *Arch() const {return S->Arch == 0?0:Owner->StrP + S->Arch;}
  138. inline APT_PURE GrpIterator Group() const { return GrpIterator(*Owner, Owner->GrpP + S->Group);}
  139. inline VerIterator VersionList() const APT_PURE;
  140. inline VerIterator CurrentVer() const APT_PURE;
  141. inline DepIterator RevDependsList() const APT_PURE;
  142. inline PrvIterator ProvidesList() const APT_PURE;
  143. OkState State() const APT_PURE;
  144. const char *CandVersion() const APT_PURE;
  145. const char *CurVersion() const APT_PURE;
  146. //Nice printable representation
  147. friend std::ostream& operator <<(std::ostream& out, PkgIterator i);
  148. std::string FullName(bool const &Pretty = false) const;
  149. // Constructors
  150. inline PkgIterator(pkgCache &Owner,Package *Trg) : Iterator<Package, PkgIterator>(Owner, Trg), HashIndex(0) {
  151. if (S == 0)
  152. S = OwnerPointer();
  153. }
  154. inline PkgIterator() : Iterator<Package, PkgIterator>(), HashIndex(0) {}
  155. };
  156. /*}}}*/
  157. // Version Iterator /*{{{*/
  158. class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
  159. public:
  160. inline Version* OwnerPointer() const {
  161. return (Owner != 0) ? Owner->VerP : 0;
  162. }
  163. // Iteration
  164. inline VerIterator& operator++() {if (S != Owner->VerP) S = Owner->VerP + S->NextVer; return *this;}
  165. inline VerIterator operator++(int) { VerIterator const tmp(*this); operator++(); return tmp; }
  166. // Comparison
  167. int CompareVer(const VerIterator &B) const;
  168. /** \brief compares two version and returns if they are similar
  169. This method should be used to identify if two pseudo versions are
  170. referring to the same "real" version */
  171. inline bool SimilarVer(const VerIterator &B) const {
  172. return (B.end() == false && S->Hash == B->Hash && strcmp(VerStr(), B.VerStr()) == 0);
  173. }
  174. // Accessors
  175. inline const char *VerStr() const {return S->VerStr == 0?0:Owner->StrP + S->VerStr;}
  176. inline const char *Section() const {return S->Section == 0?0:Owner->StrP + S->Section;}
  177. /** \brief source package name this version comes from
  178. Always contains the name, even if it is the same as the binary name */
  179. inline const char *SourcePkgName() const {return Owner->StrP + S->SourcePkgName;}
  180. /** \brief source version this version comes from
  181. Always contains the version string, even if it is the same as the binary version */
  182. inline const char *SourceVerStr() const {return Owner->StrP + S->SourceVerStr;}
  183. inline const char *Arch() const {
  184. if ((S->MultiArch & pkgCache::Version::All) == pkgCache::Version::All)
  185. return "all";
  186. return S->ParentPkg == 0?0:Owner->StrP + ParentPkg()->Arch;
  187. }
  188. inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + S->ParentPkg);}
  189. inline DescIterator DescriptionList() const;
  190. DescIterator TranslatedDescription() const;
  191. inline DepIterator DependsList() const;
  192. inline PrvIterator ProvidesList() const;
  193. inline VerFileIterator FileList() const;
  194. bool Downloadable() const;
  195. inline const char *PriorityType() const {return Owner->Priority(S->Priority);}
  196. const char *MultiArchType() const APT_PURE;
  197. std::string RelStr() const;
  198. bool Automatic() const;
  199. VerFileIterator NewestFile() const;
  200. inline VerIterator(pkgCache &Owner,Version *Trg = 0) : Iterator<Version, VerIterator>(Owner, Trg) {
  201. if (S == 0)
  202. S = OwnerPointer();
  203. }
  204. inline VerIterator() : Iterator<Version, VerIterator>() {}
  205. };
  206. /*}}}*/
  207. // Description Iterator /*{{{*/
  208. class pkgCache::DescIterator : public Iterator<Description, DescIterator> {
  209. public:
  210. inline Description* OwnerPointer() const {
  211. return (Owner != 0) ? Owner->DescP : 0;
  212. }
  213. // Iteration
  214. inline DescIterator& operator++() {if (S != Owner->DescP) S = Owner->DescP + S->NextDesc; return *this;}
  215. inline DescIterator operator++(int) { DescIterator const tmp(*this); operator++(); return tmp; }
  216. // Comparison
  217. int CompareDesc(const DescIterator &B) const;
  218. // Accessors
  219. inline const char *LanguageCode() const {return Owner->StrP + S->language_code;}
  220. inline const char *md5() const {return Owner->StrP + S->md5sum;}
  221. inline DescFileIterator FileList() const;
  222. inline DescIterator() : Iterator<Description, DescIterator>() {}
  223. inline DescIterator(pkgCache &Owner,Description *Trg = 0) : Iterator<Description, DescIterator>(Owner, Trg) {
  224. if (S == 0)
  225. S = Owner.DescP;
  226. }
  227. };
  228. /*}}}*/
  229. // Dependency iterator /*{{{*/
  230. class pkgCache::DepIterator : public Iterator<Dependency, DepIterator> {
  231. enum {DepVer, DepRev} Type;
  232. DependencyData * S2;
  233. public:
  234. inline Dependency* OwnerPointer() const {
  235. return (Owner != 0) ? Owner->DepP : 0;
  236. }
  237. // Iteration
  238. DepIterator& operator++();
  239. inline DepIterator operator++(int) { DepIterator const tmp(*this); operator++(); return tmp; }
  240. // Accessors
  241. inline const char *TargetVer() const {return S2->Version == 0?0:Owner->StrP + S2->Version;}
  242. inline PkgIterator TargetPkg() const {return PkgIterator(*Owner,Owner->PkgP + S2->Package);}
  243. inline PkgIterator SmartTargetPkg() const {PkgIterator R(*Owner,0);SmartTargetPkg(R);return R;}
  244. inline VerIterator ParentVer() const {return VerIterator(*Owner,Owner->VerP + S->ParentVer);}
  245. inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[S->ParentVer].ParentPkg);}
  246. inline bool Reverse() const {return Type == DepRev;}
  247. bool IsCritical() const APT_PURE;
  248. bool IsNegative() const APT_PURE;
  249. bool IsIgnorable(PrvIterator const &Prv) const APT_PURE;
  250. bool IsIgnorable(PkgIterator const &Pkg) const APT_PURE;
  251. /* MultiArch can be translated to SingleArch for an resolver and we did so,
  252. by adding dependencies to help the resolver understand the problem, but
  253. sometimes it is needed to identify these to ignore them… */
  254. inline bool IsMultiArchImplicit() const APT_PURE {
  255. return (S2->CompareOp & pkgCache::Dep::MultiArchImplicit) == pkgCache::Dep::MultiArchImplicit;
  256. }
  257. /* This covers additionally negative dependencies, which aren't arch-specific,
  258. but change architecture nontheless as a Conflicts: foo does applies for all archs */
  259. bool IsImplicit() const APT_PURE;
  260. bool IsSatisfied(VerIterator const &Ver) const APT_PURE;
  261. bool IsSatisfied(PrvIterator const &Prv) const APT_PURE;
  262. void GlobOr(DepIterator &Start,DepIterator &End);
  263. Version **AllTargets() const;
  264. bool SmartTargetPkg(PkgIterator &Result) const;
  265. inline const char *CompType() const {return Owner->CompType(S2->CompareOp);}
  266. inline const char *DepType() const {return Owner->DepType(S2->Type);}
  267. // overrides because we are special
  268. struct DependencyProxy
  269. {
  270. map_stringitem_t &Version;
  271. map_pointer_t &Package;
  272. map_id_t &ID;
  273. unsigned char &Type;
  274. unsigned char &CompareOp;
  275. map_pointer_t &ParentVer;
  276. map_pointer_t &DependencyData;
  277. map_pointer_t &NextRevDepends;
  278. map_pointer_t &NextDepends;
  279. map_pointer_t &NextData;
  280. DependencyProxy const * operator->() const { return this; }
  281. DependencyProxy * operator->() { return this; }
  282. };
  283. inline DependencyProxy operator->() const {return (DependencyProxy) { S2->Version, S2->Package, S->ID, S2->Type, S2->CompareOp, S->ParentVer, S->DependencyData, S->NextRevDepends, S->NextDepends, S2->NextData };}
  284. inline DependencyProxy operator->() {return (DependencyProxy) { S2->Version, S2->Package, S->ID, S2->Type, S2->CompareOp, S->ParentVer, S->DependencyData, S->NextRevDepends, S->NextDepends, S2->NextData };}
  285. void ReMap(void const * const oldMap, void const * const newMap)
  286. {
  287. Iterator<Dependency, DepIterator>::ReMap(oldMap, newMap);
  288. if (Owner == 0 || S == 0 || S2 == 0)
  289. return;
  290. S2 += (DependencyData const * const)(newMap) - (DependencyData const * const)(oldMap);
  291. }
  292. //Nice printable representation
  293. friend std::ostream& operator <<(std::ostream& out, DepIterator D);
  294. inline DepIterator(pkgCache &Owner, Dependency *Trg, Version* = 0) :
  295. Iterator<Dependency, DepIterator>(Owner, Trg), Type(DepVer), S2(Trg == 0 ? Owner.DepDataP : (Owner.DepDataP + Trg->DependencyData)) {
  296. if (S == 0)
  297. S = Owner.DepP;
  298. }
  299. inline DepIterator(pkgCache &Owner, Dependency *Trg, Package*) :
  300. Iterator<Dependency, DepIterator>(Owner, Trg), Type(DepRev), S2(Trg == 0 ? Owner.DepDataP : (Owner.DepDataP + Trg->DependencyData)) {
  301. if (S == 0)
  302. S = Owner.DepP;
  303. }
  304. inline DepIterator() : Iterator<Dependency, DepIterator>(), Type(DepVer), S2(0) {}
  305. };
  306. /*}}}*/
  307. // Provides iterator /*{{{*/
  308. class pkgCache::PrvIterator : public Iterator<Provides, PrvIterator> {
  309. enum {PrvVer, PrvPkg} Type;
  310. public:
  311. inline Provides* OwnerPointer() const {
  312. return (Owner != 0) ? Owner->ProvideP : 0;
  313. }
  314. // Iteration
  315. inline PrvIterator& operator ++() {if (S != Owner->ProvideP) S = Owner->ProvideP +
  316. (Type == PrvVer?S->NextPkgProv:S->NextProvides); return *this;}
  317. inline PrvIterator operator++(int) { PrvIterator const tmp(*this); operator++(); return tmp; }
  318. // Accessors
  319. inline const char *Name() const {return ParentPkg().Name();}
  320. inline const char *ProvideVersion() const {return S->ProvideVersion == 0?0:Owner->StrP + S->ProvideVersion;}
  321. inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + S->ParentPkg);}
  322. inline VerIterator OwnerVer() const {return VerIterator(*Owner,Owner->VerP + S->Version);}
  323. inline PkgIterator OwnerPkg() const {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[S->Version].ParentPkg);}
  324. /* MultiArch can be translated to SingleArch for an resolver and we did so,
  325. by adding provides to help the resolver understand the problem, but
  326. sometimes it is needed to identify these to ignore them… */
  327. bool IsMultiArchImplicit() const APT_PURE
  328. { return (S->Flags & pkgCache::Flag::MultiArchImplicit) == pkgCache::Flag::MultiArchImplicit; }
  329. inline PrvIterator() : Iterator<Provides, PrvIterator>(), Type(PrvVer) {}
  330. inline PrvIterator(pkgCache &Owner, Provides *Trg, Version*) :
  331. Iterator<Provides, PrvIterator>(Owner, Trg), Type(PrvVer) {
  332. if (S == 0)
  333. S = Owner.ProvideP;
  334. }
  335. inline PrvIterator(pkgCache &Owner, Provides *Trg, Package*) :
  336. Iterator<Provides, PrvIterator>(Owner, Trg), Type(PrvPkg) {
  337. if (S == 0)
  338. S = Owner.ProvideP;
  339. }
  340. };
  341. /*}}}*/
  342. // Release file /*{{{*/
  343. class pkgCache::RlsFileIterator : public Iterator<ReleaseFile, RlsFileIterator> {
  344. public:
  345. inline ReleaseFile* OwnerPointer() const {
  346. return (Owner != 0) ? Owner->RlsFileP : 0;
  347. }
  348. // Iteration
  349. inline RlsFileIterator& operator++() {if (S != Owner->RlsFileP) S = Owner->RlsFileP + S->NextFile;return *this;}
  350. inline RlsFileIterator operator++(int) { RlsFileIterator const tmp(*this); operator++(); return tmp; }
  351. // Accessors
  352. inline const char *FileName() const {return S->FileName == 0?0:Owner->StrP + S->FileName;}
  353. inline const char *Archive() const {return S->Archive == 0?0:Owner->StrP + S->Archive;}
  354. inline const char *Version() const {return S->Version == 0?0:Owner->StrP + S->Version;}
  355. inline const char *Origin() const {return S->Origin == 0?0:Owner->StrP + S->Origin;}
  356. inline const char *Codename() const {return S->Codename ==0?0:Owner->StrP + S->Codename;}
  357. inline const char *Label() const {return S->Label == 0?0:Owner->StrP + S->Label;}
  358. inline const char *Site() const {return S->Site == 0?0:Owner->StrP + S->Site;}
  359. inline bool Flagged(pkgCache::Flag::ReleaseFileFlags const flag) const {return (S->Flags & flag) == flag; }
  360. bool IsOk();
  361. std::string RelStr();
  362. // Constructors
  363. inline RlsFileIterator() : Iterator<ReleaseFile, RlsFileIterator>() {}
  364. explicit inline RlsFileIterator(pkgCache &Owner) : Iterator<ReleaseFile, RlsFileIterator>(Owner, Owner.RlsFileP) {}
  365. inline RlsFileIterator(pkgCache &Owner,ReleaseFile *Trg) : Iterator<ReleaseFile, RlsFileIterator>(Owner, Trg) {}
  366. };
  367. /*}}}*/
  368. // Package file /*{{{*/
  369. class pkgCache::PkgFileIterator : public Iterator<PackageFile, PkgFileIterator> {
  370. public:
  371. inline PackageFile* OwnerPointer() const {
  372. return (Owner != 0) ? Owner->PkgFileP : 0;
  373. }
  374. // Iteration
  375. inline PkgFileIterator& operator++() {if (S != Owner->PkgFileP) S = Owner->PkgFileP + S->NextFile; return *this;}
  376. inline PkgFileIterator operator++(int) { PkgFileIterator const tmp(*this); operator++(); return tmp; }
  377. // Accessors
  378. inline const char *FileName() const {return S->FileName == 0?0:Owner->StrP + S->FileName;}
  379. inline pkgCache::RlsFileIterator ReleaseFile() const {return RlsFileIterator(*Owner, Owner->RlsFileP + S->Release);}
  380. inline const char *Archive() const {return S->Release == 0 ? Component() : ReleaseFile().Archive();}
  381. inline const char *Version() const {return S->Release == 0 ? NULL : ReleaseFile().Version();}
  382. inline const char *Origin() const {return S->Release == 0 ? NULL : ReleaseFile().Origin();}
  383. inline const char *Codename() const {return S->Release == 0 ? NULL : ReleaseFile().Codename();}
  384. inline const char *Label() const {return S->Release == 0 ? NULL : ReleaseFile().Label();}
  385. inline const char *Site() const {return S->Release == 0 ? NULL : ReleaseFile().Site();}
  386. inline bool Flagged(pkgCache::Flag::ReleaseFileFlags const flag) const {return S->Release== 0 ? false : ReleaseFile().Flagged(flag);}
  387. inline bool Flagged(pkgCache::Flag::PkgFFlags const flag) const {return (S->Flags & flag) == flag;}
  388. inline const char *Component() const {return S->Component == 0?0:Owner->StrP + S->Component;}
  389. inline const char *Architecture() const {return S->Architecture == 0?0:Owner->StrP + S->Architecture;}
  390. inline const char *IndexType() const {return S->IndexType == 0?0:Owner->StrP + S->IndexType;}
  391. bool IsOk();
  392. std::string RelStr();
  393. // Constructors
  394. inline PkgFileIterator() : Iterator<PackageFile, PkgFileIterator>() {}
  395. explicit inline PkgFileIterator(pkgCache &Owner) : Iterator<PackageFile, PkgFileIterator>(Owner, Owner.PkgFileP) {}
  396. inline PkgFileIterator(pkgCache &Owner,PackageFile *Trg) : Iterator<PackageFile, PkgFileIterator>(Owner, Trg) {}
  397. };
  398. /*}}}*/
  399. // Version File /*{{{*/
  400. class pkgCache::VerFileIterator : public pkgCache::Iterator<VerFile, VerFileIterator> {
  401. public:
  402. inline VerFile* OwnerPointer() const {
  403. return (Owner != 0) ? Owner->VerFileP : 0;
  404. }
  405. // Iteration
  406. inline VerFileIterator& operator++() {if (S != Owner->VerFileP) S = Owner->VerFileP + S->NextFile; return *this;}
  407. inline VerFileIterator operator++(int) { VerFileIterator const tmp(*this); operator++(); return tmp; }
  408. // Accessors
  409. inline PkgFileIterator File() const {return PkgFileIterator(*Owner,S->File + Owner->PkgFileP);}
  410. inline VerFileIterator() : Iterator<VerFile, VerFileIterator>() {}
  411. inline VerFileIterator(pkgCache &Owner,VerFile *Trg) : Iterator<VerFile, VerFileIterator>(Owner, Trg) {}
  412. };
  413. /*}}}*/
  414. // Description File /*{{{*/
  415. class pkgCache::DescFileIterator : public Iterator<DescFile, DescFileIterator> {
  416. public:
  417. inline DescFile* OwnerPointer() const {
  418. return (Owner != 0) ? Owner->DescFileP : 0;
  419. }
  420. // Iteration
  421. inline DescFileIterator& operator++() {if (S != Owner->DescFileP) S = Owner->DescFileP + S->NextFile; return *this;}
  422. inline DescFileIterator operator++(int) { DescFileIterator const tmp(*this); operator++(); return tmp; }
  423. // Accessors
  424. inline PkgFileIterator File() const {return PkgFileIterator(*Owner,S->File + Owner->PkgFileP);}
  425. inline DescFileIterator() : Iterator<DescFile, DescFileIterator>() {}
  426. inline DescFileIterator(pkgCache &Owner,DescFile *Trg) : Iterator<DescFile, DescFileIterator>(Owner, Trg) {}
  427. };
  428. /*}}}*/
  429. // Inlined Begin functions can't be in the class because of order problems /*{{{*/
  430. inline pkgCache::PkgIterator pkgCache::GrpIterator::PackageList() const
  431. {return PkgIterator(*Owner,Owner->PkgP + S->FirstPackage);}
  432. inline pkgCache::VerIterator pkgCache::PkgIterator::VersionList() const
  433. {return VerIterator(*Owner,Owner->VerP + S->VersionList);}
  434. inline pkgCache::VerIterator pkgCache::PkgIterator::CurrentVer() const
  435. {return VerIterator(*Owner,Owner->VerP + S->CurrentVer);}
  436. inline pkgCache::DepIterator pkgCache::PkgIterator::RevDependsList() const
  437. {return DepIterator(*Owner,Owner->DepP + S->RevDepends,S);}
  438. inline pkgCache::PrvIterator pkgCache::PkgIterator::ProvidesList() const
  439. {return PrvIterator(*Owner,Owner->ProvideP + S->ProvidesList,S);}
  440. inline pkgCache::DescIterator pkgCache::VerIterator::DescriptionList() const
  441. {return DescIterator(*Owner,Owner->DescP + S->DescriptionList);}
  442. inline pkgCache::PrvIterator pkgCache::VerIterator::ProvidesList() const
  443. {return PrvIterator(*Owner,Owner->ProvideP + S->ProvidesList,S);}
  444. inline pkgCache::DepIterator pkgCache::VerIterator::DependsList() const
  445. {return DepIterator(*Owner,Owner->DepP + S->DependsList,S);}
  446. inline pkgCache::VerFileIterator pkgCache::VerIterator::FileList() const
  447. {return VerFileIterator(*Owner,Owner->VerFileP + S->FileList);}
  448. inline pkgCache::DescFileIterator pkgCache::DescIterator::FileList() const
  449. {return DescFileIterator(*Owner,Owner->DescFileP + S->FileList);}
  450. /*}}}*/
  451. #endif