+ struct Modifier {
+ enum Position { NONE, PREFIX, POSTFIX };
+ unsigned short ID;
+ const char * const Alias;
+ Position Pos;
+ Version SelectVersion;
+ Modifier (unsigned short const &id, const char * const alias, Position const &pos,
+ Version const &select) : ID(id), Alias(alias), Pos(pos),
+ SelectVersion(select) {};
+ };
+
+ static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache,
+ const char **cmdline, Version const &fallback,
+ CacheSetHelper &helper);
+
+ static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache,
+ std::string pkg, Version const &fallback, CacheSetHelper &helper,
+ bool const onlyFromName = false);
+
+ static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache,
+ pkgCache::PkgIterator const &P, Version const &fallback,
+ CacheSetHelper &helper);
+
+ static bool FromModifierCommandLine(unsigned short &modID,
+ VersionContainerInterface * const vci,
+ pkgCacheFile &Cache, const char * cmdline,
+ 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
+
+ \param Cache to be used to query for information
+ \param Pkg we want the candidate version from this package */
+ static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache,
+ pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper);
+
+ /** \brief returns the installed version of the package
+
+ \param Cache to be used to query for information
+ \param Pkg we want the installed version from this package */
+ static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache,
+ pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper);
+ /*}}}*/
+};
+ /*}}}*/
+template<class Container> class VersionContainer : public VersionContainerInterface {/*{{{*/
+/** \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
+ pkgCache. */
+ Container _cont;
+public: /*{{{*/
+ /** \brief smell like a pkgCache::VerIterator */
+ class const_iterator : public VersionContainerInterface::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::VerIterator getVer(void) const { return *_iter; }
+ inline pkgCache::VerIterator operator*(void) const { return *_iter; };
+ operator typename Container::const_iterator(void) const { return _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); }
+ };
+ 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; };
+ template<class Cont> void insert(VersionContainer<Cont> 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(); };
+ //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)); };
+