prefer the Policy if it is built instead of the DepCache and
[ntk/apt.git] / apt-pkg / cacheiterators.h
index 43cbe13..51bf681 100644 (file)
                                                                        /*}}}*/
 #ifndef PKGLIB_CACHEITERATORS_H
 #define PKGLIB_CACHEITERATORS_H
+#include<iterator>
+
+#include<string.h>
 // abstract Iterator template                                          /*{{{*/
 /* This template provides the very basic iterator methods we
    need to have for doing some walk-over-the-cache magic */
-template<typename Str, typename Itr> class pkgCache::Iterator {
+template<typename Str, typename Itr> class pkgCache::Iterator :
+                       public std::iterator<std::forward_iterator_tag, Str> {
        protected:
        Str *S;
        pkgCache *Owner;
@@ -62,8 +66,9 @@ template<typename Str, typename Itr> class pkgCache::Iterator {
        inline Str const *operator ->() const {return S;};
        inline operator Str *() {return S == OwnerPointer() ? 0 : S;};
        inline operator Str const *() const {return S == OwnerPointer() ? 0 : S;};
+       inline Str &operator *() {return *S;};
        inline Str const &operator *() const {return *S;};
-       inline pkgCache *Cache() {return Owner;};
+       inline pkgCache *Cache() const {return Owner;};
 
        // Mixed stuff
        inline void operator =(const Itr &B) {S = B.S; Owner = B.Owner;};
@@ -101,6 +106,11 @@ class pkgCache::GrpIterator: public Iterator<Group, GrpIterator> {
        inline const char *Name() const {return S->Name == 0?0:Owner->StrP + S->Name;};
        inline PkgIterator PackageList() const;
        PkgIterator FindPkg(string Arch = "any");
+       /** \brief find the package with the "best" architecture
+
+           The best architecture is either the "native" or the first
+           in the list of Architectures which is not an end-Pointer */
+       PkgIterator FindPreferredPkg();
        PkgIterator NextPkg(PkgIterator const &Pkg);
 
        // Constructors
@@ -151,6 +161,7 @@ class pkgCache::PkgIterator: public Iterator<Package, PkgIterator> {
 
        //Nice printable representation
        friend std::ostream& operator <<(std::ostream& out, PkgIterator i);
+       std::string FullName(bool const &Pretty = false) const;
 
        // Constructors
        inline PkgIterator(pkgCache &Owner,Package *Trg) : Iterator<Package, PkgIterator>(Owner, Trg), HashIndex(0) {
@@ -174,6 +185,13 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
 
        // Comparison
        int CompareVer(const VerIterator &B) const;
+       /** \brief compares two version and returns if they are similar
+
+           This method should be used to identify if two pseudo versions are
+           refering to the same "real" version */
+       inline bool SimilarVer(const VerIterator &B) const {
+               return (B.end() == false && S->Hash == B->Hash && strcmp(VerStr(), B.VerStr()) == 0);
+       };
 
        // Accessors
        inline const char *VerStr() const {return S->VerStr == 0?0:Owner->StrP + S->VerStr;};
@@ -196,8 +214,8 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> {
        inline PrvIterator ProvidesList() const;
        inline VerFileIterator FileList() const;
        bool Downloadable() const;
-       inline const char *PriorityType() {return Owner->Priority(S->Priority);};
-       string RelStr();
+       inline const char *PriorityType() const {return Owner->Priority(S->Priority);};
+       string RelStr() const;
 
        bool Automatic() const;
        bool Pseudo() const;
@@ -344,7 +362,8 @@ class pkgCache::PkgFileIterator : public Iterator<PackageFile, PkgFileIterator>
 
        // Constructors
        inline PkgFileIterator() : Iterator<PackageFile, PkgFileIterator>() {};
-       inline PkgFileIterator(pkgCache &Owner,PackageFile *Trg = 0) : Iterator<PackageFile, PkgFileIterator>(Owner, Trg) {};
+       inline PkgFileIterator(pkgCache &Owner) : Iterator<PackageFile, PkgFileIterator>(Owner, Owner.PkgFileP) {};
+       inline PkgFileIterator(pkgCache &Owner,PackageFile *Trg) : Iterator<PackageFile, PkgFileIterator>(Owner, Trg) {};
 };
                                                                        /*}}}*/
 // Version File                                                                /*{{{*/