]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/cacheset.h
refer to apt-secure(8) in unsecure repositories warning
[apt.git] / apt-pkg / cacheset.h
index 0b9b9441c1fec24fab59cb6a9f3c0ca7ebf2497b..c790d4311fcab86cff7713f15bba7e695c5f24f0 100644 (file)
@@ -15,6 +15,7 @@
 #if __cplusplus >= 201103L
 #include <unordered_set>
 #include <forward_list>
+#include <initializer_list>
 #endif
 #include <list>
 #include <deque>
@@ -212,14 +213,14 @@ 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 std::iterator<typename std::iterator_traits<container_iterator>::iterator_category, container_value>,
+   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; }
@@ -228,6 +229,7 @@ public:
        inline iterator_type& operator--() { --_iter;; return static_cast<iterator_type&>(*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<iterator_type&>(*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; }
@@ -249,7 +251,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>
@@ -263,8 +265,9 @@ public:
        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<iterator_type&>(*this); }
        inline iterator_type& operator=(container_iterator const &i) { this->_iter = i; return static_cast<iterator_type&>(*this); }
+       inline typename Container::iterator::reference operator*(void) const { return *this->_iter; }
 
-       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 +278,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>
@@ -289,8 +292,9 @@ public:
        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<iterator_type&>(*this); }
        inline iterator_type& operator=(container_iterator const &i) { this->_iter = i; return static_cast<iterator_type&>(*this); }
+       inline typename Container::reverse_iterator::reference operator*(void) const { return *this->_iter; }
 
-       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 +308,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(); }
 
@@ -400,6 +403,14 @@ public:                                                                    /*{{{*/
        typedef Container_iterator<PackageContainerInterface, Container, PackageContainer> iterator;
        typedef Container_const_reverse_iterator<PackageContainerInterface, Container, PackageContainer> const_reverse_iterator;
        typedef Container_reverse_iterator<PackageContainerInterface, Container, PackageContainer> 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<class Cont> void insert(PackageContainer<Cont> const &pkgcont) { _cont.insert((typename Cont::const_iterator)pkgcont.begin(), (typename Cont::const_iterator)pkgcont.end()); }
@@ -408,7 +419,7 @@ public:                                                                     /*{{{*/
        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 __cplusplus >= 201103L
+#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
@@ -434,8 +445,15 @@ public:                                                                    /*{{{*/
        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 explicit PackageContainer(Constructor const &by) : PackageContainerInterface((CacheSetHelper::PkgSelector)by) {}
 APT_IGNORE_DEPRECATED_POP
+       template<typename Itr> PackageContainer(Itr first, Itr last) : PackageContainerInterface(CacheSetHelper::UNKNOWN), _cont(first, last) {}
+#if __cplusplus >= 201103L
+       PackageContainer(std::initializer_list<value_type> list) : PackageContainerInterface(CacheSetHelper::UNKNOWN), _cont(list) {}
+       void push_back(value_type&& P) { _cont.emplace_back(std::move(P)); }
+       template<typename... Args> void emplace_back(Args&&... args) { _cont.emplace_back(std::forward<Args>(args)...); }
+#endif
+       void push_back(const value_type& P) { _cont.push_back(P); }
 
        /** \brief sort all included versions with given comparer
 
@@ -645,7 +663,7 @@ template<> inline void PackageContainer<std::vector<pkgCache::PkgIterator> >::in
        for (const_iterator p = begin; p != end; ++p)
                _cont.push_back(*p);
 }
-#if __cplusplus < 201103L
+#if APT_GCC_VERSION < 0x409
 template<> inline PackageContainer<std::set<pkgCache::PkgIterator> >::iterator PackageContainer<std::set<pkgCache::PkgIterator> >::erase(iterator i) {
        _cont.erase(i._iter);
        return end();
@@ -689,41 +707,46 @@ 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;
+       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<const_iterator::difference_type>::type size_type;
 
-       APT_PUBLIC bool empty() const APT_OVERRIDE { return false; }
-       APT_PUBLIC 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()); }
+       bool empty() const APT_OVERRIDE { return false; }
+       size_t size() const APT_OVERRIDE { return _cont->Head().PackageCount; }
 
-       APT_PUBLIC pkgCache * data() const { return _cont; }
+       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()); }
 
-       explicit APT_PUBLIC PackageUniverse(pkgCache * const Owner);
-       APT_PUBLIC virtual ~PackageUniverse();
+       pkgCache * data() const { return _cont; }
+
+       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 +764,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(); }
 
@@ -891,10 +913,19 @@ template<class Container> class VersionContainer : public VersionContainerInterf
     pkgCache. */
        Container _cont;
 public:                                                                        /*{{{*/
+
        typedef Container_const_iterator<VersionContainerInterface, Container, VersionContainer> const_iterator;
        typedef Container_iterator<VersionContainerInterface, Container, VersionContainer> iterator;
        typedef Container_const_reverse_iterator<VersionContainerInterface, Container, VersionContainer> const_reverse_iterator;
        typedef Container_reverse_iterator<VersionContainerInterface, Container, VersionContainer> 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<class Cont> void insert(VersionContainer<Cont> const &vercont) { _cont.insert((typename Cont::const_iterator)vercont.begin(), (typename Cont::const_iterator)vercont.end()); }
@@ -902,7 +933,7 @@ public:                                                                     /*{{{*/
        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 __cplusplus >= 201103L
+#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
@@ -925,6 +956,15 @@ public:                                                                    /*{{{*/
        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<typename Itr> VersionContainer(Itr first, Itr last) : VersionContainerInterface(), _cont(first, last) {}
+#if __cplusplus >= 201103L
+       VersionContainer(std::initializer_list<value_type> list) : VersionContainerInterface(), _cont(list) {}
+       void push_back(value_type&& P) { _cont.emplace_back(std::move(P)); }
+       template<typename... Args> void emplace_back(Args&&... args) { _cont.emplace_back(std::forward<Args>(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,
@@ -1068,7 +1108,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,
@@ -1080,11 +1120,11 @@ 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);
        }
                                                                        /*}}}*/
 };                                                                     /*}}}*/
@@ -1153,7 +1193,7 @@ template<> inline void VersionContainer<std::vector<pkgCache::VerIterator> >::in
        for (const_iterator v = begin; v != end; ++v)
                _cont.push_back(*v);
 }
-#if __cplusplus < 201103L
+#if APT_GCC_VERSION < 0x409
 template<> inline VersionContainer<std::set<pkgCache::VerIterator> >::iterator VersionContainer<std::set<pkgCache::VerIterator> >::erase(iterator i) {
        _cont.erase(i._iter);
        return end();