cacheiterators.h 24 KB

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