prettyprinters.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Description /*{{{*/
  2. /* ######################################################################
  3. Provide pretty printers for pkgCache structs like PkgIterator
  4. ##################################################################### */
  5. /*}}}*/
  6. // Include Files /*{{{*/
  7. #include <config.h>
  8. #include <apt-pkg/depcache.h>
  9. #include <apt-pkg/prettyprinters.h>
  10. #include <ostream>
  11. #include <string>
  12. /*}}}*/
  13. std::ostream& operator<<(std::ostream& os, const APT::PrettyPkg& pp) /*{{{*/
  14. {
  15. if (pp.Pkg.end() == true)
  16. return os << "invalid package";
  17. std::string current = (pp.Pkg.CurVersion() == 0 ? "none" : pp.Pkg.CurVersion());
  18. std::string candidate = (*pp.DepCache)[pp.Pkg].CandVersion;
  19. std::string newest = (pp.Pkg.VersionList().end() ? "none" : pp.Pkg.VersionList().VerStr());
  20. os << pp.Pkg.Name() << " [ " << pp.Pkg.Arch() << " ] < " << current;
  21. if (current != candidate)
  22. os << " -> " << candidate;
  23. if ( newest != "none" && candidate != newest)
  24. os << " | " << newest;
  25. if (pp.Pkg->VersionList == 0)
  26. os << " > ( none )";
  27. else
  28. os << " > ( " << (pp.Pkg.VersionList().Section()==0?"unknown":pp.Pkg.VersionList().Section()) << " )";
  29. return os;
  30. }
  31. /*}}}*/
  32. std::ostream& operator<<(std::ostream& os, const APT::PrettyDep& pd) /*{{{*/
  33. {
  34. if (unlikely(pd.Dep.end() == true))
  35. return os << "invalid dependency";
  36. pkgCache::PkgIterator P = pd.Dep.ParentPkg();
  37. pkgCache::PkgIterator T = pd.Dep.TargetPkg();
  38. os << (P.end() ? "invalid pkg" : P.FullName(false)) << " " << pd.Dep.DepType()
  39. << " on " << APT::PrettyPkg(pd.DepCache, T);
  40. if (pd.Dep->Version != 0)
  41. os << " (" << pd.Dep.CompType() << " " << pd.Dep.TargetVer() << ")";
  42. return os;
  43. }
  44. /*}}}*/