+class PackageContainerInterface;
+class VersionContainerInterface;
+
+class CacheSetHelper { /*{{{*/
+/** \class APT::CacheSetHelper
+ Simple base class with a lot of virtual methods which can be overridden
+ to alter the behavior or the output of the CacheSets.
+
+ This helper is passed around by the static methods in the CacheSets and
+ used every time they hit an error condition or something could be
+ printed out.
+*/
+public: /*{{{*/
+ CacheSetHelper(bool const ShowError = true,
+ GlobalError::MsgType ErrorType = GlobalError::ERROR) :
+ 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);
+
+ 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);
+
+ virtual void canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
+ virtual void canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
+ pkgCache::PkgIterator const &Pkg);
+ virtual void canNotFindCandInstVer(VersionContainerInterface * const vci,
+ pkgCacheFile &Cache,
+ pkgCache::PkgIterator const &Pkg);
+
+ virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str);
+ virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache,
+ pkgCache::PkgIterator const &Pkg);
+ virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache,
+ pkgCache::PkgIterator const &Pkg);
+ virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache,
+ pkgCache::PkgIterator const &Pkg);
+
+ 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; }
+ GlobalError::MsgType errorType(GlobalError::MsgType const &newValue)
+ {
+ if (ErrorType == newValue) return ErrorType;
+ else {
+ GlobalError::MsgType const &oldValue = ErrorType;
+ ErrorType = newValue;
+ return oldValue;
+ }
+ }
+
+ /*}}}*/
+protected:
+ bool ShowError;
+ GlobalError::MsgType ErrorType;
+}; /*}}}*/
+class PackageContainerInterface { /*{{{*/
+/** \class PackageContainerInterface
+
+ * Interface ensuring that all operations can be executed on the yet to
+ * define concrete PackageContainer - access to all methods is possible,
+ * but in general the wrappers provided by the PackageContainer template
+ * are nicer to use.
+
+ * This class mostly protects use from the need to write all implementation
+ * of the methods working on containers in the template */
+public:
+ class const_iterator { /*{{{*/
+ public:
+ virtual pkgCache::PkgIterator getPkg() const = 0;
+ operator pkgCache::PkgIterator(void) const { return getPkg(); }
+
+ inline const char *Name() const {return getPkg().Name(); }
+ inline std::string FullName(bool const Pretty) const { return getPkg().FullName(Pretty); }
+ inline std::string FullName() const { return getPkg().FullName(); }
+ inline const char *Section() const {return getPkg().Section(); }
+ inline bool Purge() const {return getPkg().Purge(); }
+ inline const char *Arch() const {return getPkg().Arch(); }
+ inline pkgCache::GrpIterator Group() const { return getPkg().Group(); }
+ inline pkgCache::VerIterator VersionList() const { return getPkg().VersionList(); }
+ inline pkgCache::VerIterator CurrentVer() const { return getPkg().CurrentVer(); }
+ inline pkgCache::DepIterator RevDependsList() const { return getPkg().RevDependsList(); }
+ inline pkgCache::PrvIterator ProvidesList() const { return getPkg().ProvidesList(); }
+ inline pkgCache::PkgIterator::OkState State() const { return getPkg().State(); }
+ inline const char *CandVersion() const { return getPkg().CandVersion(); }
+ inline const char *CurVersion() const { return getPkg().CurVersion(); }
+ inline pkgCache *Cache() const { return getPkg().Cache(); }
+ inline unsigned long Index() const {return getPkg().Index();}
+ // we have only valid iterators here
+ inline bool end() const { return false; }
+
+ inline pkgCache::Package const * operator->() const {return &*getPkg();}
+ };
+ /*}}}*/
+
+ virtual bool insert(pkgCache::PkgIterator const &P) = 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;
+
+ 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);
+
+ struct Modifier {
+ enum Position { NONE, PREFIX, POSTFIX };
+ unsigned short ID;
+ const char * const Alias;
+ Position Pos;
+ Modifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}
+ };
+
+ static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
+ pkgCacheFile &Cache, const char * cmdline,
+ std::list<Modifier> const &mods, CacheSetHelper &helper);
+};
+ /*}}}*/
+template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/
+/** \class APT::PackageContainer