]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/cacheset.h
Merge remote-tracking branch 'origin/feature/source-deb822' into feature/source-deb822
[apt.git] / apt-pkg / cacheset.h
index 411b315134da65968bc41320f2dd68a1b9fdbf94..29103aad9c3f4cffb5dd66c498cb20a5bb02dc57 100644 (file)
 // Include Files                                                       /*{{{*/
 #include <iostream>
 #include <fstream>
-#include <list>
 #include <map>
 #include <set>
+#include <list>
 #include <string>
 #include <iterator>
 
 #include <apt-pkg/error.h>
 #include <apt-pkg/pkgcache.h>
+
+#ifndef APT_8_CLEANER_HEADERS
+#include <apt-pkg/cachefile.h>
+#endif
                                                                        /*}}}*/
 
 class pkgCacheFile;
@@ -127,13 +131,15 @@ public:
        virtual bool empty() const = 0;
        virtual void clear() = 0;
 
-       enum Constructor { UNKNOWN, REGEX, TASK };
+       enum Constructor { UNKNOWN, REGEX, TASK, FNMATCH };
        virtual void setConstructor(Constructor const &con) = 0;
        virtual Constructor getConstructor() const = 0;
 
        static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
        static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
        static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper);
+       static bool FromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
+       static bool FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper);
        static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper);
        static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper);
 
@@ -159,35 +165,56 @@ template<class Container> class PackageContainer : public PackageContainerInterf
        Container _cont;
 public:                                                                        /*{{{*/
        /** \brief smell like a pkgCache::PkgIterator */
-       class const_iterator : public PackageContainerInterface::const_iterator,
-                              public std::iterator<std::forward_iterator_tag, typename Container::const_iterator> {/*{{{*/
+       class const_iterator : public PackageContainerInterface::const_iterator,/*{{{*/
+                              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) {}
                pkgCache::PkgIterator getPkg(void) const { return *_iter; }
                inline pkgCache::PkgIterator operator*(void) const { return *_iter; };
                operator typename Container::const_iterator(void) const { return _iter; }
-               inline void operator++(void) { ++_iter; };
+               inline const_iterator& operator++() { ++_iter; return *this; }
+               inline const_iterator operator++(int) { const_iterator tmp(*this); operator++(); return tmp; }
                inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; };
                inline bool operator==(const_iterator const &i) const { return _iter == i._iter; };
                friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); }
        };
-       // we are not going to allow modify our pkgiterators (it doesn't make sense)…
-       typedef APT::PackageContainer<Container>::const_iterator iterator;
+       class iterator : public PackageContainerInterface::const_iterator,
+                        public std::iterator<std::forward_iterator_tag, typename Container::iterator> {
+               typename Container::iterator _iter;
+       public:
+               iterator(typename Container::iterator i) : _iter(i) {}
+               pkgCache::PkgIterator getPkg(void) const { return *_iter; }
+               inline pkgCache::PkgIterator operator*(void) const { return *_iter; };
+               operator typename Container::iterator(void) const { return _iter; }
+               operator typename PackageContainer<Container>::const_iterator() { return typename PackageContainer<Container>::const_iterator(_iter); }
+               inline iterator& operator++() { ++_iter; return *this; }
+               inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; }
+               inline bool operator!=(iterator const &i) const { return _iter != i._iter; };
+               inline bool operator==(iterator const &i) const { return _iter == i._iter; };
+               inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; };
+               inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; };
+               friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); }
+       };
                                                                        /*}}}*/
 
        bool insert(pkgCache::PkgIterator const &P) { 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()); };
        void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); };
+
        bool empty() const { return _cont.empty(); };
        void clear() { return _cont.clear(); };
-       void erase(iterator position) { _cont.erase((typename Container::const_iterator)position); };
+       //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(); };
 
        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)); };
 
        void setConstructor(Constructor const &by) { ConstructedBy = by; };
@@ -233,6 +260,16 @@ public:                                                                    /*{{{*/
                return FromRegEx(Cache, pattern, helper);
        }
 
+       static PackageContainer FromFnmatch(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
+               PackageContainer cont(FNMATCH);
+               PackageContainerInterface::FromFnmatch(&cont, Cache, pattern, helper);
+               return cont;
+       }
+       static PackageContainer FromFnMatch(pkgCacheFile &Cache, std::string const &pattern) {
+               CacheSetHelper helper;
+               return FromFnmatch(Cache, pattern, helper);
+       }
+
        /** \brief returns a package specified by a string
 
            \param Cache the package is in
@@ -318,7 +355,25 @@ private:                                                           /*{{{*/
        Constructor ConstructedBy;
                                                                        /*}}}*/
 };                                                                     /*}}}*/
+
+template<> template<class Cont> void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
+       for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
+               _cont.push_back(*p);
+};
+// these two are 'inline' as otherwise the linker has problems with seeing these untemplated
+// specializations again and again - but we need to see them, so that library users can use them
+template<> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
+       if (P.end() == true)
+               return false;
+       _cont.push_back(P);
+       return true;
+};
+template<> inline void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
+       for (const_iterator p = begin; p != end; ++p)
+               _cont.push_back(*p);
+};
 typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet;
+typedef PackageContainer<std::list<pkgCache::PkgIterator> > PackageList;
 
 class VersionContainerInterface {                                      /*{{{*/
 /** \class APT::VersionContainerInterface
@@ -406,6 +461,13 @@ public:
                                            std::list<Modifier> const &mods,
                                            CacheSetHelper &helper);
 
+
+       static bool FromDependency(VersionContainerInterface * const vci,
+                                  pkgCacheFile &Cache,
+                                  pkgCache::DepIterator const &D,
+                                  Version const &selector,
+                                  CacheSetHelper &helper);
+
 protected:                                                             /*{{{*/
 
        /** \brief returns the candidate version of the package
@@ -425,7 +487,7 @@ protected:                                                          /*{{{*/
 };
                                                                        /*}}}*/
 template<class Container> class VersionContainer : public VersionContainerInterface {/*{{{*/
-/** \class APT::PackageContainer
+/** \class APT::VersionContainer
 
     Simple wrapper around a container class like std::set to provide a similar
     interface to a set of versions as to the complete set of all versions in the
@@ -441,13 +503,29 @@ public:                                                                   /*{{{*/
                pkgCache::VerIterator getVer(void) const { return *_iter; }
                inline pkgCache::VerIterator operator*(void) const { return *_iter; };
                operator typename Container::const_iterator(void) const { return _iter; }
-               inline void operator++(void) { ++_iter; };
+               inline const_iterator& operator++() { ++_iter; return *this; }
+               inline const_iterator operator++(int) { const_iterator tmp(*this); operator++(); return tmp; }
                inline bool operator!=(const_iterator const &i) const { return _iter != i._iter; };
                inline bool operator==(const_iterator const &i) const { return _iter == i._iter; };
                friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); }
        };
-       // we are not going to allow modify our veriterators (it doesn't make sense)…
-       typedef APT::VersionContainer<Container>::const_iterator iterator;
+       class iterator : public VersionContainerInterface::const_iterator,
+                        public std::iterator<std::forward_iterator_tag, typename Container::iterator> {
+               typename Container::iterator _iter;
+       public:
+               iterator(typename Container::iterator i) : _iter(i) {}
+               pkgCache::VerIterator getVer(void) const { return *_iter; }
+               inline pkgCache::VerIterator operator*(void) const { return *_iter; };
+               operator typename Container::iterator(void) const { return _iter; }
+               operator typename VersionContainer<Container>::const_iterator() { return typename VersionContainer<Container>::const_iterator(_iter); }
+               inline iterator& operator++() { ++_iter; return *this; }
+               inline iterator operator++(int) { iterator tmp(*this); operator++(); return tmp; }
+               inline bool operator!=(iterator const &i) const { return _iter != i._iter; };
+               inline bool operator==(iterator const &i) const { return _iter == i._iter; };
+               inline iterator& operator=(iterator const &i) { _iter = i._iter; return *this; };
+               inline iterator& operator=(typename Container::iterator const &i) { _iter = i; return *this; };
+               friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); }
+       };
                                                                        /*}}}*/
 
        bool insert(pkgCache::VerIterator const &V) { if (V.end() == true) return false; _cont.insert(V); return true; };
@@ -455,13 +533,17 @@ 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 erase(iterator position) { _cont.erase((typename Container::const_iterator)position); };
-       size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); };
+       //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(); };
 
        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::VerIterator const &V) const { return const_iterator(_cont.find(V)); };
 
        /** \brief returns all versions specified on the commandline
@@ -520,7 +602,7 @@ public:                                                                     /*{{{*/
                return FromPackage(Cache, P, fallback, helper);
        }
        static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) {
-               return FromPackage(Cache, P, CANDINST);
+               return FromPackage(Cache, P, CANDIDATE);
        }
 
        static std::map<unsigned short, VersionContainer> GroupedFromCommandLine(
@@ -547,8 +629,41 @@ public:                                                                    /*{{{*/
                return GroupedFromCommandLine(Cache, cmdline,
                                mods, fallback, helper);
        }
+
+       static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
+                                              Version const &selector, CacheSetHelper &helper) {
+               VersionContainer vercon;
+               VersionContainerInterface::FromDependency(&vercon, Cache, D, selector, helper);
+               return vercon;
+       }
+       static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
+                                              Version const &selector) {
+               CacheSetHelper helper;
+               return FromPackage(Cache, D, selector, helper);
+       }
+       static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) {
+               return FromPackage(Cache, D, CANDIDATE);
+       }
                                                                        /*}}}*/
 };                                                                     /*}}}*/
+
+template<> template<class Cont> void VersionContainer<std::list<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
+       for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
+               _cont.push_back(*v);
+};
+// these two are 'inline' as otherwise the linker has problems with seeing these untemplated
+// specializations again and again - but we need to see them, so that library users can use them
+template<> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
+       if (V.end() == true)
+               return false;
+       _cont.push_back(V);
+       return true;
+};
+template<> inline void VersionContainer<std::list<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
+       for (const_iterator v = begin; v != end; ++v)
+               _cont.push_back(*v);
+};
 typedef VersionContainer<std::set<pkgCache::VerIterator> > VersionSet;
+typedef VersionContainer<std::list<pkgCache::VerIterator> > VersionList;
 }
 #endif