summaryrefslogtreecommitdiff
path: root/apt-pkg/prettyprinters.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2016-04-28 09:22:55 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2016-04-28 10:08:32 +0200
commit84573326f41dd09b914b8374548e7ee7c93d0439 (patch)
tree3fc7af54e2322c0803495e3a79f69ab138c8f172 /apt-pkg/prettyprinters.cc
parent29636cc759c6fbb92c6c462c90611eefb67cbbd4 (diff)
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.
Diffstat (limited to 'apt-pkg/prettyprinters.cc')
-rw-r--r--apt-pkg/prettyprinters.cc56
1 files changed, 56 insertions, 0 deletions
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 <config.h>
+
+#include <apt-pkg/depcache.h>
+#include <apt-pkg/prettyprinters.h>
+
+#include <ostream>
+#include <string>
+
+ /*}}}*/
+
+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;
+}
+ /*}}}*/