]> 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 884e8b859cff9aced5259d3251c0a8b75cd49800..29f7540cab07a90f18a24da8fc33febb918a5e0f 100644 (file)
@@ -50,9 +50,8 @@ class CacheSetHelper {                                                        /*{{{*/
 */
 public:                                                                        /*{{{*/
        CacheSetHelper(bool const ShowError = true,
 */
 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 };
 
 
        enum PkgSelector { UNKNOWN, REGEX, TASK, FNMATCH, PACKAGENAME, STRING };
 
@@ -203,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);
        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 {                                      /*{{{*/
 };                                                                     /*}}}*/
 
 class PackageContainerInterface {                                      /*{{{*/
@@ -225,7 +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 {
                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 {
-                  APT_IGNORE_DEPRECATED(return getPkg().Section();)
+                  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(); }
                }
                inline bool Purge() const {return getPkg().Purge(); }
                inline const char *Arch() const {return getPkg().Arch(); }
@@ -261,8 +264,10 @@ APT_IGNORE_DEPRECATED_POP
 
        void setConstructor(CacheSetHelper::PkgSelector const by) { ConstructedBy = by; }
        CacheSetHelper::PkgSelector getConstructor() const { return ConstructedBy; }
 
        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); }
 
        APT_DEPRECATED static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
           return helper.PackageFrom(CacheSetHelper::TASK, pci, Cache, pattern); }
@@ -290,6 +295,7 @@ APT_IGNORE_DEPRECATED_POP
 
 private:
        CacheSetHelper::PkgSelector ConstructedBy;
 
 private:
        CacheSetHelper::PkgSelector ConstructedBy;
+       void * const d;
 };
                                                                        /*}}}*/
 template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/
 };
                                                                        /*}}}*/
 template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/
@@ -305,7 +311,7 @@ public:                                                                     /*{{{*/
                               public std::iterator<std::forward_iterator_tag, typename Container::const_iterator> {
                typename Container::const_iterator _iter;
        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; }
                pkgCache::PkgIterator getPkg(void) const { return *_iter; }
                inline pkgCache::PkgIterator operator*(void) const { return *_iter; }
                operator typename Container::const_iterator(void) const { return _iter; }
@@ -319,7 +325,7 @@ public:                                                                     /*{{{*/
                         public std::iterator<std::forward_iterator_tag, typename Container::iterator> {
                typename Container::iterator _iter;
        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; }
                pkgCache::PkgIterator getPkg(void) const { return *_iter; }
                inline pkgCache::PkgIterator operator*(void) const { return *_iter; }
                operator typename Container::iterator(void) const { return _iter; }
@@ -340,21 +346,18 @@ public:                                                                   /*{{{*/
 
        bool empty() const { return _cont.empty(); }
        void clear() { return _cont.clear(); }
 
        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(); }
        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)); }
 
        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) {}
+       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_IGNORE_DEPRECATED_POP
 APT_IGNORE_DEPRECATED_PUSH
        APT_DEPRECATED PackageContainer(Constructor const &by) : PackageContainerInterface((CacheSetHelper::PkgSelector)by) {}
 APT_IGNORE_DEPRECATED_POP
@@ -550,6 +553,7 @@ template<> template<class Compare> inline bool PackageContainer<std::vector<pkgC
     private methods. */
 class APT_HIDDEN PackageUniverse : public PackageContainerInterface {
        pkgCache * const _cont;
     private methods. */
 class APT_HIDDEN PackageUniverse : public PackageContainerInterface {
        pkgCache * const _cont;
+       void * const d;
 public:
        typedef pkgCache::PkgIterator iterator;
        typedef pkgCache::PkgIterator const_iterator;
 public:
        typedef pkgCache::PkgIterator iterator;
        typedef pkgCache::PkgIterator const_iterator;
@@ -562,7 +566,8 @@ public:
        APT_PUBLIC iterator begin() { return _cont->PkgBegin(); }
        APT_PUBLIC iterator end() { return _cont->PkgEnd(); }
 
        APT_PUBLIC iterator begin() { return _cont->PkgBegin(); }
        APT_PUBLIC iterator end() { return _cont->PkgEnd(); }
 
-       APT_PUBLIC 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; }
 
 private:
        bool insert(pkgCache::PkgIterator const &) { return true; }
@@ -570,9 +575,9 @@ private:
        void insert(const_iterator, const_iterator) { }
 
        void clear() { }
        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;
 };
                                                                        /*}}}*/
 typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet;
@@ -699,6 +704,12 @@ APT_IGNORE_DEPRECATED_PUSH
        }
 APT_IGNORE_DEPRECATED_POP
 
        }
 APT_IGNORE_DEPRECATED_POP
 
+       VersionContainerInterface();
+       VersionContainerInterface& operator=(VersionContainerInterface const &other);
+       virtual ~VersionContainerInterface();
+private:
+       void * const d;
+
 protected:                                                             /*{{{*/
 
        /** \brief returns the candidate version of the package
 protected:                                                             /*{{{*/
 
        /** \brief returns the candidate version of the package
@@ -732,7 +743,7 @@ public:                                                                     /*{{{*/
                               public std::iterator<std::forward_iterator_tag, typename Container::const_iterator> {/*{{{*/
                typename Container::const_iterator _iter;
        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; }
                pkgCache::VerIterator getVer(void) const { return *_iter; }
                inline pkgCache::VerIterator operator*(void) const { return *_iter; }
                operator typename Container::const_iterator(void) const { return _iter; }
@@ -746,7 +757,7 @@ public:                                                                     /*{{{*/
                         public std::iterator<std::forward_iterator_tag, typename Container::iterator> {
                typename Container::iterator _iter;
        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; }
                pkgCache::VerIterator getVer(void) const { return *_iter; }
                inline pkgCache::VerIterator operator*(void) const { return *_iter; }
                operator typename Container::iterator(void) const { return _iter; }
@@ -766,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(); }
        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(); }
        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()); }
 
        const_iterator begin() const { return const_iterator(_cont.begin()); }
        const_iterator end() const { return const_iterator(_cont.end()); }
@@ -975,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;
 template<> template<class Compare> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::sort(Compare Comp) {
        std::sort(_cont.begin(), _cont.end(), Comp);
        return true;