]> git.saurik.com Git - apt.git/commitdiff
rework cachesets API to allow future extension
authorDavid Kalnischkies <david@kalnischkies.de>
Wed, 3 Sep 2014 16:16:16 +0000 (18:16 +0200)
committerDavid Kalnischkies <david@kalnischkies.de>
Fri, 26 Sep 2014 22:10:32 +0000 (00:10 +0200)
The introduction of Fnmatch showed that each new selector would require
multiple new virtual methods in the CacheSetHelper to work correctly,
which isn't that great. We now flip to a single virtual method which
handles all cases separated by an enum – as new enum values can be added
without an ABI break.

Great care was taken to make old code work with the new way of organisation,
which means in return that you might be bombarded with deprecation
warnings now if you don't adapt, but code should still compile and work
as before as can be seen in apt itself with this commit.

Git-Dch: Ignore

apt-pkg/cacheset.cc
apt-pkg/cacheset.h
apt-private/private-cacheset.cc
cmdline/apt-cache.cc

index d95a32aff110d617343085a5dce733bd7de188c5..3c38895e972a67338bf2588f9094d9f4d602d4a3 100644 (file)
@@ -55,7 +55,7 @@ bool PackageContainerInterface::FromTask(PackageContainerInterface * const pci,
 
        bool const wasEmpty = pci->empty();
        if (wasEmpty == true)
 
        bool const wasEmpty = pci->empty();
        if (wasEmpty == true)
-               pci->setConstructor(TASK);
+               pci->setConstructor(CacheSetHelper::TASK);
 
        // get the records
        pkgRecords Recs(Cache);
 
        // get the records
        pkgRecords Recs(Cache);
@@ -91,19 +91,19 @@ bool PackageContainerInterface::FromTask(PackageContainerInterface * const pci,
                        continue;
 
                pci->insert(Pkg);
                        continue;
 
                pci->insert(Pkg);
-               helper.showTaskSelection(Pkg, pattern);
+               helper.showPackageSelection(Pkg, CacheSetHelper::TASK, pattern);
                found = true;
        }
        regfree(&Pattern);
 
        if (found == false) {
                found = true;
        }
        regfree(&Pattern);
 
        if (found == false) {
-               helper.canNotFindTask(pci, Cache, pattern);
-               pci->setConstructor(UNKNOWN);
+               helper.canNotFindPackage(CacheSetHelper::TASK, pci, Cache, pattern);
+               pci->setConstructor(CacheSetHelper::UNKNOWN);
                return false;
        }
 
                return false;
        }
 
-       if (wasEmpty == false && pci->getConstructor() != UNKNOWN)
-               pci->setConstructor(UNKNOWN);
+       if (wasEmpty == false && pci->getConstructor() != CacheSetHelper::UNKNOWN)
+               pci->setConstructor(CacheSetHelper::UNKNOWN);
 
        return true;
 }
 
        return true;
 }
@@ -116,7 +116,7 @@ bool PackageContainerInterface::FromRegEx(PackageContainerInterface * const pci,
 
        bool const wasEmpty = pci->empty();
        if (wasEmpty == true)
 
        bool const wasEmpty = pci->empty();
        if (wasEmpty == true)
-               pci->setConstructor(REGEX);
+               pci->setConstructor(CacheSetHelper::REGEX);
 
        size_t archfound = pattern.find_last_of(':');
        std::string arch = "native";
 
        size_t archfound = pattern.find_last_of(':');
        std::string arch = "native";
@@ -150,18 +150,18 @@ bool PackageContainerInterface::FromRegEx(PackageContainerInterface * const pci,
                }
 
                pci->insert(Pkg);
                }
 
                pci->insert(Pkg);
-               helper.showRegExSelection(Pkg, pattern);
+               helper.showPackageSelection(Pkg, CacheSetHelper::REGEX, pattern);
                found = true;
        }
 
        if (found == false) {
                found = true;
        }
 
        if (found == false) {
-               helper.canNotFindRegEx(pci, Cache, pattern);
-               pci->setConstructor(UNKNOWN);
+               helper.canNotFindPackage(CacheSetHelper::REGEX, pci, Cache, pattern);
+               pci->setConstructor(CacheSetHelper::UNKNOWN);
                return false;
        }
 
                return false;
        }
 
-       if (wasEmpty == false && pci->getConstructor() != UNKNOWN)
-               pci->setConstructor(UNKNOWN);
+       if (wasEmpty == false && pci->getConstructor() != CacheSetHelper::UNKNOWN)
+               pci->setConstructor(CacheSetHelper::UNKNOWN);
 
        return true;
 }
 
        return true;
 }
@@ -179,7 +179,7 @@ PackageContainerInterface::FromFnmatch(PackageContainerInterface * const pci,
 
        bool const wasEmpty = pci->empty();
        if (wasEmpty == true)
 
        bool const wasEmpty = pci->empty();
        if (wasEmpty == true)
-               pci->setConstructor(FNMATCH);
+               pci->setConstructor(CacheSetHelper::FNMATCH);
 
        size_t archfound = pattern.find_last_of(':');
        std::string arch = "native";
 
        size_t archfound = pattern.find_last_of(':');
        std::string arch = "native";
@@ -213,26 +213,18 @@ PackageContainerInterface::FromFnmatch(PackageContainerInterface * const pci,
                }
 
                pci->insert(Pkg);
                }
 
                pci->insert(Pkg);
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
-               helper.showFnmatchSelection(Pkg, pattern);
-#else
-               helper.showRegExSelection(Pkg, pattern);
-#endif
+               helper.showPackageSelection(Pkg, CacheSetHelper::FNMATCH, pattern);
                found = true;
        }
 
        if (found == false) {
                found = true;
        }
 
        if (found == false) {
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
-               helper.canNotFindFnmatch(pci, Cache, pattern);
-#else
-                helper.canNotFindRegEx(pci, Cache, pattern);
-#endif
-               pci->setConstructor(UNKNOWN);
+               helper.canNotFindPackage(CacheSetHelper::FNMATCH, pci, Cache, pattern);
+               pci->setConstructor(CacheSetHelper::UNKNOWN);
                return false;
        }
 
                return false;
        }
 
-       if (wasEmpty == false && pci->getConstructor() != UNKNOWN)
-               pci->setConstructor(UNKNOWN);
+       if (wasEmpty == false && pci->getConstructor() != CacheSetHelper::UNKNOWN)
+               pci->setConstructor(CacheSetHelper::UNKNOWN);
 
        return true;
 }
 
        return true;
 }
@@ -321,13 +313,11 @@ bool PackageContainerInterface::FromString(PackageContainerInterface * const pci
 
        if (FromGroup(pci, Cache, str, helper) == false &&
                 FromTask(pci, Cache, str, helper) == false &&
 
        if (FromGroup(pci, Cache, str, helper) == false &&
                 FromTask(pci, Cache, str, helper) == false &&
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
-                 // FIXME: hm, hm, regexp/fnmatch incompatible?
+                // FIXME: hm, hm, regexp/fnmatch incompatible?
                 FromFnmatch(pci, Cache, str, helper) == false &&
                 FromFnmatch(pci, Cache, str, helper) == false &&
-#endif
                 FromRegEx(pci, Cache, str, helper) == false)
        {
                 FromRegEx(pci, Cache, str, helper) == false)
        {
-               helper.canNotFindPackage(pci, Cache, str);
+               helper.canNotFindPackage(CacheSetHelper::PACKAGENAME, pci, Cache, str);
                found = false;
        }
 
                found = false;
        }
 
@@ -391,7 +381,7 @@ bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID,
                                                        pkgCacheFile &Cache, const char * cmdline,
                                                        std::list<Modifier> const &mods,
                                                        CacheSetHelper &helper) {
                                                        pkgCacheFile &Cache, const char * cmdline,
                                                        std::list<Modifier> const &mods,
                                                        CacheSetHelper &helper) {
-       Version select = NEWEST;
+       CacheSetHelper::VerSelector select = CacheSetHelper::NEWEST;
        std::string str = cmdline;
        if (unlikely(str.empty() == true))
                return false;
        std::string str = cmdline;
        if (unlikely(str.empty() == true))
                return false;
@@ -434,7 +424,8 @@ bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID,
 // FromCommandLine - Return all versions specified on commandline      /*{{{*/
 bool VersionContainerInterface::FromCommandLine(VersionContainerInterface * const vci,
                                                pkgCacheFile &Cache, const char **cmdline,
 // FromCommandLine - Return all versions specified on commandline      /*{{{*/
 bool VersionContainerInterface::FromCommandLine(VersionContainerInterface * const vci,
                                                pkgCacheFile &Cache, const char **cmdline,
-                                               Version const &fallback, CacheSetHelper &helper) {
+                                               CacheSetHelper::VerSelector const fallback,
+                                               CacheSetHelper &helper) {
        bool found = false;
        for (const char **I = cmdline; *I != 0; ++I)
                found |= VersionContainerInterface::FromString(vci, Cache, *I, fallback, helper);
        bool found = false;
        for (const char **I = cmdline; *I != 0; ++I)
                found |= VersionContainerInterface::FromString(vci, Cache, *I, fallback, helper);
@@ -444,7 +435,8 @@ bool VersionContainerInterface::FromCommandLine(VersionContainerInterface * cons
 // FromString - Returns all versions spedcified by a string            /*{{{*/
 bool VersionContainerInterface::FromString(VersionContainerInterface * const vci,
                                           pkgCacheFile &Cache, std::string pkg,
 // FromString - Returns all versions spedcified by a string            /*{{{*/
 bool VersionContainerInterface::FromString(VersionContainerInterface * const vci,
                                           pkgCacheFile &Cache, std::string pkg,
-                                          Version const &fallback, CacheSetHelper &helper,
+                                          CacheSetHelper::VerSelector const fallback,
+                                          CacheSetHelper &helper,
                                           bool const onlyFromName) {
         PackageSet pkgset;
         if(FileExists(pkg))
                                           bool const onlyFromName) {
         PackageSet pkgset;
         if(FileExists(pkg))
@@ -470,7 +462,7 @@ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci
        }
 
        bool errors = true;
        }
 
        bool errors = true;
-       if (pkgset.getConstructor() != PackageSet::UNKNOWN)
+       if (pkgset.getConstructor() != CacheSetHelper::UNKNOWN)
                errors = helper.showErrors(false);
 
        bool found = false;
                errors = helper.showErrors(false);
 
        bool found = false;
@@ -489,7 +481,7 @@ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci
                        if (P->VersionList != 0)
                                V = P.VersionList();
                        else
                        if (P->VersionList != 0)
                                V = P.VersionList();
                        else
-                               V = helper.canNotFindNewestVer(Cache, P);
+                               V = helper.canNotGetVersion(CacheSetHelper::NEWEST, Cache, P);
                } else {
                        pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release :
                                        pkgVersionMatch::Version));
                } else {
                        pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release :
                                        pkgVersionMatch::Version));
@@ -506,11 +498,14 @@ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci
                }
                if (V.end() == true)
                        continue;
                }
                if (V.end() == true)
                        continue;
-               helper.showSelectedVersion(P, V, ver, verIsRel);
+               if (verIsRel == true)
+                       helper.showVersionSelection(P, V, CacheSetHelper::RELEASE, ver);
+               else
+                       helper.showVersionSelection(P, V, CacheSetHelper::VERSIONNUMBER, ver);
                vci->insert(V);
                found = true;
        }
                vci->insert(V);
                found = true;
        }
-       if (pkgset.getConstructor() != PackageSet::UNKNOWN)
+       if (pkgset.getConstructor() != CacheSetHelper::UNKNOWN)
                helper.showErrors(errors);
        return found;
 }
                helper.showErrors(errors);
        return found;
 }
@@ -519,30 +514,30 @@ bool VersionContainerInterface::FromString(VersionContainerInterface * const vci
 bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vci,
                                            pkgCacheFile &Cache,
                                            pkgCache::PkgIterator const &P,
 bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vci,
                                            pkgCacheFile &Cache,
                                            pkgCache::PkgIterator const &P,
-                                           Version const &fallback,
+                                           CacheSetHelper::VerSelector const fallback,
                                            CacheSetHelper &helper) {
        pkgCache::VerIterator V;
        bool showErrors;
        bool found = false;
        switch(fallback) {
                                            CacheSetHelper &helper) {
        pkgCache::VerIterator V;
        bool showErrors;
        bool found = false;
        switch(fallback) {
-       case ALL:
+       case CacheSetHelper::ALL:
                if (P->VersionList != 0)
                        for (V = P.VersionList(); V.end() != true; ++V)
                                found |= vci->insert(V);
                else
                if (P->VersionList != 0)
                        for (V = P.VersionList(); V.end() != true; ++V)
                                found |= vci->insert(V);
                else
-                       helper.canNotFindAllVer(vci, Cache, P);
+                       helper.canNotFindVersion(CacheSetHelper::ALL, vci, Cache, P);
                break;
                break;
-       case CANDANDINST:
+       case CacheSetHelper::CANDANDINST:
                found |= vci->insert(getInstalledVer(Cache, P, helper));
                found |= vci->insert(getCandidateVer(Cache, P, helper));
                break;
                found |= vci->insert(getInstalledVer(Cache, P, helper));
                found |= vci->insert(getCandidateVer(Cache, P, helper));
                break;
-       case CANDIDATE:
+       case CacheSetHelper::CANDIDATE:
                found |= vci->insert(getCandidateVer(Cache, P, helper));
                break;
                found |= vci->insert(getCandidateVer(Cache, P, helper));
                break;
-       case INSTALLED:
+       case CacheSetHelper::INSTALLED:
                found |= vci->insert(getInstalledVer(Cache, P, helper));
                break;
                found |= vci->insert(getInstalledVer(Cache, P, helper));
                break;
-       case CANDINST:
+       case CacheSetHelper::CANDINST:
                showErrors = helper.showErrors(false);
                V = getCandidateVer(Cache, P, helper);
                if (V.end() == true)
                showErrors = helper.showErrors(false);
                V = getCandidateVer(Cache, P, helper);
                if (V.end() == true)
@@ -551,9 +546,9 @@ bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vc
                if (V.end() == false)
                        found |= vci->insert(V);
                else
                if (V.end() == false)
                        found |= vci->insert(V);
                else
-                       helper.canNotFindInstCandVer(vci, Cache, P);
+                       helper.canNotFindVersion(CacheSetHelper::CANDINST, vci, Cache, P);
                break;
                break;
-       case INSTCAND:
+       case CacheSetHelper::INSTCAND:
                showErrors = helper.showErrors(false);
                V = getInstalledVer(Cache, P, helper);
                if (V.end() == true)
                showErrors = helper.showErrors(false);
                V = getInstalledVer(Cache, P, helper);
                if (V.end() == true)
@@ -562,14 +557,18 @@ bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vc
                if (V.end() == false)
                        found |= vci->insert(V);
                else
                if (V.end() == false)
                        found |= vci->insert(V);
                else
-                       helper.canNotFindInstCandVer(vci, Cache, P);
+                       helper.canNotFindVersion(CacheSetHelper::INSTCAND, vci, Cache, P);
                break;
                break;
-       case NEWEST:
+       case CacheSetHelper::NEWEST:
                if (P->VersionList != 0)
                        found |= vci->insert(P.VersionList());
                else
                if (P->VersionList != 0)
                        found |= vci->insert(P.VersionList());
                else
-                       helper.canNotFindNewestVer(Cache, P);
+                       helper.canNotFindVersion(CacheSetHelper::NEWEST, vci, Cache, P);
                break;
                break;
+       case CacheSetHelper::RELEASE:
+       case CacheSetHelper::VERSIONNUMBER:
+               // both make no sense here, so always false
+               return false;
        }
        return found;
 }
        }
        return found;
 }
@@ -586,7 +585,7 @@ pkgCache::VerIterator VersionContainerInterface::getCandidateVer(pkgCacheFile &C
                Cand = Cache[Pkg].CandidateVerIter(Cache);
        }
        if (Cand.end() == true)
                Cand = Cache[Pkg].CandidateVerIter(Cache);
        }
        if (Cand.end() == true)
-               return helper.canNotFindCandidateVer(Cache, Pkg);
+               return helper.canNotGetVersion(CacheSetHelper::CANDIDATE, Cache, Pkg);
        return Cand;
 }
                                                                        /*}}}*/
        return Cand;
 }
                                                                        /*}}}*/
@@ -594,19 +593,30 @@ pkgCache::VerIterator VersionContainerInterface::getCandidateVer(pkgCacheFile &C
 pkgCache::VerIterator VersionContainerInterface::getInstalledVer(pkgCacheFile &Cache,
                pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) {
        if (Pkg->CurrentVer == 0)
 pkgCache::VerIterator VersionContainerInterface::getInstalledVer(pkgCacheFile &Cache,
                pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) {
        if (Pkg->CurrentVer == 0)
-               return helper.canNotFindInstalledVer(Cache, Pkg);
+               return helper.canNotGetVersion(CacheSetHelper::INSTALLED, Cache, Pkg);
        return Pkg.CurrentVer();
 }
                                                                        /*}}}*/
 
        return Pkg.CurrentVer();
 }
                                                                        /*}}}*/
 
-// canNotFindPkgName - handle the case no package has this name                /*{{{*/
-pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache,
-                       std::string const &str) {
-       if (ShowError == true)
-               _error->Insert(ErrorType, _("Unable to locate package %s"), str.c_str());
-       return pkgCache::PkgIterator(Cache, 0);
+// canNotFindPackage - with the given selector and pattern             /*{{{*/
+void CacheSetHelper::canNotFindPackage(enum PkgSelector const select,
+      PackageContainerInterface * const pci, pkgCacheFile &Cache,
+      std::string const &pattern) {
+       switch (select) {
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic push
+       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+       case REGEX: canNotFindRegEx(pci, Cache, pattern); break;
+       case TASK: canNotFindTask(pci, Cache, pattern); break;
+       case FNMATCH: canNotFindFnmatch(pci, Cache, pattern); break;
+       case PACKAGENAME: canNotFindPackage(pci, Cache, pattern); break;
+       case UNKNOWN: break;
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic pop
+#endif
+       }
 }
 }
-                                                                       /*}}}*/
 // canNotFindTask - handle the case no package is found for a task     /*{{{*/
 void CacheSetHelper::canNotFindTask(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
        if (ShowError == true)
 // canNotFindTask - handle the case no package is found for a task     /*{{{*/
 void CacheSetHelper::canNotFindTask(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
        if (ShowError == true)
@@ -618,17 +628,50 @@ void CacheSetHelper::canNotFindRegEx(PackageContainerInterface * const /*pci*/,
        if (ShowError == true)
                _error->Insert(ErrorType, _("Couldn't find any package by regex '%s'"), pattern.c_str());
 }
        if (ShowError == true)
                _error->Insert(ErrorType, _("Couldn't find any package by regex '%s'"), pattern.c_str());
 }
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+                                                                       /*}}}*/
 // canNotFindFnmatch - handle the case no package is found by a fnmatch        /*{{{*/
    void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
        if (ShowError == true)
                _error->Insert(ErrorType, _("Couldn't find any package by glob '%s'"), pattern.c_str());
 }
 // canNotFindFnmatch - handle the case no package is found by a fnmatch        /*{{{*/
    void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
        if (ShowError == true)
                _error->Insert(ErrorType, _("Couldn't find any package by glob '%s'"), pattern.c_str());
 }
-#endif                                                                 /*}}}*/
+                                                                       /*}}}*/
 // canNotFindPackage - handle the case no package is found from a string/*{{{*/
 APT_CONST void CacheSetHelper::canNotFindPackage(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string const &/*str*/) {
 }
                                                                        /*}}}*/
 // canNotFindPackage - handle the case no package is found from a string/*{{{*/
 APT_CONST void CacheSetHelper::canNotFindPackage(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string const &/*str*/) {
 }
                                                                        /*}}}*/
+                                                                       /*}}}*/
+// canNotFindPkgName - handle the case no package has this name                /*{{{*/
+pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache,
+                       std::string const &str) {
+       if (ShowError == true)
+               _error->Insert(ErrorType, _("Unable to locate package %s"), str.c_str());
+       return pkgCache::PkgIterator(Cache, 0);
+}
+                                                                       /*}}}*/
+// canNotFindVersion - for package by selector                         /*{{{*/
+void CacheSetHelper::canNotFindVersion(enum VerSelector const select, VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg)
+{
+       switch (select) {
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic push
+       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+       case ALL: canNotFindAllVer(vci, Cache, Pkg); break;
+       case INSTCAND: canNotFindInstCandVer(vci, Cache, Pkg); break;
+       case CANDINST: canNotFindCandInstVer(vci, Cache, Pkg); break;
+       case NEWEST: canNotFindNewestVer(Cache, Pkg); break;
+       case CANDIDATE: canNotFindCandidateVer(Cache, Pkg); break;
+       case INSTALLED: canNotFindInstalledVer(Cache, Pkg); break;
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic pop
+#endif
+       case CANDANDINST: canNotGetCandInstVer(Cache, Pkg); break;
+       case RELEASE:
+       case VERSIONNUMBER:
+               // invalid in this branch
+               break;
+       }
+}
 // canNotFindAllVer                                                    /*{{{*/
 void CacheSetHelper::canNotFindAllVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
                pkgCache::PkgIterator const &Pkg) {
 // canNotFindAllVer                                                    /*{{{*/
 void CacheSetHelper::canNotFindAllVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
                pkgCache::PkgIterator const &Pkg) {
@@ -637,19 +680,42 @@ void CacheSetHelper::canNotFindAllVer(VersionContainerInterface * const /*vci*/,
 }
                                                                        /*}}}*/
 // canNotFindInstCandVer                                               /*{{{*/
 }
                                                                        /*}}}*/
 // canNotFindInstCandVer                                               /*{{{*/
-void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
+void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &Cache,
                pkgCache::PkgIterator const &Pkg) {
                pkgCache::PkgIterator const &Pkg) {
-       if (ShowError == true)
-               _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
+       canNotGetInstCandVer(Cache, Pkg);
 }
                                                                        /*}}}*/
 // canNotFindInstCandVer                                               /*{{{*/
 }
                                                                        /*}}}*/
 // canNotFindInstCandVer                                               /*{{{*/
-void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
+void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &Cache,
                pkgCache::PkgIterator const &Pkg) {
                pkgCache::PkgIterator const &Pkg) {
-       if (ShowError == true)
-               _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
+       canNotGetCandInstVer(Cache, Pkg);
 }
                                                                        /*}}}*/
 }
                                                                        /*}}}*/
+                                                                       /*}}}*/
+// canNotGetVersion - for package by selector                          /*{{{*/
+pkgCache::VerIterator CacheSetHelper::canNotGetVersion(enum VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) {
+       switch (select) {
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic push
+       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+       case NEWEST: return canNotFindNewestVer(Cache, Pkg);
+       case CANDIDATE: return canNotFindCandidateVer(Cache, Pkg);
+       case INSTALLED: return canNotFindInstalledVer(Cache, Pkg);
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic pop
+#endif
+       case CANDINST: return canNotGetCandInstVer(Cache, Pkg);
+       case INSTCAND: return canNotGetInstCandVer(Cache, Pkg);
+       case ALL:
+       case CANDANDINST:
+       case RELEASE:
+       case VERSIONNUMBER:
+               // invalid in this branch
+               return pkgCache::VerIterator(Cache, 0);
+       }
+       return pkgCache::VerIterator(Cache, 0);
+}
 // canNotFindNewestVer                                                 /*{{{*/
 pkgCache::VerIterator CacheSetHelper::canNotFindNewestVer(pkgCacheFile &Cache,
                pkgCache::PkgIterator const &Pkg) {
 // canNotFindNewestVer                                                 /*{{{*/
 pkgCache::VerIterator CacheSetHelper::canNotFindNewestVer(pkgCacheFile &Cache,
                pkgCache::PkgIterator const &Pkg) {
@@ -674,6 +740,41 @@ pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache
        return pkgCache::VerIterator(Cache, 0);
 }
                                                                        /*}}}*/
        return pkgCache::VerIterator(Cache, 0);
 }
                                                                        /*}}}*/
+// canNotFindInstCandVer                                               /*{{{*/
+pkgCache::VerIterator CacheSetHelper::canNotGetInstCandVer(pkgCacheFile &Cache,
+               pkgCache::PkgIterator const &Pkg) {
+       if (ShowError == true)
+               _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
+       return pkgCache::VerIterator(Cache, 0);
+}
+                                                                       /*}}}*/
+// canNotFindInstCandVer                                               /*{{{*/
+pkgCache::VerIterator CacheSetHelper::canNotGetCandInstVer(pkgCacheFile &Cache,
+               pkgCache::PkgIterator const &Pkg) {
+       if (ShowError == true)
+               _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
+       return pkgCache::VerIterator(Cache, 0);
+}
+                                                                       /*}}}*/
+                                                                       /*}}}*/
+// showPackageSelection - by selector and given pattern                        /*{{{*/
+APT_CONST void CacheSetHelper::showPackageSelection(pkgCache::PkgIterator const &pkg, enum PkgSelector const select,
+                                      std::string const &pattern) {
+       switch (select) {
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic push
+       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+       case REGEX: showRegExSelection(pkg, pattern); break;
+       case TASK: showTaskSelection(pkg, pattern); break;
+       case FNMATCH: showFnmatchSelection(pkg, pattern); break;
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic pop
+#endif
+       case PACKAGENAME: /* no suprises here */ break;
+       case UNKNOWN: break;
+       }
+}
 // showTaskSelection                                                   /*{{{*/
 APT_CONST void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator const &/*pkg*/,
                                       std::string const &/*pattern*/) {
 // showTaskSelection                                                   /*{{{*/
 APT_CONST void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator const &/*pkg*/,
                                       std::string const &/*pattern*/) {
@@ -684,14 +785,41 @@ APT_CONST void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &/
                                        std::string const &/*pattern*/) {
 }
                                                                        /*}}}*/
                                        std::string const &/*pattern*/) {
 }
                                                                        /*}}}*/
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
 // showFnmatchSelection                                                        /*{{{*/
 APT_CONST void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator const &/*pkg*/,
                                          std::string const &/*pattern*/) {
 }
                                                                        /*}}}*/
 // showFnmatchSelection                                                        /*{{{*/
 APT_CONST void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator const &/*pkg*/,
                                          std::string const &/*pattern*/) {
 }
                                                                        /*}}}*/
+                                                                       /*}}}*/
+// showVersionSelection                                                        /*{{{*/
+APT_CONST void CacheSetHelper::showVersionSelection(pkgCache::PkgIterator const &Pkg,
+      pkgCache::VerIterator const &Ver, enum VerSelector const select, std::string const &pattern) {
+       switch (select) {
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic push
+       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+       case RELEASE:
+               showSelectedVersion(Pkg, Ver, pattern, true);
+               break;
+       case VERSIONNUMBER:
+               showSelectedVersion(Pkg, Ver, pattern, false);
+               break;
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic pop
+       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 #endif
 #endif
-// showSelectedVersion                                                 /*{{{*/
+       case NEWEST:
+       case CANDIDATE:
+       case INSTALLED:
+       case CANDINST:
+       case INSTCAND:
+       case ALL:
+       case CANDANDINST:
+               // not really suprises, but in fact: just not implemented
+               break;
+       }
+}
 APT_CONST void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/,
                                         pkgCache::VerIterator const /*Ver*/,
                                         std::string const &/*ver*/,
 APT_CONST void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/,
                                         pkgCache::VerIterator const /*Ver*/,
                                         std::string const &/*ver*/,
index 2656727d4db5bbe7a4b4787ae8be869b9911482c..57a9568083787fac0b7651b45d87b5cdf32effae 100644 (file)
@@ -53,36 +53,109 @@ public:                                                                    /*{{{*/
                        ShowError(ShowError), ErrorType(ErrorType) {}
        virtual ~CacheSetHelper() {}
 
                        ShowError(ShowError), ErrorType(ErrorType) {}
        virtual ~CacheSetHelper() {}
 
-       virtual void showTaskSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
-       virtual void showRegExSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
-       virtual void showFnmatchSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
-#endif
-       virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver,
-                                std::string const &ver, bool const verIsRel);
+       enum PkgSelector { UNKNOWN, PACKAGENAME, REGEX, TASK, FNMATCH };
+
+       /** \brief be notified about the package being selected via pattern
+        *
+        * Main use is probably to show a message to the user what happened
+        *
+        * \param pkg is the package which was selected
+        * \param select is the selection method which choose the package
+        * \param pattern is the string used by the selection method to pick the package
+        */
+       virtual void showPackageSelection(pkgCache::PkgIterator const &pkg, PkgSelector const select, std::string const &pattern);
+       // use the method above instead, react only on the type you need and let the base handle the rest if need be
+       // this allows use to add new selection methods without breaking the ABI constantly with new virtual methods
+       APT_DEPRECATED virtual void showTaskSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
+       APT_DEPRECATED virtual void showRegExSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
+       APT_DEPRECATED virtual void showFnmatchSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
+
+       /** \brief be notified if a package can't be found via pattern
+        *
+        * Can be used to show a message as well as to try something else to make it match
+        *
+        * \param select is the method tried for selection
+        * \param pci is the container the package should be inserted in
+        * \param Cache is the package universe available
+        * \param pattern is the string not matching anything
+        */
+       virtual void canNotFindPackage(enum PkgSelector const select, PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern);
+       // same as above for showPackageSelection
+       APT_DEPRECATED virtual void canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
+       APT_DEPRECATED virtual void canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
+       APT_DEPRECATED virtual void canNotFindFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
+       APT_DEPRECATED virtual void canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str);
+
+       /** \brief specifies which version(s) we want to refer to */
+       enum VerSelector {
+               /** by release string */
+               RELEASE,
+               /** by version number string */
+               VERSIONNUMBER,
+               /** 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
+       };
 
 
-       virtual void canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
-       virtual void canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
-#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
-       virtual void canNotFindFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
-#endif
-       virtual void canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str);
+       /** \brief be notified about the version being selected via pattern
+        *
+        * Main use is probably to show a message to the user what happened
+        * Note that at the moment this method is only called for RELEASE
+        * and VERSION selections, not for the others.
+        *
+        * \param Pkg is the package which was selected for
+        * \param Ver is the version selected
+        * \param select is the selection method which choose the version
+        * \param pattern is the string used by the selection method to pick the version
+        */
+       virtual void showVersionSelection(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const &Ver,
+             enum VerSelector const select, std::string const &pattern);
+       // renamed to have a similar interface to showPackageSelection
+       APT_DEPRECATED virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver,
+                                std::string const &ver, bool const verIsRel);
 
 
-       virtual void canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
-       virtual void canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
+       /** \brief be notified if a version can't be found for a package
+        *
+        * Main use is probably to show a message to the user what happened
+        *
+        * \param select is the method tried for selection
+        * \param vci is the container the version should be inserted in
+        * \param Cache is the package universe available
+        * \param Pkg is the package we wanted a version from
+        */
+       virtual void canNotFindVersion(enum VerSelector const select, VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
+       // same as above for showPackageSelection
+       APT_DEPRECATED virtual void canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
+       APT_DEPRECATED virtual void canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
                                pkgCache::PkgIterator const &Pkg);
                                pkgCache::PkgIterator const &Pkg);
-       virtual void canNotFindCandInstVer(VersionContainerInterface * const vci,
+       APT_DEPRECATED virtual void canNotFindCandInstVer(VersionContainerInterface * const vci,
                                pkgCacheFile &Cache,
                                pkgCache::PkgIterator const &Pkg);
 
                                pkgCacheFile &Cache,
                                pkgCache::PkgIterator const &Pkg);
 
-       virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str);
-       virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache,
+       // the difference between canNotFind and canNotGet is that the later is more low-level
+       // and called from other places: In this case looking into the code is the only real answer…
+       virtual pkgCache::VerIterator canNotGetVersion(enum VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
+       // same as above for showPackageSelection
+       APT_DEPRECATED virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache,
                                pkgCache::PkgIterator const &Pkg);
                                pkgCache::PkgIterator const &Pkg);
-       virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache,
+       APT_DEPRECATED virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache,
                                pkgCache::PkgIterator const &Pkg);
                                pkgCache::PkgIterator const &Pkg);
-       virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache,
+       APT_DEPRECATED virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache,
                                pkgCache::PkgIterator const &Pkg);
 
                                pkgCache::PkgIterator const &Pkg);
 
+       virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str);
+
        bool showErrors() const { return ShowError; }
        bool showErrors(bool const newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); }
        GlobalError::MsgType errorType() const { return ErrorType; }
        bool showErrors() const { return ShowError; }
        bool showErrors(bool const newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); }
        GlobalError::MsgType errorType() const { return ErrorType; }
@@ -100,6 +173,11 @@ public:                                                                    /*{{{*/
 protected:
        bool ShowError;
        GlobalError::MsgType ErrorType;
 protected:
        bool ShowError;
        GlobalError::MsgType ErrorType;
+
+       pkgCache::VerIterator canNotGetInstCandVer(pkgCacheFile &Cache,
+               pkgCache::PkgIterator const &Pkg);
+       pkgCache::VerIterator canNotGetCandInstVer(pkgCacheFile &Cache,
+               pkgCache::PkgIterator const &Pkg);
 };                                                                     /*}}}*/
 
 class PackageContainerInterface {                                      /*{{{*/
 };                                                                     /*}}}*/
 
 class PackageContainerInterface {                                      /*{{{*/
@@ -154,9 +232,24 @@ public:
        virtual bool empty() const = 0;
        virtual void clear() = 0;
 
        virtual bool empty() const = 0;
        virtual void clear() = 0;
 
-       enum Constructor { UNKNOWN, REGEX, TASK, FNMATCH };
-       virtual void setConstructor(Constructor const &con) = 0;
-       virtual Constructor getConstructor() const = 0;
+       // FIXME: This is a bloody hack removed soon. Use CacheSetHelper::PkgSelector !
+       enum APT_DEPRECATED Constructor { UNKNOWN = CacheSetHelper::UNKNOWN,
+               REGEX = CacheSetHelper::REGEX,
+               TASK = CacheSetHelper::TASK,
+               FNMATCH = CacheSetHelper::FNMATCH };
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic push
+       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+       void setConstructor(Constructor const by) { ConstructedBy = (CacheSetHelper::PkgSelector)by; }
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic pop
+#endif
+
+       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) {}
 
        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 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);
@@ -177,6 +270,9 @@ public:
        static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
                                            pkgCacheFile &Cache, const char * cmdline,
                                            std::list<Modifier> const &mods, CacheSetHelper &helper);
        static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
                                            pkgCacheFile &Cache, const char * cmdline,
                                            std::list<Modifier> const &mods, CacheSetHelper &helper);
+
+private:
+       CacheSetHelper::PkgSelector ConstructedBy;
 };
                                                                        /*}}}*/
 template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/
 };
                                                                        /*}}}*/
 template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/
@@ -240,11 +336,16 @@ public:                                                                   /*{{{*/
        iterator end() { return iterator(_cont.end()); }
        const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); }
 
        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; }
-       Constructor getConstructor() const { return ConstructedBy; }
-
-       PackageContainer() : ConstructedBy(UNKNOWN) {}
-       PackageContainer(Constructor const &by) : ConstructedBy(by) {}
+       PackageContainer() : PackageContainerInterface() {}
+       PackageContainer(CacheSetHelper::PkgSelector const &by) : PackageContainerInterface(by) {}
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic push
+       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+       APT_DEPRECATED PackageContainer(Constructor const &by) : PackageContainerInterface((CacheSetHelper::PkgSelector)by) {}
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic pop
+#endif
 
        /** \brief sort all included versions with given comparer
 
 
        /** \brief sort all included versions with given comparer
 
@@ -267,7 +368,7 @@ public:                                                                     /*{{{*/
            \param pattern name of the task
            \param helper responsible for error and message handling */
        static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
            \param pattern name of the task
            \param helper responsible for error and message handling */
        static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
-               PackageContainer cont(TASK);
+               PackageContainer cont(CacheSetHelper::TASK);
                PackageContainerInterface::FromTask(&cont, Cache, pattern, helper);
                return cont;
        }
                PackageContainerInterface::FromTask(&cont, Cache, pattern, helper);
                return cont;
        }
@@ -284,8 +385,8 @@ public:                                                                     /*{{{*/
            \param Cache the packages are in
            \param pattern regular expression for package names
            \param helper responsible for error and message handling */
            \param Cache the packages are in
            \param pattern regular expression for package names
            \param helper responsible for error and message handling */
-       static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
-               PackageContainer cont(REGEX);
+       static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
+               PackageContainer cont(CacheSetHelper::REGEX);
                PackageContainerInterface::FromRegEx(&cont, Cache, pattern, helper);
                return cont;
        }
                PackageContainerInterface::FromRegEx(&cont, Cache, pattern, helper);
                return cont;
        }
@@ -295,8 +396,8 @@ public:                                                                     /*{{{*/
                return FromRegEx(Cache, pattern, helper);
        }
 
                return FromRegEx(Cache, pattern, helper);
        }
 
-       static PackageContainer FromFnmatch(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
-               PackageContainer cont(FNMATCH);
+       static PackageContainer FromFnmatch(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
+               PackageContainer cont(CacheSetHelper::FNMATCH);
                PackageContainerInterface::FromFnmatch(&cont, Cache, pattern, helper);
                return cont;
        }
                PackageContainerInterface::FromFnmatch(&cont, Cache, pattern, helper);
                return cont;
        }
@@ -386,9 +487,6 @@ public:                                                                     /*{{{*/
                                mods, fallback, helper);
        }
                                                                        /*}}}*/
                                mods, fallback, helper);
        }
                                                                        /*}}}*/
-private:                                                               /*{{{*/
-       Constructor ConstructedBy;
-                                                                       /*}}}*/
 };                                                                     /*}}}*/
 // specialisations for push_back containers: std::list & std::vector   /*{{{*/
 template<> template<class Cont> void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
 };                                                                     /*}}}*/
 // specialisations for push_back containers: std::list & std::vector   /*{{{*/
 template<> template<class Cont> void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
@@ -461,9 +559,6 @@ private:
        iterator& erase(iterator &iter) { return iter; }
        size_t erase(const pkgCache::PkgIterator) { return 0; }
        void erase(iterator, iterator) { }
        iterator& erase(iterator &iter) { return iter; }
        size_t erase(const pkgCache::PkgIterator) { return 0; }
        void erase(iterator, iterator) { }
-
-       void setConstructor(Constructor const &) { }
-       Constructor getConstructor() const { return UNKNOWN; }
 };
                                                                        /*}}}*/
 typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet;
 };
                                                                        /*}}}*/
 typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet;
@@ -510,45 +605,83 @@ public:
        virtual void clear() = 0;
 
        /** \brief specifies which version(s) will be returned if non is given */
        virtual void clear() = 0;
 
        /** \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
+       enum APT_DEPRECATED Version {
+               ALL = CacheSetHelper::ALL,
+               CANDANDINST = CacheSetHelper::CANDANDINST,
+               CANDIDATE = CacheSetHelper::CANDIDATE,
+               INSTALLED = CacheSetHelper::INSTALLED,
+               CANDINST = CacheSetHelper::CANDINST,
+               INSTCAND = CacheSetHelper::INSTCAND,
+               NEWEST = CacheSetHelper::NEWEST
        };
 
        struct Modifier {
        };
 
        struct Modifier {
-               enum Position { NONE, PREFIX, POSTFIX };
-               unsigned short ID;
+               unsigned short const ID;
                const char * const Alias;
                const char * const Alias;
-               Position Pos;
-               Version SelectVersion;
+               enum Position { NONE, PREFIX, POSTFIX } const Pos;
+               enum CacheSetHelper::VerSelector const SelectVersion;
                Modifier (unsigned short const &id, const char * const alias, Position const &pos,
                Modifier (unsigned short const &id, const char * const alias, Position const &pos,
-                         Version const &select) : ID(id), Alias(alias), Pos(pos),
+                         enum CacheSetHelper::VerSelector const select) : ID(id), Alias(alias), Pos(pos),
                         SelectVersion(select) {}
                         SelectVersion(select) {}
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic push
+       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+               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
        };
 
        static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache,
        };
 
        static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache,
-                                   const char **cmdline, Version const &fallback,
+                                   const char **cmdline, CacheSetHelper::VerSelector const fallback,
                                    CacheSetHelper &helper);
                                    CacheSetHelper &helper);
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic push
+       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+       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
 
        static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache,
 
        static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache,
-                              std::string pkg, Version const &fallback, CacheSetHelper &helper,
+                              std::string pkg, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper,
                               bool const onlyFromName = false);
                               bool const onlyFromName = false);
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic push
+       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+       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
 
        static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache,
 
        static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache,
-                               pkgCache::PkgIterator const &P, Version const &fallback,
+                               pkgCache::PkgIterator const &P, CacheSetHelper::VerSelector const fallback,
                                CacheSetHelper &helper);
                                CacheSetHelper &helper);
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic push
+       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+       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
 
        static bool FromModifierCommandLine(unsigned short &modID,
                                            VersionContainerInterface * const vci,
 
        static bool FromModifierCommandLine(unsigned short &modID,
                                            VersionContainerInterface * const vci,
@@ -560,8 +693,22 @@ public:
        static bool FromDependency(VersionContainerInterface * const vci,
                                   pkgCacheFile &Cache,
                                   pkgCache::DepIterator const &D,
        static bool FromDependency(VersionContainerInterface * const vci,
                                   pkgCacheFile &Cache,
                                   pkgCache::DepIterator const &D,
-                                  Version const &selector,
+                                  CacheSetHelper::VerSelector const selector,
                                   CacheSetHelper &helper);
                                   CacheSetHelper &helper);
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic push
+       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+       APT_DEPRECATED static bool FromDependency(VersionContainerInterface * const vci,
+                                  pkgCacheFile &Cache,
+                                  pkgCache::DepIterator const &D,
+                                  Version const &selector,
+                                  CacheSetHelper &helper) {
+          return FromDependency(vci, Cache, D, (CacheSetHelper::VerSelector)selector, helper);
+       }
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic pop
+#endif
 
 protected:                                                             /*{{{*/
 
 
 protected:                                                             /*{{{*/
 
@@ -664,35 +811,64 @@ public:                                                                   /*{{{*/
            \param fallback version specification
            \param helper responsible for error and message handling */
        static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
            \param fallback version specification
            \param helper responsible for error and message handling */
        static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
-                       Version const &fallback, CacheSetHelper &helper) {
+                       CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) {
                VersionContainer vercon;
                VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, fallback, helper);
                return vercon;
        }
        static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
                VersionContainer vercon;
                VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, fallback, helper);
                return vercon;
        }
        static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
-                       Version const &fallback) {
+                       CacheSetHelper::VerSelector const fallback) {
                CacheSetHelper helper;
                return FromCommandLine(Cache, cmdline, fallback, helper);
        }
        static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
                CacheSetHelper helper;
                return FromCommandLine(Cache, cmdline, fallback, helper);
        }
        static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
-               return FromCommandLine(Cache, cmdline, CANDINST);
+               return FromCommandLine(Cache, cmdline, CacheSetHelper::CANDINST);
        }
        }
-
        static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg,
        static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg,
-                       Version const &fallback, CacheSetHelper &helper,
+                       CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper,
                                            bool const /*onlyFromName = false*/) {
                VersionContainer vercon;
                VersionContainerInterface::FromString(&vercon, Cache, pkg, fallback, helper);
                return vercon;
        }
        static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg,
                                            bool const /*onlyFromName = false*/) {
                VersionContainer vercon;
                VersionContainerInterface::FromString(&vercon, Cache, pkg, fallback, helper);
                return vercon;
        }
        static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg,
-                       Version const &fallback) {
+                       CacheSetHelper::VerSelector const fallback) {
                CacheSetHelper helper;
                return FromString(Cache, pkg, fallback, helper);
        }
        static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg) {
                CacheSetHelper helper;
                return FromString(Cache, pkg, fallback, helper);
        }
        static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg) {
-               return FromString(Cache, pkg, CANDINST);
+               return FromString(Cache, pkg, CacheSetHelper::CANDINST);
+       }
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic push
+       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+       static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
+                       Version const &fallback, CacheSetHelper &helper) {
+               VersionContainer vercon;
+               VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper);
+               return vercon;
+       }
+       static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
+                       Version const &fallback) {
+               CacheSetHelper helper;
+               return FromCommandLine(Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper);
        }
        }
+       static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg,
+                       Version const &fallback, CacheSetHelper &helper,
+                                           bool const /*onlyFromName = false*/) {
+               VersionContainer vercon;
+               VersionContainerInterface::FromString(&vercon, Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper);
+               return vercon;
+       }
+       static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg,
+                       Version const &fallback) {
+               CacheSetHelper helper;
+               return FromString(Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper);
+       }
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic pop
+#endif
 
        /** \brief returns all versions specified for the package
 
 
        /** \brief returns all versions specified for the package
 
@@ -701,18 +877,36 @@ public:                                                                   /*{{{*/
            \param fallback the version(s) you want to get
            \param helper the helper used for display and error handling */
        static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
            \param fallback the version(s) you want to get
            \param helper the helper used for display and error handling */
        static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
-               Version const &fallback, CacheSetHelper &helper) {
+               CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) {
                VersionContainer vercon;
                VersionContainerInterface::FromPackage(&vercon, Cache, P, fallback, helper);
                return vercon;
        }
        static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
                VersionContainer vercon;
                VersionContainerInterface::FromPackage(&vercon, Cache, P, fallback, helper);
                return vercon;
        }
        static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
-                                           Version const &fallback) {
+                                           CacheSetHelper::VerSelector const fallback) {
                CacheSetHelper helper;
                return FromPackage(Cache, P, fallback, helper);
        }
                CacheSetHelper helper;
                return FromPackage(Cache, P, fallback, helper);
        }
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic push
+       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+       static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
+               Version const &fallback, CacheSetHelper &helper) {
+               VersionContainer vercon;
+               VersionContainerInterface::FromPackage(&vercon, Cache, P, (CacheSetHelper::VerSelector)fallback, helper);
+               return vercon;
+       }
+       static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
+                                           Version const &fallback) {
+               CacheSetHelper helper;
+               return FromPackage(Cache, P, (CacheSetHelper::VerSelector)fallback, helper);
+       }
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic pop
+#endif
        static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) {
        static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) {
-               return FromPackage(Cache, P, CANDIDATE);
+               return FromPackage(Cache, P, CacheSetHelper::CANDIDATE);
        }
 
        static std::map<unsigned short, VersionContainer> GroupedFromCommandLine(
        }
 
        static std::map<unsigned short, VersionContainer> GroupedFromCommandLine(
@@ -741,18 +935,36 @@ public:                                                                   /*{{{*/
        }
 
        static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
        }
 
        static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
-                                              Version const &selector, CacheSetHelper &helper) {
+                                              CacheSetHelper::VerSelector const selector, CacheSetHelper &helper) {
                VersionContainer vercon;
                VersionContainerInterface::FromDependency(&vercon, Cache, D, selector, helper);
                return vercon;
        }
        static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
                VersionContainer vercon;
                VersionContainerInterface::FromDependency(&vercon, Cache, D, selector, helper);
                return vercon;
        }
        static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
-                                              Version const &selector) {
+                                              CacheSetHelper::VerSelector const selector) {
                CacheSetHelper helper;
                return FromPackage(Cache, D, selector, helper);
        }
                CacheSetHelper helper;
                return FromPackage(Cache, D, selector, helper);
        }
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic push
+       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+       static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
+                                              Version const &selector, CacheSetHelper &helper) {
+               VersionContainer vercon;
+               VersionContainerInterface::FromDependency(&vercon, Cache, D, (CacheSetHelper::VerSelector)selector, helper);
+               return vercon;
+       }
+       static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
+                                              Version const &selector) {
+               CacheSetHelper helper;
+               return FromPackage(Cache, D, (CacheSetHelper::VerSelector)selector, helper);
+       }
+#if __GNUC__ >= 4
+       #pragma GCC diagnostic pop
+#endif
        static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) {
        static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) {
-               return FromPackage(Cache, D, CANDIDATE);
+               return FromPackage(Cache, D, CacheSetHelper::CANDIDATE);
        }
                                                                        /*}}}*/
 };                                                                     /*}}}*/
        }
                                                                        /*}}}*/
 };                                                                     /*}}}*/
index eb77be274834e093de75e972a545cf9408818d57..cb68024db1d85e6af0513ba99291adfa2f20f779 100644 (file)
@@ -60,22 +60,22 @@ bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
       if (insertCurrentVer == true)
       {
         if (P->CurrentVer != 0)
       if (insertCurrentVer == true)
       {
         if (P->CurrentVer != 0)
-           vci->FromPackage(vci, CacheFile, P, APT::VersionContainerInterface::INSTALLED, helper);
+           vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::INSTALLED, helper);
       }
       else if (insertUpgradable == true)
       {
         if(P.CurrentVer() && state.Upgradable())
       }
       else if (insertUpgradable == true)
       {
         if(P.CurrentVer() && state.Upgradable())
-           vci->FromPackage(vci, CacheFile, P, APT::VersionContainerInterface::CANDIDATE, helper);
+           vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper);
       }
       else if (insertManualInstalled == true)
       {
         if (P.CurrentVer() &&
               ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false)
       }
       else if (insertManualInstalled == true)
       {
         if (P.CurrentVer() &&
               ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false)
-           vci->FromPackage(vci, CacheFile, P, APT::VersionContainerInterface::CANDIDATE, helper);
+           vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper);
       }
       else
       {
       }
       else
       {
-         if (vci->FromPackage(vci, CacheFile, P, APT::VersionContainerInterface::CANDIDATE, helper) == false)
+         if (vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper) == false)
         {
            // no candidate, this may happen for packages in
            // dpkg "deinstall ok config-file" state - we pick the first ver
         {
            // no candidate, this may happen for packages in
            // dpkg "deinstall ok config-file" state - we pick the first ver
index 4030ce4e61ecb279d2c0d68d39332d1097ad6425..bd10a41ef7da8b70cebdcb50e3cf626c84c5a117 100644 (file)
@@ -838,9 +838,9 @@ static bool XVcg(CommandLine &CmdL)
 
    // Load the list of packages from the command line into the show list
    APT::CacheSetHelper helper(true, GlobalError::NOTICE);
 
    // Load the list of packages from the command line into the show list
    APT::CacheSetHelper helper(true, GlobalError::NOTICE);
-   std::list<APT::PackageSet::Modifier> mods;
-   mods.push_back(APT::PackageSet::Modifier(0, ",", APT::PackageSet::Modifier::POSTFIX));
-   mods.push_back(APT::PackageSet::Modifier(1, "^", APT::PackageSet::Modifier::POSTFIX));
+   std::list<APT::CacheSetHelper::PkgModifier> mods;
+   mods.push_back(APT::CacheSetHelper::PkgModifier(0, ",", APT::PackageSet::Modifier::POSTFIX));
+   mods.push_back(APT::CacheSetHelper::PkgModifier(1, "^", APT::PackageSet::Modifier::POSTFIX));
    std::map<unsigned short, APT::PackageSet> pkgsets =
                APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0, helper);
 
    std::map<unsigned short, APT::PackageSet> pkgsets =
                APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0, helper);
 
@@ -1050,9 +1050,9 @@ static bool Dotty(CommandLine &CmdL)
 
    // Load the list of packages from the command line into the show list
    APT::CacheSetHelper helper(true, GlobalError::NOTICE);
 
    // Load the list of packages from the command line into the show list
    APT::CacheSetHelper helper(true, GlobalError::NOTICE);
-   std::list<APT::PackageSet::Modifier> mods;
-   mods.push_back(APT::PackageSet::Modifier(0, ",", APT::PackageSet::Modifier::POSTFIX));
-   mods.push_back(APT::PackageSet::Modifier(1, "^", APT::PackageSet::Modifier::POSTFIX));
+   std::list<APT::CacheSetHelper::PkgModifier> mods;
+   mods.push_back(APT::CacheSetHelper::PkgModifier(0, ",", APT::PackageSet::Modifier::POSTFIX));
+   mods.push_back(APT::CacheSetHelper::PkgModifier(1, "^", APT::PackageSet::Modifier::POSTFIX));
    std::map<unsigned short, APT::PackageSet> pkgsets =
                APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0, helper);
 
    std::map<unsigned short, APT::PackageSet> pkgsets =
                APT::PackageSet::GroupedFromCommandLine(CacheFile, CmdL.FileList + 1, mods, 0, helper);