]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/cacheiterators.h
Drop the Arch information from the Version structure as we can get
[apt.git] / apt-pkg / cacheiterators.h
index 1da5c6f0248cd508fb6a824af252d0c82f071fd8..d8e044f88f8938a9192dfcc1628c763f76af9748 100644 (file)
 #define PKGLIB_CACHEITERATORS_H
 // abstract Iterator template                                          /*{{{*/
 /* This template provides the very basic iterator methods we
-   need to have for doing some walk-over-the-cache magic, */
+   need to have for doing some walk-over-the-cache magic */
 template<typename Str, typename Itr> class pkgCache::Iterator {
-       __attribute__ ((deprecated)) void _dummy(); // FIXME: Who on earth uses this method ???
-
        protected:
        Str *S;
        pkgCache *Owner;
@@ -75,6 +73,43 @@ template<typename Str, typename Itr> class pkgCache::Iterator {
        // Constructors - look out for the variable assigning
        inline Iterator() : S(0), Owner(0) {};
        inline Iterator(pkgCache &Owner,Str *T = 0) : S(T), Owner(&Owner) {};
+};
+                                                                       /*}}}*/
+// Group Iterator                                                      /*{{{*/
+/* Packages with the same name are collected in a Group so someone only
+   interest in package names can iterate easily over the names, so the
+   different architectures can be treated as of the "same" package
+   (apt internally treat them as totally different packages) */
+class pkgCache::GrpIterator: public Iterator<Group, GrpIterator> {
+       long HashIndex;
+
+       protected:
+       inline Group* OwnerPointer() const {
+               return Owner->GrpP;
+       };
+
+       public:
+       // This constructor is the 'begin' constructor, never use it.
+       inline GrpIterator(pkgCache &Owner) : Iterator<Group, GrpIterator>(Owner), HashIndex(-1) {
+               S = OwnerPointer();
+               operator ++(0);
+       };
+
+       virtual void operator ++(int);
+       virtual void operator ++() {operator ++(0);};
+
+       inline const char *Name() const {return S->Name == 0?0:Owner->StrP + S->Name;};
+       inline PkgIterator PackageList() const;
+       PkgIterator FindPkg(string Arch = "any");
+       PkgIterator NextPkg(PkgIterator const &Pkg);
+
+       // Constructors
+       inline GrpIterator(pkgCache &Owner, Group *Trg) : Iterator<Group, GrpIterator>(Owner, Trg), HashIndex(0) {
+               if (S == 0)
+                       S = OwnerPointer();
+       };
+       inline GrpIterator() : Iterator<Group, GrpIterator>(), HashIndex(0) {};
+
 };
                                                                        /*}}}*/
 // Package Iterator                                                    /*{{{*/
@@ -103,6 +138,8 @@ class pkgCache::PkgIterator: public Iterator<Package, PkgIterator> {
        inline const char *Section() const {return S->Section == 0?0:Owner->StrP + S->Section;};
        inline bool Purge() const {return S->CurrentState == pkgCache::State::Purge ||
                (S->CurrentVer == 0 && S->CurrentState == pkgCache::State::NotInstalled);};
+       inline const char *Arch() const {return S->Arch == 0?0:Owner->StrP + S->Arch;};
+       inline GrpIterator Group() const { return GrpIterator(*Owner, Owner->GrpP + S->Group);};
 
        inline VerIterator VersionList() const;
        inline VerIterator CurrentVer() const;
@@ -141,7 +178,7 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
        // Accessors
        inline const char *VerStr() const {return S->VerStr == 0?0:Owner->StrP + S->VerStr;};
        inline const char *Section() const {return S->Section == 0?0:Owner->StrP + S->Section;};
-       inline const char *Arch() const {return S->Arch == 0?0:Owner->StrP + S->Arch;};
+       inline const char *Arch() const {return S->ParentPkg == 0?0:Owner->StrP + ParentPkg()->Arch;};
        inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + S->ParentPkg);};
 
        inline DescIterator DescriptionList() const;
@@ -339,6 +376,8 @@ class pkgCache::DescFileIterator : public Iterator<DescFile, DescFileIterator> {
 };
                                                                        /*}}}*/
 // Inlined Begin functions cant be in the class because of order problems /*{{{*/
+inline pkgCache::PkgIterator pkgCache::GrpIterator::PackageList() const
+       {return PkgIterator(*Owner,Owner->PkgP + S->FirstPackage);};
 inline pkgCache::VerIterator pkgCache::PkgIterator::VersionList() const
        {return VerIterator(*Owner,Owner->VerP + S->VersionList);};
 inline pkgCache::VerIterator pkgCache::PkgIterator::CurrentVer() const