]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/cacheset.h
cleanup Container.erase API to look more like std::containers
[apt.git] / apt-pkg / cacheset.h
index 892ad2dfce0b574b9f3738d7391cd1a4e6d538db..29f7540cab07a90f18a24da8fc33febb918a5e0f 100644 (file)
@@ -23,6 +23,7 @@
 #include <apt-pkg/error.h>
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/macros.h>
 
 #ifndef APT_8_CLEANER_HEADERS
 #include <apt-pkg/cachefile.h>
@@ -49,9 +50,8 @@ class CacheSetHelper {                                                        /*{{{*/
 */
 public:                                                                        /*{{{*/
        CacheSetHelper(bool const ShowError = true,
-               GlobalError::MsgType ErrorType = GlobalError::ERROR) :
-                       ShowError(ShowError), ErrorType(ErrorType) {}
-       virtual ~CacheSetHelper() {}
+               GlobalError::MsgType ErrorType = GlobalError::ERROR);
+       virtual ~CacheSetHelper();
 
        enum PkgSelector { UNKNOWN, REGEX, TASK, FNMATCH, PACKAGENAME, STRING };
 
@@ -202,6 +202,8 @@ protected:
        bool PackageFromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
        bool PackageFromPackageName(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
        bool PackageFromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern);
+private:
+       void * const d;
 };                                                                     /*}}}*/
 
 class PackageContainerInterface {                                      /*{{{*/
@@ -224,14 +226,9 @@ public:
                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 {
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic push
-       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
-          return getPkg().Section();
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic pop
-#endif
+                  APT_IGNORE_DEPRECATED_PUSH
+                     return getPkg().Section();
+                  APT_IGNORE_DEPRECATED_POP
                }
                inline bool Purge() const {return getPkg().Purge(); }
                inline const char *Arch() const {return getPkg().Arch(); }
@@ -261,19 +258,16 @@ public:
                REGEX = CacheSetHelper::REGEX,
                TASK = CacheSetHelper::TASK,
                FNMATCH = CacheSetHelper::FNMATCH };
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic push
-       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
+APT_IGNORE_DEPRECATED_PUSH
        void setConstructor(Constructor const by) { ConstructedBy = (CacheSetHelper::PkgSelector)by; }
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic pop
-#endif
+APT_IGNORE_DEPRECATED_POP
 
        void setConstructor(CacheSetHelper::PkgSelector const by) { ConstructedBy = by; }
        CacheSetHelper::PkgSelector getConstructor() const { return ConstructedBy; }
-       PackageContainerInterface() : ConstructedBy(CacheSetHelper::UNKNOWN) {}
-       PackageContainerInterface(CacheSetHelper::PkgSelector const by) : ConstructedBy(by) {}
+       PackageContainerInterface();
+       explicit PackageContainerInterface(CacheSetHelper::PkgSelector const by);
+       PackageContainerInterface& operator=(PackageContainerInterface const &other);
+       virtual ~PackageContainerInterface();
 
        APT_DEPRECATED static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
           return helper.PackageFrom(CacheSetHelper::TASK, pci, Cache, pattern); }
@@ -290,22 +284,18 @@ public:
 
        APT_DEPRECATED typedef CacheSetHelper::PkgModifier Modifier;
 
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic push
-       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
+APT_IGNORE_DEPRECATED_PUSH
        APT_DEPRECATED 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,
              pkgCacheFile &Cache, const char * cmdline,
              std::list<Modifier> const &mods, CacheSetHelper &helper) {
           return helper.PackageFromModifierCommandLine(modID, pci, Cache, cmdline, mods); }
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic pop
-#endif
+APT_IGNORE_DEPRECATED_POP
 
 private:
        CacheSetHelper::PkgSelector ConstructedBy;
+       void * const d;
 };
                                                                        /*}}}*/
 template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/
@@ -321,7 +311,7 @@ public:                                                                     /*{{{*/
                               public std::iterator<std::forward_iterator_tag, typename Container::const_iterator> {
                typename Container::const_iterator _iter;
        public:
-               const_iterator(typename Container::const_iterator i) : _iter(i) {}
+               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; }
@@ -335,7 +325,7 @@ public:                                                                     /*{{{*/
                         public std::iterator<std::forward_iterator_tag, typename Container::iterator> {
                typename Container::iterator _iter;
        public:
-               iterator(typename Container::iterator i) : _iter(i) {}
+               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; }
@@ -356,29 +346,21 @@ public:                                                                   /*{{{*/
 
        bool empty() const { return _cont.empty(); }
        void clear() { return _cont.clear(); }
-       //FIXME: on ABI break, replace the first with the second without bool
-       void erase(iterator position) { _cont.erase((typename Container::iterator)position); }
-       iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); }
-       size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); }
-       void erase(iterator first, iterator last) { _cont.erase(first, last); }
        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(); }
        const_iterator begin() const { return const_iterator(_cont.begin()); }
        const_iterator end() const { return const_iterator(_cont.end()); }
        iterator begin() { return iterator(_cont.begin()); }
        iterator end() { return iterator(_cont.end()); }
        const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); }
 
-       PackageContainer() : PackageContainerInterface() {}
-       PackageContainer(CacheSetHelper::PkgSelector const &by) : PackageContainerInterface(by) {}
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic push
-       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
+       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) {}
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic pop
-#endif
+APT_IGNORE_DEPRECATED_POP
 
        /** \brief sort all included versions with given comparer
 
@@ -439,10 +421,7 @@ public:                                                                    /*{{{*/
                return FromFnmatch(Cache, pattern, helper);
        }
 
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic push
-       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
+APT_IGNORE_DEPRECATED_PUSH
        /** \brief returns a package specified by a string
 
            \param Cache the package is in
@@ -455,9 +434,7 @@ public:                                                                     /*{{{*/
                CacheSetHelper helper;
                return FromName(Cache, pattern, helper);
        }
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic pop
-#endif
+APT_IGNORE_DEPRECATED_POP
 
        /** \brief returns all packages specified by a string
 
@@ -574,21 +551,23 @@ template<> template<class Compare> inline bool PackageContainer<std::vector<pkgC
 
     The wrapping is read-only in practice modeled by making erase and co
     private methods. */
-class PackageUniverse : public PackageContainerInterface {
+class APT_HIDDEN PackageUniverse : public PackageContainerInterface {
        pkgCache * const _cont;
+       void * const d;
 public:
        typedef pkgCache::PkgIterator iterator;
        typedef pkgCache::PkgIterator const_iterator;
 
-       bool empty() const { return false; }
-       size_t size() const { 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 _cont->PkgBegin(); }
-       const_iterator end() const { return  _cont->PkgEnd(); }
-       iterator begin() { return _cont->PkgBegin(); }
-       iterator end() { return _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(); }
 
-       PackageUniverse(pkgCache * const Owner) : _cont(Owner) { }
+       explicit APT_PUBLIC PackageUniverse(pkgCache * const Owner);
+       APT_PUBLIC virtual ~PackageUniverse();
 
 private:
        bool insert(pkgCache::PkgIterator const &) { return true; }
@@ -596,9 +575,9 @@ private:
        void insert(const_iterator, const_iterator) { }
 
        void clear() { }
-       iterator& erase(iterator &iter) { return iter; }
-       size_t erase(const pkgCache::PkgIterator) { return 0; }
-       void erase(iterator, iterator) { }
+       iterator erase( iterator pos );
+       iterator erase( iterator first, iterator last );
+       size_t erase(pkgCache::PkgIterator const & P);
 };
                                                                        /*}}}*/
 typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet;
@@ -663,65 +642,45 @@ public:
                Modifier (unsigned short const &id, const char * const alias, Position const &pos,
                          enum CacheSetHelper::VerSelector const select) : ID(id), Alias(alias), Pos(pos),
                         SelectVersion(select) {}
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic push
-       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
+APT_IGNORE_DEPRECATED_PUSH
                APT_DEPRECATED 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) {}
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic pop
-#endif
+APT_IGNORE_DEPRECATED_POP
        };
 
        static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache,
                                    const char **cmdline, CacheSetHelper::VerSelector const fallback,
                                    CacheSetHelper &helper);
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic push
-       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
+APT_IGNORE_DEPRECATED_PUSH
        APT_DEPRECATED 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);
        }
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic pop
-#endif
+APT_IGNORE_DEPRECATED_POP
 
        static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache,
                               std::string pkg, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper,
                               bool const onlyFromName = false);
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic push
-       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
+APT_IGNORE_DEPRECATED_PUSH
        APT_DEPRECATED 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);
        }
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic pop
-#endif
+APT_IGNORE_DEPRECATED_POP
 
        static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache,
                                pkgCache::PkgIterator const &P, CacheSetHelper::VerSelector const fallback,
                                CacheSetHelper &helper);
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic push
-       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
+APT_IGNORE_DEPRECATED_PUSH
        APT_DEPRECATED 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);
        }
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic pop
-#endif
+APT_IGNORE_DEPRECATED_POP
 
        static bool FromModifierCommandLine(unsigned short &modID,
                                            VersionContainerInterface * const vci,
@@ -735,10 +694,7 @@ public:
                                   pkgCache::DepIterator const &D,
                                   CacheSetHelper::VerSelector const selector,
                                   CacheSetHelper &helper);
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic push
-       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
+APT_IGNORE_DEPRECATED_PUSH
        APT_DEPRECATED static bool FromDependency(VersionContainerInterface * const vci,
                                   pkgCacheFile &Cache,
                                   pkgCache::DepIterator const &D,
@@ -746,9 +702,13 @@ public:
                                   CacheSetHelper &helper) {
           return FromDependency(vci, Cache, D, (CacheSetHelper::VerSelector)selector, helper);
        }
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic pop
-#endif
+APT_IGNORE_DEPRECATED_POP
+
+       VersionContainerInterface();
+       VersionContainerInterface& operator=(VersionContainerInterface const &other);
+       virtual ~VersionContainerInterface();
+private:
+       void * const d;
 
 protected:                                                             /*{{{*/
 
@@ -783,7 +743,7 @@ public:                                                                     /*{{{*/
                               public std::iterator<std::forward_iterator_tag, typename Container::const_iterator> {/*{{{*/
                typename Container::const_iterator _iter;
        public:
-               const_iterator(typename Container::const_iterator i) : _iter(i) {}
+               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; }
@@ -797,7 +757,7 @@ public:                                                                     /*{{{*/
                         public std::iterator<std::forward_iterator_tag, typename Container::iterator> {
                typename Container::iterator _iter;
        public:
-               iterator(typename Container::iterator i) : _iter(i) {}
+               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; }
@@ -817,12 +777,10 @@ public:                                                                   /*{{{*/
        void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }
        bool empty() const { return _cont.empty(); }
        void clear() { return _cont.clear(); }
-       //FIXME: on ABI break, replace the first with the second without bool
-       void erase(iterator position) { _cont.erase((typename Container::iterator)position); }
-       iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); }
-       size_t erase(const pkgCache::VerIterator x) { return _cont.erase(x); }
-       void erase(iterator first, iterator last) { _cont.erase(first, last); }
        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(); }
 
        const_iterator begin() const { return const_iterator(_cont.begin()); }
        const_iterator end() const { return const_iterator(_cont.end()); }
@@ -879,10 +837,7 @@ public:                                                                    /*{{{*/
        static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg) {
                return FromString(Cache, pkg, CacheSetHelper::CANDINST);
        }
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic push
-       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
+APT_IGNORE_DEPRECATED_PUSH
        static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
                        Version const &fallback, CacheSetHelper &helper) {
                VersionContainer vercon;
@@ -906,9 +861,7 @@ public:                                                                     /*{{{*/
                CacheSetHelper helper;
                return FromString(Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper);
        }
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic pop
-#endif
+APT_IGNORE_DEPRECATED_POP
 
        /** \brief returns all versions specified for the package
 
@@ -927,10 +880,7 @@ public:                                                                    /*{{{*/
                CacheSetHelper helper;
                return FromPackage(Cache, P, fallback, helper);
        }
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic push
-       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
+APT_IGNORE_DEPRECATED_PUSH
        static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
                Version const &fallback, CacheSetHelper &helper) {
                VersionContainer vercon;
@@ -942,9 +892,7 @@ public:                                                                     /*{{{*/
                CacheSetHelper helper;
                return FromPackage(Cache, P, (CacheSetHelper::VerSelector)fallback, helper);
        }
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic pop
-#endif
+APT_IGNORE_DEPRECATED_POP
        static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) {
                return FromPackage(Cache, P, CacheSetHelper::CANDIDATE);
        }
@@ -985,10 +933,7 @@ public:                                                                    /*{{{*/
                CacheSetHelper helper;
                return FromPackage(Cache, D, selector, helper);
        }
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic push
-       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
+APT_IGNORE_DEPRECATED_PUSH
        static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
                                               Version const &selector, CacheSetHelper &helper) {
                VersionContainer vercon;
@@ -1000,9 +945,7 @@ public:                                                                    /*{{{*/
                CacheSetHelper helper;
                return FromPackage(Cache, D, (CacheSetHelper::VerSelector)selector, helper);
        }
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic pop
-#endif
+APT_IGNORE_DEPRECATED_POP
        static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) {
                return FromPackage(Cache, D, CacheSetHelper::CANDIDATE);
        }
@@ -1041,6 +984,13 @@ template<> inline void VersionContainer<std::vector<pkgCache::VerIterator> >::in
 }
                                                                        /*}}}*/
 
+template<> inline size_t PackageContainer<std::set<pkgCache::PkgIterator> >::erase(pkgCache::PkgIterator const &P) {
+       return _cont.erase(P);
+}
+template<> inline size_t VersionContainer<std::set<pkgCache::VerIterator> >::erase(pkgCache::VerIterator const &V) {
+       return _cont.erase(V);
+}
+
 template<> template<class Compare> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::sort(Compare Comp) {
        std::sort(_cont.begin(), _cont.end(), Comp);
        return true;