From 84573326f41dd09b914b8374548e7ee7c93d0439 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 28 Apr 2016 09:22:55 +0200 Subject: factor out Pkg/DepIterator prettyprinters into own header The old prettyprinters have only access to the struct they pretty print, which isn't enough usually as we want to know for a package also a bit of state information like which version is the candidate. We therefore need to pull the DepCache into context and hence use a temporary struct which is printed instead of the iterator itself. --- apt-pkg/prettyprinters.cc | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 apt-pkg/prettyprinters.cc (limited to 'apt-pkg/prettyprinters.cc') diff --git a/apt-pkg/prettyprinters.cc b/apt-pkg/prettyprinters.cc new file mode 100644 index 000000000..a736cabf4 --- /dev/null +++ b/apt-pkg/prettyprinters.cc @@ -0,0 +1,56 @@ +// Description /*{{{*/ +/* ###################################################################### + + Provide pretty printers for pkgCache structs like PkgIterator + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include + +#include +#include + +#include +#include + + /*}}}*/ + +std::ostream& operator<<(std::ostream& os, const APT::PrettyPkg& pp) /*{{{*/ +{ + if (pp.Pkg.end() == true) + return os << "invalid package"; + + std::string current = (pp.Pkg.CurVersion() == 0 ? "none" : pp.Pkg.CurVersion()); + std::string candidate = (*pp.DepCache)[pp.Pkg].CandVersion; + std::string newest = (pp.Pkg.VersionList().end() ? "none" : pp.Pkg.VersionList().VerStr()); + + os << pp.Pkg.Name() << " [ " << pp.Pkg.Arch() << " ] < " << current; + if (current != candidate) + os << " -> " << candidate; + if ( newest != "none" && candidate != newest) + os << " | " << newest; + if (pp.Pkg->VersionList == 0) + os << " > ( none )"; + else + os << " > ( " << (pp.Pkg.VersionList().Section()==0?"unknown":pp.Pkg.VersionList().Section()) << " )"; + return os; +} + /*}}}*/ +std::ostream& operator<<(std::ostream& os, const APT::PrettyDep& pd) /*{{{*/ +{ + if (unlikely(pd.Dep.end() == true)) + return os << "invalid dependency"; + + pkgCache::PkgIterator P = pd.Dep.ParentPkg(); + pkgCache::PkgIterator T = pd.Dep.TargetPkg(); + + os << (P.end() ? "invalid pkg" : P.FullName(false)) << " " << pd.Dep.DepType() + << " on " << APT::PrettyPkg(pd.DepCache, T); + + if (pd.Dep->Version != 0) + os << " (" << pd.Dep.CompType() << " " << pd.Dep.TargetVer() << ")"; + + return os; +} + /*}}}*/ -- cgit v1.2.3