]> git.saurik.com Git - apt-legacy.git/blobdiff - apt-pkg/cacheiterators.h
Break the ABI and fix the package limit.
[apt-legacy.git] / apt-pkg / cacheiterators.h
index 08eafca0f44db8e722299e68307b9f887e0b6dd9..f6083805fd00ab8c00399fe1875b9fb0f718d1ed 100644 (file)
@@ -32,7 +32,7 @@
 #define PKGLIB_CACHEITERATORS_H
 
 
-// Package Iterator
+// Package Iterator                                                    /*{{{*/
 class pkgCache::PkgIterator
 {
    friend class pkgCache;
@@ -71,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);};
@@ -78,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) 
@@ -90,8 +98,8 @@ class pkgCache::PkgIterator
    };
    inline PkgIterator() : Pkg(0), Owner(0), HashIndex(0) {};
 };
-
-// Version Iterator
+                                                                       /*}}}*/
+// Version Iterator                                                    /*{{{*/
 class pkgCache::VerIterator
 {
    Version *Ver;
@@ -104,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;};
@@ -122,6 +133,7 @@ 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);};
@@ -146,8 +158,50 @@ 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;};
 
-// Description Iterator
+   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;
@@ -160,7 +214,7 @@ class pkgCache::DescIterator
    // Iteration
    void operator ++(int) {if (Desc != Owner->DescP) Desc = Owner->DescP + Desc->NextDesc;};
    inline void operator ++() {operator ++(0);};
-   inline bool end() const {return Desc == Owner->DescP?true:false;};
+   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
@@ -190,8 +244,8 @@ class pkgCache::DescIterator
         Desc = Owner.DescP;
    };
 };
-
-// Dependency iterator
+                                                                       /*}}}*/
+// Dependency iterator                                                 /*{{{*/
 class pkgCache::DepIterator
 {
    Dependency *Dep;
@@ -249,8 +303,8 @@ class pkgCache::DepIterator
    };
    inline DepIterator() : Dep(0), Type(DepVer), Owner(0) {};
 };
-
-// Provides iterator
+                                                                       /*}}}*/
+// Provides iterator                                                   /*{{{*/
 class pkgCache::PrvIterator
 {
    Provides *Prv;
@@ -302,8 +356,8 @@ class pkgCache::PrvIterator
         Prv = Owner.ProvideP;
    };
 };
-
-// Package file 
+                                                                       /*}}}*/
+// Package file                                                                /*{{{*/
 class pkgCache::PkgFileIterator
 {
    pkgCache *Owner;
@@ -314,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;};
@@ -348,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;
@@ -360,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;};
@@ -380,8 +434,8 @@ class pkgCache::VerFileIterator
    inline VerFileIterator() : Owner(0), FileP(0) {};
    inline VerFileIterator(pkgCache &Owner,VerFile *Trg) : Owner(&Owner), FileP(Trg) {};
 };
-
-// Description File 
+                                                                       /*}}}*/
+// Description File                                                    /*{{{*/
 class pkgCache::DescFileIterator
 {
    pkgCache *Owner;
@@ -392,7 +446,7 @@ class pkgCache::DescFileIterator
    // Iteration
    void operator ++(int) {if (FileP != Owner->DescFileP) FileP = Owner->DescFileP + FileP->NextFile;};
    inline void operator ++() {operator ++(0);};
-   inline bool end() const {return FileP == Owner->DescFileP?true:false;};
+   inline bool end() const {return Owner == 0 ||  FileP == Owner->DescFileP?true:false;};
 
    // Comparison
    inline bool operator ==(const DescFileIterator &B) const {return FileP == B.FileP;};
@@ -412,8 +466,8 @@ class pkgCache::DescFileIterator
    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
+                                                                       /*}}}*/
+// 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
@@ -422,6 +476,8 @@ 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
@@ -432,5 +488,5 @@ 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