From 856d3b06a6eb6a7f455294c69fc13604e099fd56 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 5 Jun 2010 09:20:29 +0200 Subject: Add a method to get a VersionSet from the Commandline and refactor the existing methods a bit to reuse them easier intern --- apt-pkg/cacheset.h | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-) (limited to 'apt-pkg/cacheset.h') diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index f0131bfed..708531b4a 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -14,6 +14,7 @@ #include #include +#include #include /*}}}*/ namespace APT { @@ -68,12 +69,23 @@ public: /*{{{*/ \param Cache the packages are in \param pattern regular expression for package names \param out stream to print the notice to */ - static APT::PackageSet FromRegEx(pkgCache &Cache, std::string pattern, std::ostream &out); - static APT::PackageSet FromRegEx(pkgCache &Cache, std::string const &pattern) { + static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string pattern, std::ostream &out); + static APT::PackageSet FromRegEx(pkgCacheFile &Cache, std::string const &pattern) { std::ostream out (std::ofstream("/dev/null").rdbuf()); return APT::PackageSet::FromRegEx(Cache, pattern, out); } + /** \brief returns all packages specified by a string + + \param Cache the packages are in + \param string String the package name(s) should be extracted from + \param out stream to print various notices to */ + static APT::PackageSet FromString(pkgCacheFile &Cache, const char * const string, std::ostream &out); + static APT::PackageSet FromString(pkgCacheFile &Cache, const char * const string) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::PackageSet::FromString(Cache, string, out); + } + /** \brief returns all packages specified on the commandline Get all package names from the commandline and executes regex's if needed. @@ -81,8 +93,8 @@ public: /*{{{*/ \param Cache the packages are in \param cmdline Command line the package names should be extracted from \param out stream to print various notices to */ - static APT::PackageSet FromCommandLine(pkgCache &Cache, const char **cmdline, std::ostream &out); - static APT::PackageSet FromCommandLine(pkgCache &Cache, const char **cmdline) { + static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, std::ostream &out); + static APT::PackageSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { std::ostream out (std::ofstream("/dev/null").rdbuf()); return APT::PackageSet::FromCommandLine(Cache, cmdline, out); } @@ -133,6 +145,60 @@ public: /*{{{*/ // 103. set::iterator is required to be modifiable, but this allows modification of keys typedef typename APT::VersionSet::const_iterator iterator; + /** \brief specifies which version(s) will be returned if non is given */ + enum Version { + /** All versions */ + ALL, + /** Candidate and installed version */ + CANDANDINST, + /** Candidate version */ + CANDIDATE, + /** Installed version */ + INSTALLED, + /** Candidate or if non installed version */ + CANDINST, + /** Installed or if non candidate version */ + INSTCAND, + /** Newest version */ + NEWEST + }; + + /** \brief returns all versions specified on the commandline + + Get all versions from the commandline, uses given default version if + non specifically requested and executes regex's if needed on names. + \param Cache the packages and versions are in + \param cmdline Command line the versions should be extracted from + \param out stream to print various notices to */ + static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, + APT::VersionSet::Version const &fallback, std::ostream &out); + static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline, + APT::VersionSet::Version const &fallback) { + std::ostream out (std::ofstream("/dev/null").rdbuf()); + return APT::VersionSet::FromCommandLine(Cache, cmdline, fallback, out); + } + static APT::VersionSet FromCommandLine(pkgCacheFile &Cache, const char **cmdline) { + return APT::VersionSet::FromCommandLine(Cache, cmdline, CANDINST); + } + /*}}}*/ +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 + \param AllowError add an error to the stack if not */ + static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg, bool const &AllowError = false); + + /** \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 + \param AllowError add an error to the stack if not */ + static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache, + pkgCache::PkgIterator const &Pkg, bool const &AllowError = false); + /*}}}*/ }; /*}}}*/ } -- cgit v1.2.3