X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/ffb081b79263a699a612583fcf1b9957b5900a77..a473295d01ed9c599926d9a8c212d4e1a404f78b:/apt-pkg/cacheset.h diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index df437084b..7edeac4af 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -15,8 +15,10 @@ #if __cplusplus >= 201103L #include #include +#include #endif #include +#include #include #include #include @@ -74,8 +76,7 @@ public: /*{{{*/ pkgCacheFile &Cache, const char * cmdline, std::list const &mods); - // use PackageFrom(PACKAGENAME, …) instead - APT_DEPRECATED pkgCache::PkgIterator PackageFromName(pkgCacheFile &Cache, std::string const &pattern); + APT_DEPRECATED_MSG("use .PackageFrom(PACKAGENAME, …) instead") pkgCache::PkgIterator PackageFromName(pkgCacheFile &Cache, std::string const &pattern); /** \brief be notified about the package being selected via pattern * @@ -87,10 +88,10 @@ public: /*{{{*/ */ virtual void showPackageSelection(pkgCache::PkgIterator const &pkg, PkgSelector const select, std::string const &pattern); // use the method above instead, react only on the type you need and let the base handle the rest if need be - // this allows use to add new selection methods without breaking the ABI constantly with new virtual methods - APT_DEPRECATED virtual void showTaskSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); - APT_DEPRECATED virtual void showRegExSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); - APT_DEPRECATED virtual void showFnmatchSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); + // this allows us to add new selection methods without breaking the ABI constantly with new virtual methods + APT_DEPRECATED_MSG("override .showPackageSelection and select with switch") virtual void showTaskSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); + APT_DEPRECATED_MSG("override .showPackageSelection and select with switch") virtual void showRegExSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); + APT_DEPRECATED_MSG("override .showPackageSelection and select with switch") virtual void showFnmatchSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern); /** \brief be notified if a package can't be found via pattern * @@ -103,10 +104,10 @@ public: /*{{{*/ */ virtual void canNotFindPackage(enum PkgSelector const select, PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern); // same as above for showPackageSelection - APT_DEPRECATED virtual void canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); - APT_DEPRECATED virtual void canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); - APT_DEPRECATED virtual void canNotFindFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); - APT_DEPRECATED virtual void canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str); + APT_DEPRECATED_MSG("override .canNotFindPackage and select with switch") virtual void canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); + APT_DEPRECATED_MSG("override .canNotFindPackage and select with switch") virtual void canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); + APT_DEPRECATED_MSG("override .canNotFindPackage and select with switch") virtual void canNotFindFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern); + APT_DEPRECATED_MSG("override .canNotFindPackage and select with switch") virtual void canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str); /** \brief specifies which version(s) we want to refer to */ enum VerSelector { @@ -143,8 +144,7 @@ public: /*{{{*/ */ virtual void showVersionSelection(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const &Ver, enum VerSelector const select, std::string const &pattern); - // renamed to have a similar interface to showPackageSelection - APT_DEPRECATED virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver, + APT_DEPRECATED_MSG("use .showVersionSelection instead, similar to .showPackageSelection") virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver, std::string const &ver, bool const verIsRel); /** \brief be notified if a version can't be found for a package @@ -157,23 +157,21 @@ public: /*{{{*/ * \param Pkg is the package we wanted a version from */ virtual void canNotFindVersion(enum VerSelector const select, VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); - // same as above for showPackageSelection - APT_DEPRECATED virtual void canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); - APT_DEPRECATED virtual void canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, + APT_DEPRECATED_MSG("override .canNotFindVersion and select via switch") virtual void canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); + APT_DEPRECATED_MSG("override .canNotFindVersion and select via switch") virtual void canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); - APT_DEPRECATED virtual void canNotFindCandInstVer(VersionContainerInterface * const vci, + APT_DEPRECATED_MSG("override .canNotFindVersion and select via switch") virtual void canNotFindCandInstVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); // the difference between canNotFind and canNotGet is that the later is more low-level // and called from other places: In this case looking into the code is the only real answer… virtual pkgCache::VerIterator canNotGetVersion(enum VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); - // same as above for showPackageSelection - APT_DEPRECATED virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, + APT_DEPRECATED_MSG("override .canNotGetVersion and select via switch") virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); - APT_DEPRECATED virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, + APT_DEPRECATED_MSG("override .canNotGetVersion and select via switch") virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); - APT_DEPRECATED virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache, + APT_DEPRECATED_MSG("override .canNotGetVersion and select via switch") virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg); virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str); @@ -209,7 +207,92 @@ protected: private: void * const d; }; /*}}}*/ +// Iterator templates for our Containers /*{{{*/ +template class Container_iterator_base : + public std::iterator::iterator_category, container_value>, + 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 typename container_iterator::difference_type operator-(iterator_type const &b) { return (_iter - b._iter); } + 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::iterator::reference operator*(void) const { return *this->_iter; } + + 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::reverse_iterator::reference operator*(void) const { return *this->_iter; } + + inline typename Container::value_type getType(void) const { return *this->_iter; } +}; + /*}}}*/ class PackageContainerInterface { /*{{{*/ /** \class PackageContainerInterface @@ -221,44 +304,44 @@ 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(); } - APT_DEPRECATED inline const char *Section() const { + 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_MSG("Use the .Section method of VerIterator instead") 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(); } + APT_DEPRECATED_MSG("This method does not respect apt_preferences! Use pkgDepCache::GetCandidateVersion(Pkg)") 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, + enum APT_DEPRECATED_MSG("Use CacheSetHelper::PkgSelector instead") Constructor { UNKNOWN = CacheSetHelper::UNKNOWN, REGEX = CacheSetHelper::REGEX, TASK = CacheSetHelper::TASK, FNMATCH = CacheSetHelper::FNMATCH }; @@ -273,25 +356,25 @@ APT_IGNORE_DEPRECATED_POP PackageContainerInterface& operator=(PackageContainerInterface const &other); virtual ~PackageContainerInterface(); - APT_DEPRECATED static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { + APT_DEPRECATED_MSG("Use helper.PackageFrom(CacheSetHelper::TASK, …) instead") static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { return helper.PackageFrom(CacheSetHelper::TASK, pci, Cache, pattern); } - APT_DEPRECATED static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { + APT_DEPRECATED_MSG("Use helper.PackageFrom(CacheSetHelper::REGEX, …) instead") static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { return helper.PackageFrom(CacheSetHelper::REGEX, pci, Cache, pattern); } - APT_DEPRECATED static bool FromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { + APT_DEPRECATED_MSG("Use helper.PackageFrom(CacheSetHelper::FNMATCH, …) instead") static bool FromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { return helper.PackageFrom(CacheSetHelper::FNMATCH, pci, Cache, pattern); } - APT_DEPRECATED static bool FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { + APT_DEPRECATED_MSG("Use helper.PackageFrom(CacheSetHelper::PACKAGENAME, …) instead") static bool FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { return helper.PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, pattern); } - APT_DEPRECATED static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { + APT_DEPRECATED_MSG("Use helper.PackageFrom(CacheSetHelper::STRING, …) instead") static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { return helper.PackageFrom(CacheSetHelper::STRING, pci, Cache, pattern); } - APT_DEPRECATED static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) { + APT_DEPRECATED_MSG("Use helper.PackageFromCommandLine instead") static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) { return helper.PackageFromCommandLine(pci, Cache, cmdline); } - APT_DEPRECATED typedef CacheSetHelper::PkgModifier Modifier; + APT_DEPRECATED_MSG("enum moved to CacheSetHelper::PkgModifier") typedef CacheSetHelper::PkgModifier Modifier; APT_IGNORE_DEPRECATED_PUSH - APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { + APT_DEPRECATED_MSG("Use helper.PackageFromName instead") static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { return helper.PackageFromName(Cache, pattern); } - APT_DEPRECATED static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci, + APT_DEPRECATED_MSG("Use helper.PackageFromModifierCommandLine instead") static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci, pkgCacheFile &Cache, const char * cmdline, std::list const &mods, CacheSetHelper &helper) { return helper.PackageFromModifierCommandLine(modID, pci, Cache, cmdline, mods); } @@ -311,78 +394,27 @@ template class PackageContainer : public PackageContainerInterf Container _cont; public: /*{{{*/ /** \brief smell like a pkgCache::PkgIterator */ - class const_iterator : public PackageContainerInterface::const_iterator,/*{{{*/ - public std::iterator::iterator_category, typename Container::const_iterator> { - typedef typename Container::const_iterator container_iterator; - container_iterator _iter; - typedef const_iterator iterator_type; - public: - explicit const_iterator(container_iterator i) : _iter(i) {} - inline pkgCache::PkgIterator getPkg(void) const { return *_iter; } - inline pkgCache::PkgIterator operator*(void) const { return *_iter; } - operator container_iterator(void) const { return _iter; } - inline iterator_type& operator++() { ++_iter; return *this; } - inline iterator_type operator++(int) { iterator_type tmp(*this); operator++(); return tmp; } - inline iterator_type operator+(typename iterator_type::difference_type const &n) { return iterator_type(_iter + n); } - inline iterator_type operator+=(typename iterator_type::difference_type const &n) { _iter += n; return *this; } - inline iterator_type& operator--() { --_iter; return *this; } - inline iterator_type operator--(int) { iterator_type tmp(*this); operator--(); return tmp; } - inline iterator_type operator-(typename iterator_type::difference_type const &n) { return iterator_type(_iter - n); } - inline iterator_type operator-=(typename iterator_type::difference_type const &n) { _iter -= n; return *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 iterator_type::reference operator[](typename iterator_type::difference_type const &n) const { return _iter[n]; } - - friend std::ostream& operator<<(std::ostream& out, iterator_type i) { return operator<<(out, *i); } - friend class PackageContainer; - }; - class iterator : public PackageContainerInterface::const_iterator, - public std::iterator::iterator_category, typename Container::iterator> { - typedef typename Container::iterator container_iterator; - container_iterator _iter; - typedef iterator iterator_type; - public: - explicit iterator(container_iterator i) : _iter(i) {} - inline pkgCache::PkgIterator getPkg(void) const { return *_iter; } - inline pkgCache::PkgIterator operator*(void) const { return *_iter; } - operator container_iterator(void) const { return _iter; } - inline iterator_type& operator++() { ++_iter; return *this; } - inline iterator_type operator++(int) { iterator_type tmp(*this); operator++(); return tmp; } - inline iterator_type operator+(typename iterator_type::difference_type const &n) { return iterator_type(_iter + n); } - inline iterator_type operator+=(typename iterator_type::difference_type const &n) { _iter += n; return *this; } - inline iterator_type& operator--() { --_iter; return *this; } - inline iterator_type operator--(int) { iterator_type tmp(*this); operator--(); return tmp; } - inline iterator_type operator-(typename iterator_type::difference_type const &n) { return iterator_type(_iter - n); } - inline iterator_type operator-=(typename iterator_type::difference_type const &n) { _iter -= n; return *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 iterator_type::reference operator[](typename iterator_type::difference_type const &n) const { return _iter[n]; } - - operator typename PackageContainer::const_iterator() { return typename PackageContainer::const_iterator(_iter); } - inline iterator& operator=(iterator_type const &i) { _iter = i._iter; return *this; } - inline iterator& operator=(container_iterator const &i) { _iter = i; return *this; } - - friend std::ostream& operator<<(std::ostream& out, iterator_type i) { return operator<<(out, *i); } - friend class PackageContainer; - }; - /*}}}*/ - - bool insert(pkgCache::PkgIterator const &P) { if (P.end() == true) return false; _cont.insert(P); return true; } + typedef Container_const_iterator const_iterator; + typedef Container_iterator iterator; + typedef Container_const_reverse_iterator const_reverse_iterator; + typedef Container_reverse_iterator reverse_iterator; + typedef typename Container::value_type value_type; + typedef typename Container::pointer pointer; + typedef typename Container::const_pointer const_pointer; + typedef typename Container::reference reference; + typedef typename Container::const_reference const_reference; + typedef typename Container::difference_type difference_type; + typedef typename Container::size_type size_type; + typedef typename Container::allocator_type allocator_type; + + 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(); } -#if __cplusplus >= 201103L + 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 @@ -391,17 +423,32 @@ public: /*{{{*/ #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) {} explicit PackageContainer(CacheSetHelper::PkgSelector const &by) : PackageContainerInterface(by) {} APT_IGNORE_DEPRECATED_PUSH - APT_DEPRECATED PackageContainer(Constructor const &by) : PackageContainerInterface((CacheSetHelper::PkgSelector)by) {} + APT_DEPRECATED_MSG("Construct with a CacheSetHelper::PkgSelector instead") explicit PackageContainer(Constructor const &by) : PackageContainerInterface((CacheSetHelper::PkgSelector)by) {} APT_IGNORE_DEPRECATED_POP + template PackageContainer(Itr first, Itr last) : PackageContainerInterface(CacheSetHelper::UNKNOWN), _cont(first, last) {} +#if __cplusplus >= 201103L + PackageContainer(std::initializer_list list) : PackageContainerInterface(CacheSetHelper::UNKNOWN), _cont(list) {} + void push_back(value_type&& P) { _cont.emplace_back(std::move(P)); } + template void emplace_back(Args&&... args) { _cont.emplace_back(std::forward(args)...); } +#endif + void push_back(const value_type& P) { _cont.push_back(P); } /** \brief sort all included versions with given comparer @@ -468,10 +515,10 @@ APT_IGNORE_DEPRECATED_PUSH \param Cache the package is in \param pattern String the package name should be extracted from \param helper responsible for error and message handling */ - APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { + APT_DEPRECATED_MSG("Use helper.PackageFromName instead") static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) { return helper.PackageFromName(Cache, pattern); } - APT_DEPRECATED static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern) { + APT_DEPRECATED_MSG("Use helper.PackageFromName instead") static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern) { CacheSetHelper helper; return FromName(Cache, pattern, helper); } @@ -546,7 +593,7 @@ 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); @@ -557,6 +604,10 @@ template<> template void PackageContainer 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); @@ -577,6 +628,12 @@ template<> inline bool PackageContainer 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; @@ -593,11 +650,15 @@ template<> inline void PackageContainer _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 +#if APT_GCC_VERSION < 0x409 template<> inline PackageContainer >::iterator PackageContainer >::erase(iterator i) { _cont.erase(i._iter); return end(); @@ -607,8 +668,6 @@ template<> inline PackageContainer >::iterator P return end(); } #endif - /*}}}*/ - template<> template inline bool PackageContainer >::sort(Compare Comp) { std::sort(_cont.begin(), _cont.end(), Comp); return true; @@ -623,6 +682,11 @@ template<> template inline bool PackageContainer template inline bool PackageContainer >::sort(Compare Comp) { + std::sort(_cont.begin(), _cont.end(), Comp); + return true; +} + /*}}}*/ // class PackageUniverse - pkgCache as PackageContainerInterface /*{{{*/ /** \class PackageUniverse @@ -632,34 +696,52 @@ 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; + typedef pkgCache::PkgIterator value_type; + typedef typename pkgCache::PkgIterator* pointer; + typedef typename pkgCache::PkgIterator const* const_pointer; + typedef const pkgCache::PkgIterator& const_reference; + typedef const_reference reference; + typedef const_iterator::difference_type difference_type; + typedef std::make_unsigned::type size_type; + + + 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 const_iterator cbegin() const { return _cont->PkgBegin(); } - APT_PUBLIC const_iterator cend() 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) { } + 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) { } - void clear() { } - 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 > PackageSet; @@ -668,6 +750,7 @@ typedef PackageContainer > PackageUnor typedef PackageContainer > PackageForwardList; #endif typedef PackageContainer > PackageList; +typedef PackageContainer > PackageDeque; typedef PackageContainer > PackageVector; class VersionContainerInterface { /*{{{*/ @@ -676,41 +759,42 @@ 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 { + enum APT_DEPRECATED_MSG("enum moved to CacheSetHelper::VerSelector instead") Version { ALL = CacheSetHelper::ALL, CANDANDINST = CacheSetHelper::CANDANDINST, CANDIDATE = CacheSetHelper::CANDIDATE, @@ -729,7 +813,7 @@ public: enum CacheSetHelper::VerSelector const select) : ID(id), Alias(alias), Pos(pos), SelectVersion(select) {} APT_IGNORE_DEPRECATED_PUSH - APT_DEPRECATED Modifier(unsigned short const &id, const char * const alias, Position const &pos, + APT_DEPRECATED_MSG("Construct with a CacheSetHelper::VerSelector instead") Modifier(unsigned short const &id, const char * const alias, Position const &pos, Version const &select) : ID(id), Alias(alias), Pos(pos), SelectVersion((CacheSetHelper::VerSelector)select) {} APT_IGNORE_DEPRECATED_POP @@ -739,7 +823,7 @@ APT_IGNORE_DEPRECATED_POP const char **cmdline, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper); APT_IGNORE_DEPRECATED_PUSH - APT_DEPRECATED static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache, + APT_DEPRECATED_MSG("Use CacheSetHelper::VerSelector as fallback selector") static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache, const char **cmdline, Version const &fallback, CacheSetHelper &helper) { return FromCommandLine(vci, Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper); @@ -750,7 +834,7 @@ APT_IGNORE_DEPRECATED_POP std::string pkg, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper, bool const onlyFromName = false); APT_IGNORE_DEPRECATED_PUSH - APT_DEPRECATED static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache, + APT_DEPRECATED_MSG("Use CacheSetHelper::VerSelector as fallback selector") static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache, std::string pkg, Version const &fallback, CacheSetHelper &helper, bool const onlyFromName = false) { return FromString(vci, Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper, onlyFromName); @@ -761,7 +845,7 @@ APT_IGNORE_DEPRECATED_POP pkgCache::PkgIterator const &P, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper); APT_IGNORE_DEPRECATED_PUSH - APT_DEPRECATED static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache, + APT_DEPRECATED_MSG("Use CacheSetHelper::VerSelector as fallback selector") static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &P, Version const &fallback, CacheSetHelper &helper) { return FromPackage(vci, Cache, P, (CacheSetHelper::VerSelector)fallback, helper); @@ -781,7 +865,7 @@ APT_IGNORE_DEPRECATED_POP CacheSetHelper::VerSelector const selector, CacheSetHelper &helper); APT_IGNORE_DEPRECATED_PUSH - APT_DEPRECATED static bool FromDependency(VersionContainerInterface * const vci, + APT_DEPRECATED_MSG("Use CacheSetHelper::VerSelector as fallback selector") static bool FromDependency(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::DepIterator const &D, Version const &selector, @@ -824,93 +908,58 @@ 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::iterator_category, typename Container::const_iterator> { - typedef typename Container::const_iterator container_iterator; - container_iterator _iter; - typedef const_iterator iterator_type; - public: - explicit const_iterator(container_iterator i) : _iter(i) {} - inline pkgCache::VerIterator getVer(void) const { return *_iter; } - inline pkgCache::VerIterator operator*(void) const { return *_iter; } - operator container_iterator(void) const { return _iter; } - inline iterator_type& operator++() { ++_iter; return *this; } - inline iterator_type operator++(int) { iterator_type tmp(*this); operator++(); return tmp; } - inline iterator_type operator+(typename iterator_type::difference_type const &n) { return iterator_type(_iter + n); } - inline iterator_type operator+=(typename iterator_type::difference_type const &n) { _iter += n; return *this; } - inline iterator_type& operator--() { --_iter; return *this; } - inline iterator_type operator--(int) { iterator_type tmp(*this); operator--(); return tmp; } - inline iterator_type operator-(typename iterator_type::difference_type const &n) { return iterator_type(_iter - n); } - inline iterator_type operator-=(typename iterator_type::difference_type const &n) { _iter -= n; return *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 iterator_type::reference operator[](typename iterator_type::difference_type const &n) const { return _iter[n]; } - - friend std::ostream& operator<<(std::ostream& out, iterator_type i) { return operator<<(out, *i); } - friend class VersionContainer; - }; - class iterator : public VersionContainerInterface::const_iterator, - public std::iterator::iterator_category, typename Container::iterator> { - typedef typename Container::iterator container_iterator; - container_iterator _iter; - typedef iterator iterator_type; - public: - explicit iterator(container_iterator i) : _iter(i) {} - inline pkgCache::VerIterator getVer(void) const { return *_iter; } - inline pkgCache::VerIterator operator*(void) const { return *_iter; } - operator container_iterator(void) const { return _iter; } - inline iterator_type& operator++() { ++_iter; return *this; } - inline iterator_type operator++(int) { iterator_type tmp(*this); operator++(); return tmp; } - inline iterator_type operator+(typename iterator_type::difference_type const &n) { return iterator_type(_iter + n); } - inline iterator_type operator+=(typename iterator_type::difference_type const &n) { _iter += n; return *this; } - inline iterator_type& operator--() { --_iter; return *this; } - inline iterator_type operator--(int) { iterator_type tmp(*this); operator--(); return tmp; } - inline iterator_type operator-(typename iterator_type::difference_type const &n) { return iterator_type(_iter - n); } - inline iterator_type operator-=(typename iterator_type::difference_type const &n) { _iter -= n; return *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 iterator_type::reference operator[](typename iterator_type::difference_type const &n) const { return _iter[n]; } - - operator typename VersionContainer::const_iterator() { return typename VersionContainer::const_iterator(_iter); } - inline iterator& operator=(iterator_type const &i) { _iter = i._iter; return *this; } - inline iterator& operator=(container_iterator const &i) { _iter = i; return *this; } - - friend std::ostream& operator<<(std::ostream& out, iterator_type i) { return operator<<(out, *i); } - friend class VersionContainer; - }; - /*}}}*/ - bool insert(pkgCache::VerIterator const &V) { if (V.end() == true) return false; _cont.insert(V); return true; } + typedef Container_const_iterator const_iterator; + typedef Container_iterator iterator; + typedef Container_const_reverse_iterator const_reverse_iterator; + typedef Container_reverse_iterator reverse_iterator; + typedef typename Container::value_type value_type; + typedef typename Container::pointer pointer; + typedef typename Container::const_pointer const_pointer; + typedef typename Container::reference reference; + typedef typename Container::const_reference const_reference; + typedef typename Container::difference_type difference_type; + typedef typename Container::size_type size_type; + typedef typename Container::allocator_type allocator_type; + + 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(); } -#if __cplusplus >= 201103L + 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 APT_GCC_VERSION >= 0x409 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)); } + VersionContainer() : VersionContainerInterface() {} + template VersionContainer(Itr first, Itr last) : VersionContainerInterface(), _cont(first, last) {} +#if __cplusplus >= 201103L + VersionContainer(std::initializer_list list) : VersionContainerInterface(), _cont(list) {} + void push_back(value_type&& P) { _cont.emplace_back(std::move(P)); } + template void emplace_back(Args&&... args) { _cont.emplace_back(std::forward(args)...); } +#endif + void push_back(const value_type& P) { _cont.push_back(P); } + /** \brief sort all included versions with given comparer Some containers are sorted by default, some are not and can't be, @@ -1054,7 +1103,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, @@ -1066,15 +1115,15 @@ 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); @@ -1085,6 +1134,10 @@ template<> template void VersionContainer 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); @@ -1105,6 +1158,12 @@ template<> inline bool VersionContainer 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; @@ -1121,11 +1180,15 @@ template<> inline void VersionContainer _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); } -#if __cplusplus < 201103L +#if APT_GCC_VERSION < 0x409 template<> inline VersionContainer >::iterator VersionContainer >::erase(iterator i) { _cont.erase(i._iter); return end(); @@ -1135,8 +1198,6 @@ template<> inline VersionContainer >::iterator V return end(); } #endif - /*}}}*/ - template<> template inline bool VersionContainer >::sort(Compare Comp) { std::sort(_cont.begin(), _cont.end(), Comp); return true; @@ -1151,6 +1212,11 @@ template<> template inline bool VersionContainer template inline bool VersionContainer >::sort(Compare Comp) { + std::sort(_cont.begin(), _cont.end(), Comp); + return true; +} + /*}}}*/ typedef VersionContainer > VersionSet; #if __cplusplus >= 201103L @@ -1158,6 +1224,7 @@ typedef VersionContainer > VersionUnor typedef VersionContainer > VersionForwardList; #endif typedef VersionContainer > VersionList; +typedef VersionContainer > VersionDeque; typedef VersionContainer > VersionVector; } #endif