diff options
-rw-r--r-- | apt-pkg/cacheiterators.h | 90 | ||||
-rw-r--r-- | apt-pkg/cacheset.cc | 3 | ||||
-rw-r--r-- | apt-pkg/cacheset.h | 63 | ||||
-rw-r--r-- | apt-pkg/pkgcache.cc | 8 | ||||
-rw-r--r-- | apt-private/private-cachefile.h | 5 |
5 files changed, 77 insertions, 92 deletions
diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index d7614374e..06deef950 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -43,10 +43,6 @@ need to have for doing some walk-over-the-cache magic */ template<typename Str, typename Itr> class pkgCache::Iterator : public std::iterator<std::forward_iterator_tag, Str> { - 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 +51,14 @@ template<typename Str, typename Itr> 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<Itr const*>(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 @@ -99,20 +97,19 @@ template<typename Str, typename Itr> class pkgCache::Iterator : class pkgCache::GrpIterator: public Iterator<Group, GrpIterator> { long HashIndex; - protected: + public: inline Group* OwnerPointer() const { return (Owner != 0) ? Owner->GrpP : 0; } - public: // This constructor is the 'begin' constructor, never use it. explicit inline GrpIterator(pkgCache &Owner) : Iterator<Group, GrpIterator>(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; @@ -140,20 +137,19 @@ class pkgCache::GrpIterator: public Iterator<Group, GrpIterator> { class pkgCache::PkgIterator: public Iterator<Package, PkgIterator> { long HashIndex; - protected: + public: inline Package* OwnerPointer() const { return (Owner != 0) ? Owner->PkgP : 0; } - public: // This constructor is the 'begin' constructor, never use it. explicit inline PkgIterator(pkgCache &Owner) : Iterator<Package, PkgIterator>(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}; @@ -193,15 +189,14 @@ class pkgCache::PkgIterator: public Iterator<Package, PkgIterator> { /*}}}*/ // Version Iterator /*{{{*/ class pkgCache::VerIterator : public Iterator<Version, VerIterator> { - 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; @@ -253,15 +248,14 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> { /*}}}*/ // Description Iterator /*{{{*/ class pkgCache::DescIterator : public Iterator<Description, DescIterator> { - 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; @@ -282,16 +276,15 @@ class pkgCache::DescIterator : public Iterator<Description, DescIterator> { class pkgCache::DepIterator : public Iterator<Dependency, DepIterator> { enum {DepVer, DepRev} Type; - 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);} + inline DepIterator& operator++() {if (S != Owner->DepP) S = Owner->DepP + + (Type == DepVer ? S->NextDepends : S->NextRevDepends); return *this;} + 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;} @@ -333,16 +326,15 @@ class pkgCache::DepIterator : public Iterator<Dependency, DepIterator> { class pkgCache::PrvIterator : public Iterator<Provides, PrvIterator> { 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();} @@ -368,15 +360,14 @@ class pkgCache::PrvIterator : public Iterator<Provides, PrvIterator> { /*}}}*/ // Release file /*{{{*/ class pkgCache::RlsFileIterator : public Iterator<ReleaseFile, RlsFileIterator> { - protected: + public: inline ReleaseFile* OwnerPointer() const { return (Owner != 0) ? Owner->RlsFileP : 0; } - public: // Iteration - void operator ++(int) {if (S != Owner->RlsFileP) S = Owner->RlsFileP + 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;} @@ -399,15 +390,14 @@ class pkgCache::RlsFileIterator : public Iterator<ReleaseFile, RlsFileIterator> /*}}}*/ // Package file /*{{{*/ class pkgCache::PkgFileIterator : public Iterator<PackageFile, PkgFileIterator> { - protected: + public: inline PackageFile* OwnerPointer() const { return (Owner != 0) ? Owner->PkgFileP : 0; } - public: // Iteration - void operator ++(int) {if (S != Owner->PkgFileP) S = Owner->PkgFileP + S->NextFile;} - inline void operator ++() {operator ++(0);} + 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;} @@ -435,15 +425,14 @@ class pkgCache::PkgFileIterator : public Iterator<PackageFile, PkgFileIterator> /*}}}*/ // Version File /*{{{*/ class pkgCache::VerFileIterator : public pkgCache::Iterator<VerFile, VerFileIterator> { - 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);} @@ -454,15 +443,14 @@ class pkgCache::VerFileIterator : public pkgCache::Iterator<VerFile, VerFileIter /*}}}*/ // Description File /*{{{*/ class pkgCache::DescFileIterator : public Iterator<DescFile, DescFileIterator> { - 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);} diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc index f5cf52159..af607a197 100644 --- a/apt-pkg/cacheset.cc +++ b/apt-pkg/cacheset.cc @@ -935,7 +935,8 @@ PackageContainerInterface& PackageContainerInterface::operator=(PackageContainer } PackageContainerInterface::~PackageContainerInterface() {} -PackageUniverse::PackageUniverse(pkgCache * const Owner) : _cont(Owner), d(NULL) { } +PackageUniverse::PackageUniverse(pkgCache * const Owner) : _cont(Owner), d(NULL) {} +PackageUniverse::PackageUniverse(pkgCacheFile * const Owner) : _cont(Owner->GetPkgCache()), d(NULL) {} PackageUniverse::~PackageUniverse() {} VersionContainerInterface::VersionContainerInterface() : d(NULL) {} diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index 5455fe74b..95df55dcc 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -213,13 +213,13 @@ private: // Iterator templates for our Containers /*{{{*/ template<typename Interface, typename Master, typename iterator_type, typename container_iterator, typename container_value> class Container_iterator_base : public std::iterator<typename std::iterator_traits<container_iterator>::iterator_category, container_iterator>, - public Interface::iterator_base + public Interface::template iterator_base<iterator_type> { protected: container_iterator _iter; public: explicit Container_iterator_base(container_iterator i) : _iter(i) {} - inline container_value operator*(void) const { return this->getType(); } + inline container_value operator*(void) const { return static_cast<iterator_type const*>(this)->getType(); }; operator container_iterator(void) const { return _iter; } inline iterator_type& operator++() { ++_iter; return static_cast<iterator_type&>(*this); } inline iterator_type operator++(int) { iterator_type tmp(*this); operator++(); return tmp; } @@ -249,7 +249,7 @@ public: explicit Container_const_iterator(container_iterator i) : Container_iterator_base<Interface, Master, iterator_type, container_iterator, typename Container::value_type>(i) {} - inline virtual typename Container::value_type getType(void) const APT_OVERRIDE { return *this->_iter; } + inline typename Container::value_type getType(void) const { return *this->_iter; } }; template<class Interface, class Container, class Master> class Container_iterator : public Container_iterator_base<Interface, Master, Container_iterator<Interface, Container, Master>, typename Container::iterator, typename Container::value_type> @@ -264,7 +264,7 @@ public: inline iterator_type& operator=(iterator_type const &i) { this->_iter = i._iter; return static_cast<iterator_type&>(*this); } inline iterator_type& operator=(container_iterator const &i) { this->_iter = i; return static_cast<iterator_type&>(*this); } - inline virtual typename Container::value_type getType(void) const APT_OVERRIDE { return *this->_iter; } + inline typename Container::value_type getType(void) const { return *this->_iter; } }; template<class Interface, class Container, class Master> class Container_const_reverse_iterator : public Container_iterator_base<Interface, Master, Container_const_reverse_iterator<Interface, Container, Master>, typename Container::const_reverse_iterator, typename Container::value_type> @@ -275,7 +275,7 @@ public: explicit Container_const_reverse_iterator(container_iterator i) : Container_iterator_base<Interface, Master, iterator_type, container_iterator, typename Container::value_type>(i) {} - inline virtual typename Container::value_type getType(void) const APT_OVERRIDE { return *this->_iter; } + inline typename Container::value_type getType(void) const { return *this->_iter; } }; template<class Interface, class Container, class Master> class Container_reverse_iterator : public Container_iterator_base<Interface, Master, Container_reverse_iterator<Interface, Container, Master>, typename Container::reverse_iterator, typename Container::value_type> @@ -290,7 +290,7 @@ public: inline iterator_type& operator=(iterator_type const &i) { this->_iter = i._iter; return static_cast<iterator_type&>(*this); } inline iterator_type& operator=(container_iterator const &i) { this->_iter = i; return static_cast<iterator_type&>(*this); } - inline virtual typename Container::value_type getType(void) const APT_OVERRIDE { return *this->_iter; } + inline typename Container::value_type getType(void) const { return *this->_iter; } }; /*}}}*/ class PackageContainerInterface { /*{{{*/ @@ -304,9 +304,8 @@ class PackageContainerInterface { /*{{{*/ * This class mostly protects use from the need to write all implementation * of the methods working on containers in the template */ public: - class iterator_base { /*{{{*/ - protected: - virtual pkgCache::PkgIterator getType() const = 0; + template<class Itr> class iterator_base { /*{{{*/ + pkgCache::PkgIterator getType() const { return static_cast<Itr const*>(this)->getType(); }; public: operator pkgCache::PkgIterator(void) const { return getType(); } @@ -689,41 +688,38 @@ class APT_PUBLIC PackageUniverse : public PackageContainerInterface { public: class const_iterator : public APT::Container_iterator_base<APT::PackageContainerInterface, PackageUniverse, PackageUniverse::const_iterator, pkgCache::PkgIterator, pkgCache::PkgIterator> { - protected: - inline virtual pkgCache::PkgIterator getType(void) const APT_OVERRIDE - { - return _iter; - } public: explicit const_iterator(pkgCache::PkgIterator i): Container_iterator_base<APT::PackageContainerInterface, PackageUniverse, PackageUniverse::const_iterator, pkgCache::PkgIterator, pkgCache::PkgIterator>(i) {} + inline pkgCache::PkgIterator getType(void) const { return _iter; } }; typedef const_iterator iterator; - APT_PUBLIC bool empty() const APT_OVERRIDE { return false; } - APT_PUBLIC size_t size() const APT_OVERRIDE { return _cont->Head().PackageCount; } + bool empty() const APT_OVERRIDE { return false; } + size_t size() const APT_OVERRIDE { return _cont->Head().PackageCount; } - APT_PUBLIC const_iterator begin() const { return const_iterator(_cont->PkgBegin()); } - APT_PUBLIC const_iterator end() const { return const_iterator(_cont->PkgEnd()); } - APT_PUBLIC const_iterator cbegin() const { return const_iterator(_cont->PkgBegin()); } - APT_PUBLIC const_iterator cend() const { return const_iterator(_cont->PkgEnd()); } - APT_PUBLIC iterator begin() { return iterator(_cont->PkgBegin()); } - APT_PUBLIC iterator end() { return iterator(_cont->PkgEnd()); } + const_iterator begin() const { return const_iterator(_cont->PkgBegin()); } + const_iterator end() const { return const_iterator(_cont->PkgEnd()); } + const_iterator cbegin() const { return const_iterator(_cont->PkgBegin()); } + const_iterator cend() const { return const_iterator(_cont->PkgEnd()); } + iterator begin() { return iterator(_cont->PkgBegin()); } + iterator end() { return iterator(_cont->PkgEnd()); } - APT_PUBLIC pkgCache * data() const { return _cont; } + pkgCache * data() const { return _cont; } - explicit APT_PUBLIC PackageUniverse(pkgCache * const Owner); - APT_PUBLIC virtual ~PackageUniverse(); + explicit PackageUniverse(pkgCache * const Owner); + explicit PackageUniverse(pkgCacheFile * const Owner); + virtual ~PackageUniverse(); private: - bool insert(pkgCache::PkgIterator const &) APT_OVERRIDE { return true; } - template<class Cont> void insert(PackageContainer<Cont> const &) { } - void insert(const_iterator, const_iterator) { } + APT_HIDDEN bool insert(pkgCache::PkgIterator const &) APT_OVERRIDE { return true; } + template<class Cont> APT_HIDDEN void insert(PackageContainer<Cont> const &) { } + APT_HIDDEN void insert(const_iterator, const_iterator) { } - void clear() APT_OVERRIDE { } - iterator erase( const_iterator pos ); - iterator erase( const_iterator first, const_iterator last ); + APT_HIDDEN void clear() APT_OVERRIDE { } + APT_HIDDEN iterator erase( const_iterator pos ); + APT_HIDDEN iterator erase( const_iterator first, const_iterator last ); }; /*}}}*/ typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet; @@ -741,9 +737,8 @@ class VersionContainerInterface { /*{{{*/ Same as APT::PackageContainerInterface, just for Versions */ public: /** \brief smell like a pkgCache::VerIterator */ - class iterator_base { /*{{{*/ - protected: - virtual pkgCache::VerIterator getType() const = 0; + template<class Itr> class iterator_base { /*{{{*/ + pkgCache::VerIterator getType() const { return static_cast<Itr const*>(this)->getType(); }; public: operator pkgCache::VerIterator(void) { return getType(); } diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index ae04bc699..aebbffe8b 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -411,7 +411,7 @@ pkgCache::PkgIterator pkgCache::GrpIterator::NextPkg(pkgCache::PkgIterator const // GrpIterator::operator ++ - Postfix incr /*{{{*/ // --------------------------------------------------------------------- /* This will advance to the next logical group in the hash table. */ -void pkgCache::GrpIterator::operator ++(int) +pkgCache::GrpIterator& pkgCache::GrpIterator::operator++() { // Follow the current links if (S != Owner->GrpP) @@ -423,12 +423,13 @@ void pkgCache::GrpIterator::operator ++(int) HashIndex++; S = Owner->GrpP + Owner->HeaderP->GrpHashTableP()[HashIndex]; } + return *this; } /*}}}*/ // PkgIterator::operator ++ - Postfix incr /*{{{*/ // --------------------------------------------------------------------- /* This will advance to the next logical package in the hash table. */ -void pkgCache::PkgIterator::operator ++(int) +pkgCache::PkgIterator& pkgCache::PkgIterator::operator ++() { // Follow the current links if (S != Owner->PkgP) @@ -440,6 +441,7 @@ void pkgCache::PkgIterator::operator ++(int) HashIndex++; S = Owner->PkgP + Owner->HeaderP->PkgHashTableP()[HashIndex]; } + return *this; } /*}}}*/ // PkgIterator::State - Check the State of the package /*{{{*/ @@ -685,7 +687,7 @@ void pkgCache::DepIterator::GlobOr(DepIterator &Start,DepIterator &End) for (bool LastOR = true; end() == false && LastOR == true;) { LastOR = (S->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or; - (*this)++; + ++(*this); if (LastOR == true) End = (*this); } diff --git a/apt-private/private-cachefile.h b/apt-private/private-cachefile.h index 221852629..ed9342db0 100644 --- a/apt-private/private-cachefile.h +++ b/apt-private/private-cachefile.h @@ -72,13 +72,12 @@ public: class const_iterator : public APT::Container_iterator_base<APT::PackageContainerInterface, SortedPackageUniverse, SortedPackageUniverse::const_iterator, std::vector<map_pointer_t>::const_iterator, pkgCache::PkgIterator> { pkgCache * const Cache; - protected: - inline virtual pkgCache::PkgIterator getType(void) const APT_OVERRIDE + public: + inline pkgCache::PkgIterator getType(void) const { if (*_iter == 0) return pkgCache::PkgIterator(*Cache); return pkgCache::PkgIterator(*Cache, Cache->PkgP + *_iter); } - public: explicit const_iterator(pkgCache * const Owner, std::vector<map_pointer_t>::const_iterator i): Container_iterator_base<APT::PackageContainerInterface, SortedPackageUniverse, SortedPackageUniverse::const_iterator, std::vector<map_pointer_t>::const_iterator, pkgCache::PkgIterator>(i), Cache(Owner) {} |