X-Git-Url: https://git.saurik.com/apt-legacy.git/blobdiff_plain/da6ee4691da8cccb60b8673b4f97fb7f6df3ec7d..01d22655e3a095de0884c63545dddcf1fab12efc:/apt-pkg/cacheiterators.h diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index 2b326bd..f608380 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -31,11 +31,8 @@ #ifndef PKGLIB_CACHEITERATORS_H #define PKGLIB_CACHEITERATORS_H -#ifdef __GNUG__ -#pragma interface "apt-pkg/cacheiterators.h" -#endif -// Package Iterator +// Package Iterator /*{{{*/ class pkgCache::PkgIterator { friend class pkgCache; @@ -74,6 +71,7 @@ class pkgCache::PkgIterator inline pkgCache *Cache() {return Owner;}; inline const char *Name() const {return Pkg->Name == 0?0:Owner->StrP + Pkg->Name;}; + inline const char *Display() const {return Pkg->Display == 0?0:Owner->StrP + Pkg->Display;}; inline const char *Section() const {return Pkg->Section == 0?0:Owner->StrP + Pkg->Section;}; inline bool Purge() const {return Pkg->CurrentState == pkgCache::State::Purge || (Pkg->CurrentVer == 0 && Pkg->CurrentState == pkgCache::State::NotInstalled);}; @@ -81,9 +79,16 @@ class pkgCache::PkgIterator inline VerIterator CurrentVer() const; inline DepIterator RevDependsList() const; inline PrvIterator ProvidesList() const; + inline TagIterator TagList() const; inline unsigned long Index() const {return Pkg - Owner->PkgP;}; OkState State() const; - + + //Nice printable representation + friend std::ostream& operator<<(std::ostream& out, pkgCache::PkgIterator Pkg); + + const char *CandVersion() const; + const char *CurVersion() const; + // Constructors inline PkgIterator(pkgCache &Owner,Package *Trg) : Pkg(Trg), Owner(&Owner), HashIndex(0) @@ -93,13 +98,13 @@ class pkgCache::PkgIterator }; inline PkgIterator() : Pkg(0), Owner(0), HashIndex(0) {}; }; - -// Version Iterator + /*}}}*/ +// Version Iterator /*{{{*/ class pkgCache::VerIterator { Version *Ver; pkgCache *Owner; - + void _dummy(); public: @@ -107,14 +112,17 @@ class pkgCache::VerIterator // Iteration void operator ++(int) {if (Ver != Owner->VerP) Ver = Owner->VerP + Ver->NextVer;}; inline void operator ++() {operator ++(0);}; - inline bool end() const {return Owner == NULL || (Ver == Owner->VerP?true:false);}; + inline bool end() const {return Owner == 0 || (Ver == Owner->VerP?true:false);}; inline void operator =(const VerIterator &B) {Ver = B.Ver; Owner = B.Owner;}; // Comparison inline bool operator ==(const VerIterator &B) const {return Ver == B.Ver;}; inline bool operator !=(const VerIterator &B) const {return Ver != B.Ver;}; int CompareVer(const VerIterator &B) const; - + + // Testing + inline bool IsGood() const { return Ver && Owner && ! end();}; + // Accessors inline Version *operator ->() {return Ver;}; inline Version const *operator ->() const {return Ver;}; @@ -125,9 +133,12 @@ class pkgCache::VerIterator inline pkgCache *Cache() {return Owner;}; inline const char *VerStr() const {return Ver->VerStr == 0?0:Owner->StrP + Ver->VerStr;}; + inline const char *Display() const {return Ver->Display == 0?0:Owner->StrP + Ver->Display;}; inline const char *Section() const {return Ver->Section == 0?0:Owner->StrP + Ver->Section;}; inline const char *Arch() const {return Ver->Arch == 0?0:Owner->StrP + Ver->Arch;}; inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + Ver->ParentPkg);}; + inline DescIterator DescriptionList() const; + DescIterator TranslatedDescription() const; inline DepIterator DependsList() const; inline PrvIterator ProvidesList() const; inline VerFileIterator FileList() const; @@ -147,8 +158,94 @@ class pkgCache::VerIterator Ver = Owner.VerP; }; }; + /*}}}*/ +// Tag Iterator /*{{{*/ +class pkgCache::TagIterator +{ + Tag *Tg; + pkgCache *Owner; + + void _dummy(); + + public: + + // Iteration + void operator ++(int) {if (Tg != Owner->TagP) Tg = Owner->TagP + Tg->NextTag;}; + inline void operator ++() {operator ++(0);}; + inline bool end() const {return Tg == Owner->TagP?true:false;}; + inline void operator =(const TagIterator &B) {Tg = B.Tg; Owner = B.Owner;}; + + // Comparison + inline bool operator ==(const TagIterator &B) const {return Tg == B.Tg;}; + inline bool operator !=(const TagIterator &B) const {return Tg != B.Tg;}; + int CompareTag(const TagIterator &B) const; + + // Accessors + inline Tag *operator ->() {return Tg;}; + inline Tag const *operator ->() const {return Tg;}; + inline Tag &operator *() {return *Tg;}; + inline Tag const &operator *() const {return *Tg;}; + inline operator Tag *() {return Tg == Owner->TagP?0:Tg;}; + inline operator Tag const *() const {return Tg == Owner->TagP?0:Tg;}; + inline pkgCache *Cache() {return Owner;}; + + inline const char *Name() const {return Owner->StrP + Tg->Name;}; + inline unsigned long Index() const {return Tg - Owner->TagP;}; + + inline TagIterator() : Tg(0), Owner(0) {}; + inline TagIterator(pkgCache &Owner,Tag *Trg = 0) : Tg(Trg), + Owner(&Owner) + { + if (Tg == 0) + Tg = Owner.TagP; + }; +}; + /*}}}*/ +// Description Iterator /*{{{*/ +class pkgCache::DescIterator +{ + Description *Desc; + pkgCache *Owner; + + void _dummy(); + + public: -// Dependency iterator + // Iteration + void operator ++(int) {if (Desc != Owner->DescP) Desc = Owner->DescP + Desc->NextDesc;}; + inline void operator ++() {operator ++(0);}; + inline bool end() const {return Owner == 0 || Desc == Owner->DescP?true:false;}; + inline void operator =(const DescIterator &B) {Desc = B.Desc; Owner = B.Owner;}; + + // Comparison + inline bool operator ==(const DescIterator &B) const {return Desc == B.Desc;}; + inline bool operator !=(const DescIterator &B) const {return Desc != B.Desc;}; + int CompareDesc(const DescIterator &B) const; + + // Accessors + inline Description *operator ->() {return Desc;}; + inline Description const *operator ->() const {return Desc;}; + inline Description &operator *() {return *Desc;}; + inline Description const &operator *() const {return *Desc;}; + inline operator Description *() {return Desc == Owner->DescP?0:Desc;}; + inline operator Description const *() const {return Desc == Owner->DescP?0:Desc;}; + inline pkgCache *Cache() {return Owner;}; + + inline const char *LanguageCode() const {return Owner->StrP + Desc->language_code;}; + inline const char *md5() const {return Owner->StrP + Desc->md5sum;}; + inline DescFileIterator FileList() const; + inline unsigned long Index() const {return Desc - Owner->DescP;}; + + inline DescIterator() : Desc(0), Owner(0) {}; + inline DescIterator(pkgCache &Owner,Description *Trg = 0) : Desc(Trg), + Owner(&Owner) + { + if (Desc == 0) + Desc = Owner.DescP; + }; +}; + /*}}}*/ +// Dependency iterator /*{{{*/ class pkgCache::DepIterator { Dependency *Dep; @@ -206,8 +303,8 @@ class pkgCache::DepIterator }; inline DepIterator() : Dep(0), Type(DepVer), Owner(0) {}; }; - -// Provides iterator + /*}}}*/ +// Provides iterator /*{{{*/ class pkgCache::PrvIterator { Provides *Prv; @@ -259,8 +356,8 @@ class pkgCache::PrvIterator Prv = Owner.ProvideP; }; }; - -// Package file + /*}}}*/ +// Package file /*{{{*/ class pkgCache::PkgFileIterator { pkgCache *Owner; @@ -271,7 +368,7 @@ class pkgCache::PkgFileIterator // Iteration void operator ++(int) {if (File!= Owner->PkgFileP) File = Owner->PkgFileP + File->NextFile;}; inline void operator ++() {operator ++(0);}; - inline bool end() const {return File == Owner->PkgFileP?true:false;}; + inline bool end() const {return Owner == 0 || File == Owner->PkgFileP?true:false;}; // Comparison inline bool operator ==(const PkgFileIterator &B) const {return File == B.File;}; @@ -305,8 +402,8 @@ class pkgCache::PkgFileIterator inline PkgFileIterator(pkgCache &Owner) : Owner(&Owner), File(Owner.PkgFileP) {}; inline PkgFileIterator(pkgCache &Owner,PackageFile *Trg) : Owner(&Owner), File(Trg) {}; }; - -// Version File + /*}}}*/ +// Version File /*{{{*/ class pkgCache::VerFileIterator { pkgCache *Owner; @@ -317,7 +414,7 @@ class pkgCache::VerFileIterator // Iteration void operator ++(int) {if (FileP != Owner->VerFileP) FileP = Owner->VerFileP + FileP->NextFile;}; inline void operator ++() {operator ++(0);}; - inline bool end() const {return FileP == Owner->VerFileP?true:false;}; + inline bool end() const {return Owner == 0 || FileP == Owner->VerFileP?true:false;}; // Comparison inline bool operator ==(const VerFileIterator &B) const {return FileP == B.FileP;}; @@ -337,8 +434,40 @@ class pkgCache::VerFileIterator inline VerFileIterator() : Owner(0), FileP(0) {}; inline VerFileIterator(pkgCache &Owner,VerFile *Trg) : Owner(&Owner), FileP(Trg) {}; }; + /*}}}*/ +// Description File /*{{{*/ +class pkgCache::DescFileIterator +{ + pkgCache *Owner; + DescFile *FileP; + + public: -// Inlined Begin functions cant be in the class because of order problems + // Iteration + void operator ++(int) {if (FileP != Owner->DescFileP) FileP = Owner->DescFileP + FileP->NextFile;}; + inline void operator ++() {operator ++(0);}; + inline bool end() const {return Owner == 0 || FileP == Owner->DescFileP?true:false;}; + + // Comparison + inline bool operator ==(const DescFileIterator &B) const {return FileP == B.FileP;}; + inline bool operator !=(const DescFileIterator &B) const {return FileP != B.FileP;}; + + // Accessors + inline DescFile *operator ->() {return FileP;}; + inline DescFile const *operator ->() const {return FileP;}; + inline DescFile const &operator *() const {return *FileP;}; + inline operator DescFile *() {return FileP == Owner->DescFileP?0:FileP;}; + inline operator DescFile const *() const {return FileP == Owner->DescFileP?0:FileP;}; + inline pkgCache *Cache() {return Owner;}; + + inline PkgFileIterator File() const {return PkgFileIterator(*Owner,FileP->File + Owner->PkgFileP);}; + inline unsigned long Index() const {return FileP - Owner->DescFileP;}; + + inline DescFileIterator() : Owner(0), FileP(0) {}; + inline DescFileIterator(pkgCache &Owner,DescFile *Trg) : Owner(&Owner), FileP(Trg) {}; +}; + /*}}}*/ +// Inlined Begin functions cant be in the class because of order problems /*{{{*/ inline pkgCache::VerIterator pkgCache::PkgIterator::VersionList() const {return VerIterator(*Owner,Owner->VerP + Pkg->VersionList);}; inline pkgCache::VerIterator pkgCache::PkgIterator::CurrentVer() const @@ -347,11 +476,17 @@ inline pkgCache::DepIterator pkgCache::PkgIterator::RevDependsList() const {return DepIterator(*Owner,Owner->DepP + Pkg->RevDepends,Pkg);}; inline pkgCache::PrvIterator pkgCache::PkgIterator::ProvidesList() const {return PrvIterator(*Owner,Owner->ProvideP + Pkg->ProvidesList,Pkg);}; +inline pkgCache::TagIterator pkgCache::PkgIterator::TagList() const + {return TagIterator(*Owner,Owner->TagP + Pkg->TagList);}; +inline pkgCache::DescIterator pkgCache::VerIterator::DescriptionList() const + {return DescIterator(*Owner,Owner->DescP + Ver->DescriptionList);}; inline pkgCache::PrvIterator pkgCache::VerIterator::ProvidesList() const {return PrvIterator(*Owner,Owner->ProvideP + Ver->ProvidesList,Ver);}; inline pkgCache::DepIterator pkgCache::VerIterator::DependsList() const {return DepIterator(*Owner,Owner->DepP + Ver->DependsList,Ver);}; inline pkgCache::VerFileIterator pkgCache::VerIterator::FileList() const {return VerFileIterator(*Owner,Owner->VerFileP + Ver->FileList);}; - +inline pkgCache::DescFileIterator pkgCache::DescIterator::FileList() const + {return DescFileIterator(*Owner,Owner->DescFileP + Desc->FileList);}; + /*}}}*/ #endif