X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/765190e493645e13b5651625d87fd9c8db910a85..77e274f5ad23d79294f28ecc9868fc6f534214a4:/apt-pkg/cacheiterators.h diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index f8f4c05ce..62d0ab59c 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -35,6 +35,9 @@ #include #include #include +#ifdef APT_PKG_EXPOSE_STRING_VIEW +#include +#endif #include @@ -43,10 +46,6 @@ need to have for doing some walk-over-the-cache magic */ template class pkgCache::Iterator : public std::iterator { - protected: - Str *S; - pkgCache *Owner; - /** \brief Returns the Pointer for this struct in the owner * The implementation of this method should be pretty short * as it will only return the Pointer into the mmap stored @@ -55,12 +54,14 @@ template class pkgCache::Iterator : * basic methods from the actual structure. * \return Pointer to the first structure of this type */ - virtual Str* OwnerPointer() const = 0; + Str* OwnerPointer() const { return static_cast(this)->OwnerPointer(); } + + protected: + Str *S; + pkgCache *Owner; public: // Iteration - virtual void operator ++(int) = 0; - virtual void operator ++() = 0; // Should be {operator ++(0);} inline bool end() const {return Owner == 0 || S == OwnerPointer();} // Comparison @@ -77,7 +78,6 @@ template class pkgCache::Iterator : inline pkgCache *Cache() const {return Owner;} // Mixed stuff - inline void operator =(const Itr &B) {S = B.S; Owner = B.Owner;} inline bool IsGood() const { return S && Owner && ! end();} inline unsigned long Index() const {return S - OwnerPointer();} @@ -100,24 +100,27 @@ template class pkgCache::Iterator : class pkgCache::GrpIterator: public Iterator { long HashIndex; - protected: + public: inline Group* OwnerPointer() const { return (Owner != 0) ? Owner->GrpP : 0; } - public: // This constructor is the 'begin' constructor, never use it. - inline GrpIterator(pkgCache &Owner) : Iterator(Owner), HashIndex(-1) { + explicit inline GrpIterator(pkgCache &Owner) : Iterator(Owner), HashIndex(-1) { S = OwnerPointer(); - operator ++(0); + operator++(); } - virtual void operator ++(int); - virtual void operator ++() {operator ++(0);} + GrpIterator& operator++(); + inline GrpIterator operator++(int) { GrpIterator const tmp(*this); operator++(); return tmp; } inline const char *Name() const {return S->Name == 0?0:Owner->StrP + S->Name;} inline PkgIterator PackageList() const; PkgIterator FindPkg(std::string Arch = "any") const; +#ifdef APT_PKG_EXPOSE_STRING_VIEW + APT_HIDDEN PkgIterator FindPkg(APT::StringView Arch = APT::StringView("any", 3)) const; + APT_HIDDEN PkgIterator FindPkg(const char *Arch) const; +#endif /** \brief find the package with the "best" architecture The best architecture is either the "native" or the first @@ -141,30 +144,27 @@ class pkgCache::GrpIterator: public Iterator { class pkgCache::PkgIterator: public Iterator { long HashIndex; - protected: + public: inline Package* OwnerPointer() const { return (Owner != 0) ? Owner->PkgP : 0; } - public: // This constructor is the 'begin' constructor, never use it. - inline PkgIterator(pkgCache &Owner) : Iterator(Owner), HashIndex(-1) { + explicit inline PkgIterator(pkgCache &Owner) : Iterator(Owner), HashIndex(-1) { S = OwnerPointer(); - operator ++(0); + operator++(); } - virtual void operator ++(int); - virtual void operator ++() {operator ++(0);} + PkgIterator& operator++(); + inline PkgIterator operator++(int) { PkgIterator const tmp(*this); operator++(); return tmp; } enum OkState {NeedsNothing,NeedsUnpack,NeedsConfigure}; // Accessors inline const char *Name() const { return Group().Name(); } // Versions have sections - and packages can have different versions with different sections - // so this interface is broken by design. It used to return the section of the "first parsed - // package stanza", but as this can potentially be anything it now returns the section of the - // newest version instead (if any). aka: Run as fast as you can to Version.Section(). - APT_DEPRECATED const char *Section() const; + // so this interface is broken by design. Run as fast as you can to Version.Section(). + APT_DEPRECATED_MSG("Use the .Section method of VerIterator instead") inline const char *Section() const; 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;} @@ -175,11 +175,11 @@ class pkgCache::PkgIterator: public Iterator { inline DepIterator RevDependsList() const APT_PURE; inline PrvIterator ProvidesList() const APT_PURE; OkState State() const APT_PURE; - const char *CandVersion() const APT_PURE; + APT_DEPRECATED_MSG("This method does not respect apt_preferences! Use pkgDepCache::GetCandidateVersion(Pkg)") const char *CandVersion() const APT_PURE; const char *CurVersion() const APT_PURE; //Nice printable representation - friend std::ostream& operator <<(std::ostream& out, PkgIterator i); + APT_DEPRECATED_MSG("Use APT::PrettyPkg instead") friend std::ostream& operator <<(std::ostream& out, PkgIterator i); std::string FullName(bool const &Pretty = false) const; // Constructors @@ -192,15 +192,14 @@ class pkgCache::PkgIterator: public Iterator { /*}}}*/ // Version Iterator /*{{{*/ class pkgCache::VerIterator : public Iterator { - protected: + public: inline Version* OwnerPointer() const { return (Owner != 0) ? Owner->VerP : 0; } - public: // Iteration - void operator ++(int) {if (S != Owner->VerP) S = Owner->VerP + S->NextVer;} - inline void operator ++() {operator ++(0);} + inline VerIterator& operator++() {if (S != Owner->VerP) S = Owner->VerP + S->NextVer; return *this;} + inline VerIterator operator++(int) { VerIterator const tmp(*this); operator++(); return tmp; } // Comparison int CompareVer(const VerIterator &B) const; @@ -215,14 +214,12 @@ class pkgCache::VerIterator : public Iterator { // 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;} -#if APT_PKG_ABI >= 413 /** \brief source package name this version comes from Always contains the name, even if it is the same as the binary name */ inline const char *SourcePkgName() const {return Owner->StrP + S->SourcePkgName;} /** \brief source version this version comes from Always contains the version string, even if it is the same as the binary version */ inline const char *SourceVerStr() const {return Owner->StrP + S->SourceVerStr;} -#endif inline const char *Arch() const { if ((S->MultiArch & pkgCache::Version::All) == pkgCache::Version::All) return "all"; @@ -252,15 +249,14 @@ class pkgCache::VerIterator : public Iterator { /*}}}*/ // Description Iterator /*{{{*/ class pkgCache::DescIterator : public Iterator { - protected: + public: inline Description* OwnerPointer() const { return (Owner != 0) ? Owner->DescP : 0; } - public: // Iteration - void operator ++(int) {if (S != Owner->DescP) S = Owner->DescP + S->NextDesc;} - inline void operator ++() {operator ++(0);} + inline DescIterator& operator++() {if (S != Owner->DescP) S = Owner->DescP + S->NextDesc; return *this;} + inline DescIterator operator++(int) { DescIterator const tmp(*this); operator++(); return tmp; } // Comparison int CompareDesc(const DescIterator &B) const; @@ -280,21 +276,20 @@ class pkgCache::DescIterator : public Iterator { // Dependency iterator /*{{{*/ class pkgCache::DepIterator : public Iterator { enum {DepVer, DepRev} Type; + DependencyData * S2; - protected: + public: inline Dependency* OwnerPointer() const { return (Owner != 0) ? Owner->DepP : 0; } - public: // Iteration - void operator ++(int) {if (S != Owner->DepP) S = Owner->DepP + - (Type == DepVer ? S->NextDepends : S->NextRevDepends);} - inline void operator ++() {operator ++(0);} + DepIterator& operator++(); + inline DepIterator operator++(int) { DepIterator const tmp(*this); operator++(); return tmp; } // Accessors - inline const char *TargetVer() const {return S->Version == 0?0:Owner->StrP + S->Version;} - inline PkgIterator TargetPkg() const {return PkgIterator(*Owner,Owner->PkgP + S->Package);} + inline const char *TargetVer() const {return S2->Version == 0?0:Owner->StrP + S2->Version;} + inline PkgIterator TargetPkg() const {return PkgIterator(*Owner,Owner->PkgP + S2->Package);} inline PkgIterator SmartTargetPkg() const {PkgIterator R(*Owner,0);SmartTargetPkg(R);return R;} inline VerIterator ParentVer() const {return VerIterator(*Owner,Owner->VerP + S->ParentVer);} inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[S->ParentVer].ParentPkg);} @@ -303,45 +298,79 @@ class pkgCache::DepIterator : public Iterator { bool IsNegative() const APT_PURE; bool IsIgnorable(PrvIterator const &Prv) const APT_PURE; bool IsIgnorable(PkgIterator const &Pkg) const APT_PURE; - bool IsMultiArchImplicit() const APT_PURE; + /* MultiArch can be translated to SingleArch for an resolver and we did so, + by adding dependencies to help the resolver understand the problem, but + sometimes it is needed to identify these to ignore them… */ + inline bool IsMultiArchImplicit() const APT_PURE { + return (S2->CompareOp & pkgCache::Dep::MultiArchImplicit) == pkgCache::Dep::MultiArchImplicit; + } + /* This covers additionally negative dependencies, which aren't arch-specific, + but change architecture nonetheless as a Conflicts: foo does applies for all archs */ + bool IsImplicit() const APT_PURE; + bool IsSatisfied(VerIterator const &Ver) const APT_PURE; bool IsSatisfied(PrvIterator const &Prv) const APT_PURE; void GlobOr(DepIterator &Start,DepIterator &End); Version **AllTargets() const; bool SmartTargetPkg(PkgIterator &Result) const; - inline const char *CompType() const {return Owner->CompType(S->CompareOp);} - inline const char *DepType() const {return Owner->DepType(S->Type);} + inline const char *CompType() const {return Owner->CompType(S2->CompareOp);} + inline const char *DepType() const {return Owner->DepType(S2->Type);} + + // overrides because we are special + struct DependencyProxy + { + map_stringitem_t &Version; + map_pointer_t &Package; + map_id_t &ID; + unsigned char &Type; + unsigned char &CompareOp; + map_pointer_t &ParentVer; + map_pointer_t &DependencyData; + map_pointer_t &NextRevDepends; + map_pointer_t &NextDepends; + map_pointer_t &NextData; + DependencyProxy const * operator->() const { return this; } + DependencyProxy * operator->() { return this; } + }; + 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 };} + 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 };} + void ReMap(void const * const oldMap, void const * const newMap) + { + Iterator::ReMap(oldMap, newMap); + if (Owner == 0 || S == 0 || S2 == 0) + return; + S2 += (DependencyData const * const)(newMap) - (DependencyData const * const)(oldMap); + } //Nice printable representation - friend std::ostream& operator <<(std::ostream& out, DepIterator D); + APT_DEPRECATED_MSG("Use APT::PrettyDep instead") friend std::ostream& operator <<(std::ostream& out, DepIterator D); inline DepIterator(pkgCache &Owner, Dependency *Trg, Version* = 0) : - Iterator(Owner, Trg), Type(DepVer) { + Iterator(Owner, Trg), Type(DepVer), S2(Trg == 0 ? Owner.DepDataP : (Owner.DepDataP + Trg->DependencyData)) { if (S == 0) S = Owner.DepP; } inline DepIterator(pkgCache &Owner, Dependency *Trg, Package*) : - Iterator(Owner, Trg), Type(DepRev) { + Iterator(Owner, Trg), Type(DepRev), S2(Trg == 0 ? Owner.DepDataP : (Owner.DepDataP + Trg->DependencyData)) { if (S == 0) S = Owner.DepP; } - inline DepIterator() : Iterator(), Type(DepVer) {} + inline DepIterator() : Iterator(), Type(DepVer), S2(0) {} }; /*}}}*/ // Provides iterator /*{{{*/ class pkgCache::PrvIterator : public Iterator { enum {PrvVer, PrvPkg} Type; - protected: + public: inline Provides* OwnerPointer() const { return (Owner != 0) ? Owner->ProvideP : 0; } - public: // Iteration - void operator ++(int) {if (S != Owner->ProvideP) S = Owner->ProvideP + - (Type == PrvVer?S->NextPkgProv:S->NextProvides);} - inline void operator ++() {operator ++(0);} + inline PrvIterator& operator ++() {if (S != Owner->ProvideP) S = Owner->ProvideP + + (Type == PrvVer?S->NextPkgProv:S->NextProvides); return *this;} + inline PrvIterator operator++(int) { PrvIterator const tmp(*this); operator++(); return tmp; } // Accessors inline const char *Name() const {return ParentPkg().Name();} @@ -350,7 +379,12 @@ class pkgCache::PrvIterator : public Iterator { inline VerIterator OwnerVer() const {return VerIterator(*Owner,Owner->VerP + S->Version);} inline PkgIterator OwnerPkg() const {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[S->Version].ParentPkg);} - bool IsMultiArchImplicit() const APT_PURE; + /* MultiArch can be translated to SingleArch for an resolver and we did so, + by adding provides to help the resolver understand the problem, but + sometimes it is needed to identify these to ignore them… */ + bool IsMultiArchImplicit() const APT_PURE + { return (S->Flags & pkgCache::Flag::MultiArchImplicit) == pkgCache::Flag::MultiArchImplicit; } + inline PrvIterator() : Iterator(), Type(PrvVer) {} inline PrvIterator(pkgCache &Owner, Provides *Trg, Version*) : @@ -365,27 +399,59 @@ class pkgCache::PrvIterator : public Iterator { } }; /*}}}*/ -// Package file /*{{{*/ -class pkgCache::PkgFileIterator : public Iterator { - protected: - inline PackageFile* OwnerPointer() const { - return (Owner != 0) ? Owner->PkgFileP : 0; +// Release file /*{{{*/ +class pkgCache::RlsFileIterator : public Iterator { + public: + inline ReleaseFile* OwnerPointer() const { + return (Owner != 0) ? Owner->RlsFileP : 0; } - public: // Iteration - void operator ++(int) {if (S != Owner->PkgFileP) S = Owner->PkgFileP + S->NextFile;} - inline void operator ++() {operator ++(0);} + inline RlsFileIterator& operator++() {if (S != Owner->RlsFileP) S = Owner->RlsFileP + S->NextFile;return *this;} + inline RlsFileIterator operator++(int) { RlsFileIterator const tmp(*this); operator++(); return tmp; } // Accessors inline const char *FileName() const {return S->FileName == 0?0:Owner->StrP + S->FileName;} inline const char *Archive() const {return S->Archive == 0?0:Owner->StrP + S->Archive;} - inline const char *Component() const {return S->Component == 0?0:Owner->StrP + S->Component;} inline const char *Version() const {return S->Version == 0?0:Owner->StrP + S->Version;} inline const char *Origin() const {return S->Origin == 0?0:Owner->StrP + S->Origin;} inline const char *Codename() const {return S->Codename ==0?0:Owner->StrP + S->Codename;} inline const char *Label() const {return S->Label == 0?0:Owner->StrP + S->Label;} inline const char *Site() const {return S->Site == 0?0:Owner->StrP + S->Site;} + inline bool Flagged(pkgCache::Flag::ReleaseFileFlags const flag) const {return (S->Flags & flag) == flag; } + + bool IsOk(); + std::string RelStr(); + + // Constructors + inline RlsFileIterator() : Iterator() {} + explicit inline RlsFileIterator(pkgCache &Owner) : Iterator(Owner, Owner.RlsFileP) {} + inline RlsFileIterator(pkgCache &Owner,ReleaseFile *Trg) : Iterator(Owner, Trg) {} +}; + /*}}}*/ +// Package file /*{{{*/ +class pkgCache::PkgFileIterator : public Iterator { + public: + inline PackageFile* OwnerPointer() const { + return (Owner != 0) ? Owner->PkgFileP : 0; + } + + // Iteration + inline PkgFileIterator& operator++() {if (S != Owner->PkgFileP) S = Owner->PkgFileP + S->NextFile; return *this;} + inline PkgFileIterator operator++(int) { PkgFileIterator const tmp(*this); operator++(); return tmp; } + + // Accessors + inline const char *FileName() const {return S->FileName == 0?0:Owner->StrP + S->FileName;} + inline pkgCache::RlsFileIterator ReleaseFile() const {return RlsFileIterator(*Owner, Owner->RlsFileP + S->Release);} + inline const char *Archive() const {return S->Release == 0 ? Component() : ReleaseFile().Archive();} + inline const char *Version() const {return S->Release == 0 ? NULL : ReleaseFile().Version();} + inline const char *Origin() const {return S->Release == 0 ? NULL : ReleaseFile().Origin();} + inline const char *Codename() const {return S->Release == 0 ? NULL : ReleaseFile().Codename();} + inline const char *Label() const {return S->Release == 0 ? NULL : ReleaseFile().Label();} + inline const char *Site() const {return S->Release == 0 ? NULL : ReleaseFile().Site();} + inline bool Flagged(pkgCache::Flag::ReleaseFileFlags const flag) const {return S->Release== 0 ? false : ReleaseFile().Flagged(flag);} + inline bool Flagged(pkgCache::Flag::PkgFFlags const flag) const {return (S->Flags & flag) == flag;} + inline const char *Component() const {return S->Component == 0?0:Owner->StrP + S->Component;} inline const char *Architecture() const {return S->Architecture == 0?0:Owner->StrP + S->Architecture;} inline const char *IndexType() const {return S->IndexType == 0?0:Owner->StrP + S->IndexType;} @@ -394,21 +460,20 @@ class pkgCache::PkgFileIterator : public Iterator // Constructors inline PkgFileIterator() : Iterator() {} - inline PkgFileIterator(pkgCache &Owner) : Iterator(Owner, Owner.PkgFileP) {} + explicit inline PkgFileIterator(pkgCache &Owner) : Iterator(Owner, Owner.PkgFileP) {} inline PkgFileIterator(pkgCache &Owner,PackageFile *Trg) : Iterator(Owner, Trg) {} }; /*}}}*/ // Version File /*{{{*/ class pkgCache::VerFileIterator : public pkgCache::Iterator { - protected: + public: inline VerFile* OwnerPointer() const { return (Owner != 0) ? Owner->VerFileP : 0; } - public: // Iteration - void operator ++(int) {if (S != Owner->VerFileP) S = Owner->VerFileP + S->NextFile;} - inline void operator ++() {operator ++(0);} + inline VerFileIterator& operator++() {if (S != Owner->VerFileP) S = Owner->VerFileP + S->NextFile; return *this;} + inline VerFileIterator operator++(int) { VerFileIterator const tmp(*this); operator++(); return tmp; } // Accessors inline PkgFileIterator File() const {return PkgFileIterator(*Owner,S->File + Owner->PkgFileP);} @@ -419,15 +484,14 @@ class pkgCache::VerFileIterator : public pkgCache::Iterator { - protected: + public: inline DescFile* OwnerPointer() const { return (Owner != 0) ? Owner->DescFileP : 0; } - public: // Iteration - void operator ++(int) {if (S != Owner->DescFileP) S = Owner->DescFileP + S->NextFile;} - inline void operator ++() {operator ++(0);} + inline DescFileIterator& operator++() {if (S != Owner->DescFileP) S = Owner->DescFileP + S->NextFile; return *this;} + inline DescFileIterator operator++(int) { DescFileIterator const tmp(*this); operator++(); return tmp; } // Accessors inline PkgFileIterator File() const {return PkgFileIterator(*Owner,S->File + Owner->PkgFileP);} @@ -457,5 +521,7 @@ inline pkgCache::VerFileIterator pkgCache::VerIterator::FileList() const {return VerFileIterator(*Owner,Owner->VerFileP + S->FileList);} inline pkgCache::DescFileIterator pkgCache::DescIterator::FileList() const {return DescFileIterator(*Owner,Owner->DescFileP + S->FileList);} +APT_DEPRECATED_MSG("Use the .Section method of VerIterator instead") inline const char * pkgCache::PkgIterator::Section() const + {return S->VersionList == 0 ? 0 : VersionList().Section();} /*}}}*/ #endif