X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/c687384b7a53887ea455fd824824429615d94f7b..858f91bb796e68b8133574cc85649b9af87a9e8b:/apt-pkg/cacheset.h diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index 29f7540ca..7c03ad97a 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -12,7 +12,12 @@ #include #include #include +#if __cplusplus >= 201103L +#include +#include +#endif #include +#include #include #include #include @@ -205,7 +210,89 @@ protected: private: void * const d; }; /*}}}*/ +// Iterator templates for our Containers /*{{{*/ +template class Container_iterator_base : + public std::iterator::iterator_category, container_iterator>, + public Interface::template iterator_base +{ +protected: + container_iterator _iter; +public: + explicit Container_iterator_base(container_iterator i) : _iter(i) {} + inline container_value operator*(void) const { return static_cast(this)->getType(); }; + operator container_iterator(void) const { return _iter; } + inline iterator_type& operator++() { ++_iter; return static_cast(*this); } + inline iterator_type operator++(int) { iterator_type tmp(*this); operator++(); return tmp; } + inline iterator_type operator+(typename container_iterator::difference_type const &n) { return iterator_type(_iter + n); } + inline iterator_type operator+=(typename container_iterator::difference_type const &n) { _iter += n; return static_cast(*this); } + inline iterator_type& operator--() { --_iter;; return static_cast(*this); } + inline iterator_type operator--(int) { iterator_type tmp(*this); operator--(); return tmp; } + inline iterator_type operator-(typename container_iterator::difference_type const &n) { return iterator_type(_iter - n); } + inline iterator_type operator-=(typename container_iterator::difference_type const &n) { _iter -= n; return static_cast(*this); } + inline bool operator!=(iterator_type const &i) const { return _iter != i._iter; } + inline bool operator==(iterator_type const &i) const { return _iter == i._iter; } + inline bool operator<(iterator_type const &i) const { return _iter < i._iter; } + inline bool operator>(iterator_type const &i) const { return _iter > i._iter; } + inline bool operator<=(iterator_type const &i) const { return _iter <= i._iter; } + inline bool operator>=(iterator_type const &i) const { return _iter >= i._iter; } + inline typename container_iterator::reference operator[](typename container_iterator::difference_type const &n) const { return _iter[n]; } + + friend std::ostream& operator<<(std::ostream& out, iterator_type i) { return operator<<(out, *i); } + friend Master; +}; +template class Container_const_iterator : + public Container_iterator_base, typename Container::const_iterator, typename Container::value_type> +{ + typedef Container_const_iterator iterator_type; + typedef typename Container::const_iterator container_iterator; +public: + explicit Container_const_iterator(container_iterator i) : + Container_iterator_base(i) {} + + inline typename Container::value_type getType(void) const { return *this->_iter; } +}; +template class Container_iterator : + public Container_iterator_base, typename Container::iterator, typename Container::value_type> +{ + typedef Container_iterator iterator_type; + typedef typename Container::iterator container_iterator; +public: + explicit Container_iterator(container_iterator i) : + Container_iterator_base(i) {} + + operator typename Master::const_iterator() { return typename Master::const_iterator(this->_iter); } + inline iterator_type& operator=(iterator_type const &i) { this->_iter = i._iter; return static_cast(*this); } + inline iterator_type& operator=(container_iterator const &i) { this->_iter = i; return static_cast(*this); } + + inline typename Container::value_type getType(void) const { return *this->_iter; } +}; +template class Container_const_reverse_iterator : + public Container_iterator_base, typename Container::const_reverse_iterator, typename Container::value_type> +{ + typedef Container_const_reverse_iterator iterator_type; + typedef typename Container::const_reverse_iterator container_iterator; +public: + explicit Container_const_reverse_iterator(container_iterator i) : + Container_iterator_base(i) {} + + inline typename Container::value_type getType(void) const { return *this->_iter; } +}; +template class Container_reverse_iterator : + public Container_iterator_base, typename Container::reverse_iterator, typename Container::value_type> +{ + typedef Container_reverse_iterator iterator_type; + typedef typename Container::reverse_iterator container_iterator; +public: + explicit Container_reverse_iterator(container_iterator i) : + Container_iterator_base(i) {} + operator typename Master::const_iterator() { return typename Master::const_iterator(this->_iter); } + inline iterator_type& operator=(iterator_type const &i) { this->_iter = i._iter; return static_cast(*this); } + inline iterator_type& operator=(container_iterator const &i) { this->_iter = i; return static_cast(*this); } + + inline typename Container::value_type getType(void) const { return *this->_iter; } +}; + /*}}}*/ class PackageContainerInterface { /*{{{*/ /** \class PackageContainerInterface @@ -217,41 +304,42 @@ 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 const_iterator { /*{{{*/ + template class iterator_base { /*{{{*/ + pkgCache::PkgIterator getType() const { return static_cast(this)->getType(); }; public: - virtual pkgCache::PkgIterator getPkg() const = 0; - operator pkgCache::PkgIterator(void) const { return getPkg(); } + operator pkgCache::PkgIterator(void) const { return getType(); } - inline const char *Name() const {return getPkg().Name(); } - inline std::string FullName(bool const Pretty) const { return getPkg().FullName(Pretty); } - inline std::string FullName() const { return getPkg().FullName(); } + inline const char *Name() const {return getType().Name(); } + inline std::string FullName(bool const Pretty) const { return getType().FullName(Pretty); } + inline std::string FullName() const { return getType().FullName(); } APT_DEPRECATED inline const char *Section() const { APT_IGNORE_DEPRECATED_PUSH - return getPkg().Section(); + return getType().Section(); APT_IGNORE_DEPRECATED_POP } - inline bool Purge() const {return getPkg().Purge(); } - inline const char *Arch() const {return getPkg().Arch(); } - inline pkgCache::GrpIterator Group() const { return getPkg().Group(); } - inline pkgCache::VerIterator VersionList() const { return getPkg().VersionList(); } - inline pkgCache::VerIterator CurrentVer() const { return getPkg().CurrentVer(); } - inline pkgCache::DepIterator RevDependsList() const { return getPkg().RevDependsList(); } - inline pkgCache::PrvIterator ProvidesList() const { return getPkg().ProvidesList(); } - inline pkgCache::PkgIterator::OkState State() const { return getPkg().State(); } - inline const char *CandVersion() const { return getPkg().CandVersion(); } - inline const char *CurVersion() const { return getPkg().CurVersion(); } - inline pkgCache *Cache() const { return getPkg().Cache(); } - inline unsigned long Index() const {return getPkg().Index();} + inline bool Purge() const {return getType().Purge(); } + inline const char *Arch() const {return getType().Arch(); } + inline pkgCache::GrpIterator Group() const { return getType().Group(); } + inline pkgCache::VerIterator VersionList() const { return getType().VersionList(); } + inline pkgCache::VerIterator CurrentVer() const { return getType().CurrentVer(); } + inline pkgCache::DepIterator RevDependsList() const { return getType().RevDependsList(); } + inline pkgCache::PrvIterator ProvidesList() const { return getType().ProvidesList(); } + inline pkgCache::PkgIterator::OkState State() const { return getType().State(); } + inline const char *CandVersion() const { return getType().CandVersion(); } + inline const char *CurVersion() const { return getType().CurVersion(); } + inline pkgCache *Cache() const { return getType().Cache(); } + inline unsigned long Index() const {return getType().Index();} // we have only valid iterators here inline bool end() const { return false; } - inline pkgCache::Package const * operator->() const {return &*getPkg();} + inline pkgCache::Package const * operator->() const {return &*getType();} }; /*}}}*/ virtual bool insert(pkgCache::PkgIterator const &P) = 0; virtual bool empty() const = 0; virtual void clear() = 0; + virtual size_t size() const = 0; // FIXME: This is a bloody hack removed soon. Use CacheSetHelper::PkgSelector ! enum APT_DEPRECATED Constructor { UNKNOWN = CacheSetHelper::UNKNOWN, @@ -307,53 +395,39 @@ template class PackageContainer : public PackageContainerInterf Container _cont; public: /*{{{*/ /** \brief smell like a pkgCache::PkgIterator */ - class const_iterator : public PackageContainerInterface::const_iterator,/*{{{*/ - public std::iterator { - typename Container::const_iterator _iter; - public: - explicit const_iterator(typename Container::const_iterator i) : _iter(i) {} - pkgCache::PkgIterator getPkg(void) const { return *_iter; } - inline pkgCache::PkgIterator operator*(void) const { return *_iter; } - operator typename Container::const_iterator(void) const { return _iter; } - inline const_iterator& operator++() { ++_iter; return *this; } - inline const_iterator operator++(int) { const_iterator tmp(*this); operator++(); return tmp; } - inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; } - inline bool operator==(const_iterator const &i) const { return _iter == i._iter; } - friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); } - }; - class iterator : public PackageContainerInterface::const_iterator, - public std::iterator { - typename Container::iterator _iter; - public: - explicit iterator(typename Container::iterator i) : _iter(i) {} - pkgCache::PkgIterator getPkg(void) const { return *_iter; } - inline pkgCache::PkgIterator operator*(void) const { return *_iter; } - operator typename Container::iterator(void) const { return _iter; } - operator typename PackageContainer::const_iterator() { return typename PackageContainer::const_iterator(_iter); } - inline iterator& operator++() { ++_iter; return *this; } - inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; } - inline bool operator!=(iterator const &i) const { return _iter != i._iter; } - inline bool operator==(iterator const &i) const { return _iter == i._iter; } - inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; } - inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; } - friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); } - }; - /*}}}*/ + typedef Container_const_iterator const_iterator; + typedef Container_iterator iterator; + typedef Container_const_reverse_iterator const_reverse_iterator; + typedef Container_reverse_iterator reverse_iterator; - bool insert(pkgCache::PkgIterator const &P) { if (P.end() == true) return false; _cont.insert(P); return true; } + bool insert(pkgCache::PkgIterator const &P) APT_OVERRIDE { if (P.end() == true) return false; _cont.insert(P); return true; } template void insert(PackageContainer const &pkgcont) { _cont.insert((typename Cont::const_iterator)pkgcont.begin(), (typename Cont::const_iterator)pkgcont.end()); } void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); } - bool empty() const { return _cont.empty(); } - void clear() { return _cont.clear(); } - size_t size() const { return _cont.size(); } - iterator erase( iterator pos ) { return iterator(_cont.erase(pos)); } - iterator erase( iterator first, iterator last ) { return iterator(_cont.erase(first, last)); } - size_t erase(pkgCache::PkgIterator const & P) { size_t oldsize = size(); _cont.erase(std::remove(_cont.begin(), _cont.end(), P), _cont.end()); return oldsize - size(); } + bool empty() const APT_OVERRIDE { return _cont.empty(); } + void clear() APT_OVERRIDE { return _cont.clear(); } + size_t size() const APT_OVERRIDE { return _cont.size(); } +#if __GNUC__ >= 5 || (__GNUC_MINOR__ >= 9 && __GNUC__ >= 4) + iterator erase( const_iterator pos ) { return iterator(_cont.erase(pos._iter)); } + iterator erase( const_iterator first, const_iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); } +#else + iterator erase( iterator pos ) { return iterator(_cont.erase(pos._iter)); } + iterator erase( iterator first, iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); } +#endif const_iterator begin() const { return const_iterator(_cont.begin()); } const_iterator end() const { return const_iterator(_cont.end()); } + const_reverse_iterator rbegin() const { return const_reverse_iterator(_cont.rbegin()); } + const_reverse_iterator rend() const { return const_reverse_iterator(_cont.rend()); } +#if __cplusplus >= 201103L + const_iterator cbegin() const { return const_iterator(_cont.cbegin()); } + const_iterator cend() const { return const_iterator(_cont.cend()); } + const_reverse_iterator crbegin() const { return const_reverse_iterator(_cont.crbegin()); } + const_reverse_iterator crend() const { return const_reverse_iterator(_cont.crend()); } +#endif iterator begin() { return iterator(_cont.begin()); } iterator end() { return iterator(_cont.end()); } + reverse_iterator rbegin() { return reverse_iterator(_cont.rbegin()); } + reverse_iterator rend() { return reverse_iterator(_cont.rend()); } const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); } PackageContainer() : PackageContainerInterface(CacheSetHelper::UNKNOWN) {} @@ -505,16 +579,26 @@ APT_IGNORE_DEPRECATED_POP } /*}}}*/ }; /*}}}*/ -// specialisations for push_back containers: std::list & std::vector /*{{{*/ +// various specialisations for PackageContainer /*{{{*/ template<> template void PackageContainer >::insert(PackageContainer const &pkgcont) { for (typename PackageContainer::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p) _cont.push_back(*p); } +#if __cplusplus >= 201103L +template<> template void PackageContainer >::insert(PackageContainer const &pkgcont) { + for (typename PackageContainer::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p) + _cont.push_front(*p); +} +#endif +template<> template void PackageContainer >::insert(PackageContainer const &pkgcont) { + for (typename PackageContainer::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p) + _cont.push_back(*p); +} template<> template void PackageContainer >::insert(PackageContainer const &pkgcont) { for (typename PackageContainer::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p) _cont.push_back(*p); } -// these two are 'inline' as otherwise the linker has problems with seeing these untemplated +// these are 'inline' as otherwise the linker has problems with seeing these untemplated // specializations again and again - but we need to see them, so that library users can use them template<> inline bool PackageContainer >::insert(pkgCache::PkgIterator const &P) { if (P.end() == true) @@ -522,6 +606,20 @@ template<> inline bool PackageContainer >::inse _cont.push_back(P); return true; } +#if __cplusplus >= 201103L +template<> inline bool PackageContainer >::insert(pkgCache::PkgIterator const &P) { + if (P.end() == true) + return false; + _cont.push_front(P); + return true; +} +#endif +template<> inline bool PackageContainer >::insert(pkgCache::PkgIterator const &P) { + if (P.end() == true) + return false; + _cont.push_back(P); + return true; +} template<> inline bool PackageContainer >::insert(pkgCache::PkgIterator const &P) { if (P.end() == true) return false; @@ -532,16 +630,49 @@ template<> inline void PackageContainer >::inse for (const_iterator p = begin; p != end; ++p) _cont.push_back(*p); } +#if __cplusplus >= 201103L +template<> inline void PackageContainer >::insert(const_iterator begin, const_iterator end) { + for (const_iterator p = begin; p != end; ++p) + _cont.push_front(*p); +} +#endif +template<> inline void PackageContainer >::insert(const_iterator begin, const_iterator end) { + for (const_iterator p = begin; p != end; ++p) + _cont.push_back(*p); +} template<> inline void PackageContainer >::insert(const_iterator begin, const_iterator end) { for (const_iterator p = begin; p != end; ++p) _cont.push_back(*p); } - /*}}}*/ - +#if __cplusplus < 201103L +template<> inline PackageContainer >::iterator PackageContainer >::erase(iterator i) { + _cont.erase(i._iter); + return end(); +} +template<> inline PackageContainer >::iterator PackageContainer >::erase(iterator first, iterator last) { + _cont.erase(first, last); + return end(); +} +#endif template<> template inline bool PackageContainer >::sort(Compare Comp) { std::sort(_cont.begin(), _cont.end(), Comp); return true; } +template<> template inline bool PackageContainer >::sort(Compare Comp) { + _cont.sort(Comp); + return true; +} +#if __cplusplus >= 201103L +template<> template inline bool PackageContainer >::sort(Compare Comp) { + _cont.sort(Comp); + return true; +} +#endif +template<> template inline bool PackageContainer >::sort(Compare Comp) { + std::sort(_cont.begin(), _cont.end(), Comp); + return true; +} + /*}}}*/ // class PackageUniverse - pkgCache as PackageContainerInterface /*{{{*/ /** \class PackageUniverse @@ -551,37 +682,53 @@ template<> template inline bool PackageContainer + { + public: + explicit const_iterator(pkgCache::PkgIterator i): + Container_iterator_base(i) {} + + inline pkgCache::PkgIterator getType(void) const { return _iter; } + }; + typedef const_iterator iterator; + + bool empty() const APT_OVERRIDE { return false; } + size_t size() const APT_OVERRIDE { return _cont->Head().PackageCount; } - APT_PUBLIC bool empty() const { return false; } - APT_PUBLIC size_t size() const { return _cont->Head().PackageCount; } + 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 const_iterator begin() const { return _cont->PkgBegin(); } - APT_PUBLIC const_iterator end() const { return _cont->PkgEnd(); } - APT_PUBLIC iterator begin() { return _cont->PkgBegin(); } - APT_PUBLIC iterator end() { return _cont->PkgEnd(); } + 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 &) { return true; } - template void insert(PackageContainer const &) { } - void insert(const_iterator, const_iterator) { } - - void clear() { } - iterator erase( iterator pos ); - iterator erase( iterator first, iterator last ); - size_t erase(pkgCache::PkgIterator const & P); + APT_HIDDEN bool insert(pkgCache::PkgIterator const &) APT_OVERRIDE { return true; } + template APT_HIDDEN void insert(PackageContainer const &) { } + APT_HIDDEN void insert(const_iterator, const_iterator) { } + + 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 > PackageSet; +#if __cplusplus >= 201103L +typedef PackageContainer > PackageUnorderedSet; +typedef PackageContainer > PackageForwardList; +#endif typedef PackageContainer > PackageList; +typedef PackageContainer > PackageDeque; typedef PackageContainer > PackageVector; class VersionContainerInterface { /*{{{*/ @@ -590,38 +737,39 @@ class VersionContainerInterface { /*{{{*/ Same as APT::PackageContainerInterface, just for Versions */ public: /** \brief smell like a pkgCache::VerIterator */ - class const_iterator { /*{{{*/ + template class iterator_base { /*{{{*/ + pkgCache::VerIterator getType() const { return static_cast(this)->getType(); }; public: - virtual pkgCache::VerIterator getVer() const = 0; - operator pkgCache::VerIterator(void) { return getVer(); } - - inline pkgCache *Cache() const { return getVer().Cache(); } - inline unsigned long Index() const {return getVer().Index();} - inline int CompareVer(const pkgCache::VerIterator &B) const { return getVer().CompareVer(B); } - inline const char *VerStr() const { return getVer().VerStr(); } - inline const char *Section() const { return getVer().Section(); } - inline const char *Arch() const { return getVer().Arch(); } - inline pkgCache::PkgIterator ParentPkg() const { return getVer().ParentPkg(); } - inline pkgCache::DescIterator DescriptionList() const { return getVer().DescriptionList(); } - inline pkgCache::DescIterator TranslatedDescription() const { return getVer().TranslatedDescription(); } - inline pkgCache::DepIterator DependsList() const { return getVer().DependsList(); } - inline pkgCache::PrvIterator ProvidesList() const { return getVer().ProvidesList(); } - inline pkgCache::VerFileIterator FileList() const { return getVer().FileList(); } - inline bool Downloadable() const { return getVer().Downloadable(); } - inline const char *PriorityType() const { return getVer().PriorityType(); } - inline std::string RelStr() const { return getVer().RelStr(); } - inline bool Automatic() const { return getVer().Automatic(); } - inline pkgCache::VerFileIterator NewestFile() const { return getVer().NewestFile(); } + operator pkgCache::VerIterator(void) { return getType(); } + + inline pkgCache *Cache() const { return getType().Cache(); } + inline unsigned long Index() const {return getType().Index();} + inline int CompareVer(const pkgCache::VerIterator &B) const { return getType().CompareVer(B); } + inline const char *VerStr() const { return getType().VerStr(); } + inline const char *Section() const { return getType().Section(); } + inline const char *Arch() const { return getType().Arch(); } + inline pkgCache::PkgIterator ParentPkg() const { return getType().ParentPkg(); } + inline pkgCache::DescIterator DescriptionList() const { return getType().DescriptionList(); } + inline pkgCache::DescIterator TranslatedDescription() const { return getType().TranslatedDescription(); } + inline pkgCache::DepIterator DependsList() const { return getType().DependsList(); } + inline pkgCache::PrvIterator ProvidesList() const { return getType().ProvidesList(); } + inline pkgCache::VerFileIterator FileList() const { return getType().FileList(); } + inline bool Downloadable() const { return getType().Downloadable(); } + inline const char *PriorityType() const { return getType().PriorityType(); } + inline std::string RelStr() const { return getType().RelStr(); } + inline bool Automatic() const { return getType().Automatic(); } + inline pkgCache::VerFileIterator NewestFile() const { return getType().NewestFile(); } // we have only valid iterators here inline bool end() const { return false; } - inline pkgCache::Version const * operator->() const { return &*getVer(); } + inline pkgCache::Version const * operator->() const { return &*getType(); } }; /*}}}*/ virtual bool insert(pkgCache::VerIterator const &V) = 0; virtual bool empty() const = 0; virtual void clear() = 0; + virtual size_t size() const = 0; /** \brief specifies which version(s) will be returned if non is given */ enum APT_DEPRECATED Version { @@ -738,54 +886,38 @@ template class VersionContainer : public VersionContainerInterf pkgCache. */ Container _cont; public: /*{{{*/ - /** \brief smell like a pkgCache::VerIterator */ - class const_iterator : public VersionContainerInterface::const_iterator, - public std::iterator {/*{{{*/ - typename Container::const_iterator _iter; - public: - explicit const_iterator(typename Container::const_iterator i) : _iter(i) {} - pkgCache::VerIterator getVer(void) const { return *_iter; } - inline pkgCache::VerIterator operator*(void) const { return *_iter; } - operator typename Container::const_iterator(void) const { return _iter; } - inline const_iterator& operator++() { ++_iter; return *this; } - inline const_iterator operator++(int) { const_iterator tmp(*this); operator++(); return tmp; } - inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; } - inline bool operator==(const_iterator const &i) const { return _iter == i._iter; } - friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); } - }; - class iterator : public VersionContainerInterface::const_iterator, - public std::iterator { - typename Container::iterator _iter; - public: - explicit iterator(typename Container::iterator i) : _iter(i) {} - pkgCache::VerIterator getVer(void) const { return *_iter; } - inline pkgCache::VerIterator operator*(void) const { return *_iter; } - operator typename Container::iterator(void) const { return _iter; } - operator typename VersionContainer::const_iterator() { return typename VersionContainer::const_iterator(_iter); } - inline iterator& operator++() { ++_iter; return *this; } - inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; } - inline bool operator!=(iterator const &i) const { return _iter != i._iter; } - inline bool operator==(iterator const &i) const { return _iter == i._iter; } - inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; } - inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; } - friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); } - }; - /*}}}*/ + typedef Container_const_iterator const_iterator; + typedef Container_iterator iterator; + typedef Container_const_reverse_iterator const_reverse_iterator; + typedef Container_reverse_iterator reverse_iterator; - bool insert(pkgCache::VerIterator const &V) { if (V.end() == true) return false; _cont.insert(V); return true; } + bool insert(pkgCache::VerIterator const &V) APT_OVERRIDE { if (V.end() == true) return false; _cont.insert(V); return true; } template void insert(VersionContainer const &vercont) { _cont.insert((typename Cont::const_iterator)vercont.begin(), (typename Cont::const_iterator)vercont.end()); } void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); } - bool empty() const { return _cont.empty(); } - void clear() { return _cont.clear(); } - size_t size() const { return _cont.size(); } - iterator erase( iterator pos ) { return iterator(_cont.erase(pos)); } - iterator erase( iterator first, iterator last ) { return iterator(_cont.erase(first, last)); } - size_t erase(pkgCache::VerIterator const & V) { size_t oldsize = size(); _cont.erase(std::remove(_cont.begin(), _cont.end(), V), _cont.end()); return oldsize - size(); } - + bool empty() const APT_OVERRIDE { return _cont.empty(); } + void clear() APT_OVERRIDE { return _cont.clear(); } + size_t size() const APT_OVERRIDE { return _cont.size(); } +#if __GNUC__ >= 5 || (__GNUC_MINOR__ >= 9 && __GNUC__ >= 4) + iterator erase( const_iterator pos ) { return iterator(_cont.erase(pos._iter)); } + iterator erase( const_iterator first, const_iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); } +#else + iterator erase( iterator pos ) { return iterator(_cont.erase(pos._iter)); } + iterator erase( iterator first, iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); } +#endif const_iterator begin() const { return const_iterator(_cont.begin()); } const_iterator end() const { return const_iterator(_cont.end()); } + const_reverse_iterator rbegin() const { return const_reverse_iterator(_cont.rbegin()); } + const_reverse_iterator rend() const { return const_reverse_iterator(_cont.rend()); } +#if __cplusplus >= 201103L + const_iterator cbegin() const { return const_iterator(_cont.cbegin()); } + const_iterator cend() const { return const_iterator(_cont.cend()); } + const_reverse_iterator crbegin() const { return const_reverse_iterator(_cont.crbegin()); } + const_reverse_iterator crend() const { return const_reverse_iterator(_cont.crend()); } +#endif iterator begin() { return iterator(_cont.begin()); } iterator end() { return iterator(_cont.end()); } + reverse_iterator rbegin() { return reverse_iterator(_cont.rbegin()); } + reverse_iterator rend() { return reverse_iterator(_cont.rend()); } const_iterator find(pkgCache::VerIterator const &V) const { return const_iterator(_cont.find(V)); } /** \brief sort all included versions with given comparer @@ -931,7 +1063,7 @@ APT_IGNORE_DEPRECATED_POP static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, CacheSetHelper::VerSelector const selector) { CacheSetHelper helper; - return FromPackage(Cache, D, selector, helper); + return FromDependency(Cache, D, selector, helper); } APT_IGNORE_DEPRECATED_PUSH static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, @@ -943,24 +1075,34 @@ APT_IGNORE_DEPRECATED_PUSH static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, Version const &selector) { CacheSetHelper helper; - return FromPackage(Cache, D, (CacheSetHelper::VerSelector)selector, helper); + return FromDependency(Cache, D, (CacheSetHelper::VerSelector)selector, helper); } APT_IGNORE_DEPRECATED_POP static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) { - return FromPackage(Cache, D, CacheSetHelper::CANDIDATE); + return FromDependency(Cache, D, CacheSetHelper::CANDIDATE); } /*}}}*/ }; /*}}}*/ -// specialisations for push_back containers: std::list & std::vector /*{{{*/ +// various specialisations for VersionContainer /*{{{*/ template<> template void VersionContainer >::insert(VersionContainer const &vercont) { for (typename VersionContainer::const_iterator v = vercont.begin(); v != vercont.end(); ++v) _cont.push_back(*v); } +#if __cplusplus >= 201103L +template<> template void VersionContainer >::insert(VersionContainer const &vercont) { + for (typename VersionContainer::const_iterator v = vercont.begin(); v != vercont.end(); ++v) + _cont.push_front(*v); +} +#endif +template<> template void VersionContainer >::insert(VersionContainer const &vercont) { + for (typename VersionContainer::const_iterator v = vercont.begin(); v != vercont.end(); ++v) + _cont.push_back(*v); +} template<> template void VersionContainer >::insert(VersionContainer const &vercont) { for (typename VersionContainer::const_iterator v = vercont.begin(); v != vercont.end(); ++v) _cont.push_back(*v); } -// these two are 'inline' as otherwise the linker has problems with seeing these untemplated +// these are 'inline' as otherwise the linker has problems with seeing these untemplated // specializations again and again - but we need to see them, so that library users can use them template<> inline bool VersionContainer >::insert(pkgCache::VerIterator const &V) { if (V.end() == true) @@ -968,6 +1110,20 @@ template<> inline bool VersionContainer >::inse _cont.push_back(V); return true; } +#if __cplusplus >= 201103L +template<> inline bool VersionContainer >::insert(pkgCache::VerIterator const &V) { + if (V.end() == true) + return false; + _cont.push_front(V); + return true; +} +#endif +template<> inline bool VersionContainer >::insert(pkgCache::VerIterator const &V) { + if (V.end() == true) + return false; + _cont.push_back(V); + return true; +} template<> inline bool VersionContainer >::insert(pkgCache::VerIterator const &V) { if (V.end() == true) return false; @@ -978,26 +1134,57 @@ template<> inline void VersionContainer >::inse for (const_iterator v = begin; v != end; ++v) _cont.push_back(*v); } +#if __cplusplus >= 201103L +template<> inline void VersionContainer >::insert(const_iterator begin, const_iterator end) { + for (const_iterator v = begin; v != end; ++v) + _cont.push_front(*v); +} +#endif +template<> inline void VersionContainer >::insert(const_iterator begin, const_iterator end) { + for (const_iterator v = begin; v != end; ++v) + _cont.push_back(*v); +} template<> inline void VersionContainer >::insert(const_iterator begin, const_iterator end) { for (const_iterator v = begin; v != end; ++v) _cont.push_back(*v); } - /*}}}*/ - -template<> inline size_t PackageContainer >::erase(pkgCache::PkgIterator const &P) { - return _cont.erase(P); +#if __cplusplus < 201103L +template<> inline VersionContainer >::iterator VersionContainer >::erase(iterator i) { + _cont.erase(i._iter); + return end(); } -template<> inline size_t VersionContainer >::erase(pkgCache::VerIterator const &V) { - return _cont.erase(V); +template<> inline VersionContainer >::iterator VersionContainer >::erase(iterator first, iterator last) { + _cont.erase(first, last); + return end(); } - +#endif template<> template inline bool VersionContainer >::sort(Compare Comp) { std::sort(_cont.begin(), _cont.end(), Comp); return true; } +template<> template inline bool VersionContainer >::sort(Compare Comp) { + _cont.sort(Comp); + return true; +} +#if __cplusplus >= 201103L +template<> template inline bool VersionContainer >::sort(Compare Comp) { + _cont.sort(Comp); + return true; +} +#endif +template<> template inline bool VersionContainer >::sort(Compare Comp) { + std::sort(_cont.begin(), _cont.end(), Comp); + return true; +} + /*}}}*/ typedef VersionContainer > VersionSet; +#if __cplusplus >= 201103L +typedef VersionContainer > VersionUnorderedSet; +typedef VersionContainer > VersionForwardList; +#endif typedef VersionContainer > VersionList; +typedef VersionContainer > VersionDeque; typedef VersionContainer > VersionVector; } #endif