From: Chris Dams Date: Fri, 7 Jul 2006 11:55:52 +0000 (+0000) Subject: Make it possible to print exmaps and exvectors. X-Git-Tag: release_1-4-0~83 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=a57c586be1fb226e9dd234b481c6b1da91013925 Make it possible to print exmaps and exvectors. --- diff --git a/ginac/ex.h b/ginac/ex.h index 1e56e823..228b44e5 100644 --- a/ginac/ex.h +++ b/ginac/ex.h @@ -678,6 +678,10 @@ struct ex_swap : public std::binary_function { void operator() (ex &lh, ex &rh) const { lh.swap(rh); } }; +// Make it possible to print exvectors and exmaps +std::ostream & operator<<(std::ostream & os, const exvector & e); +std::ostream & operator<<(std::ostream & os, const exmap & e); + // wrapper functions around member functions inline size_t nops(const ex & thisex) { return thisex.nops(); } diff --git a/ginac/operators.cpp b/ginac/operators.cpp index 0ad960d4..1a1b6de4 100644 --- a/ginac/operators.cpp +++ b/ginac/operators.cpp @@ -350,6 +350,65 @@ std::ostream & operator<<(std::ostream & os, const ex & e) return os; } +std::ostream & operator<<(std::ostream & os, const exvector & e) +{ + print_context *p = get_print_context(os); + exvector::const_iterator i = e.begin(); + exvector::const_iterator vend = e.end(); + + if (i==vend) { + os << "[]"; + return os; + } + + os << "["; + while (true) { + if (p == 0) + i -> print(print_dflt(os)); + else + i -> print(*p); + ++i; + if (i==vend) + break; + os << ","; + } + os << "]"; + + return os; +} + +std::ostream & operator<<(std::ostream & os, const exmap & e) +{ + print_context *p = get_print_context(os); + exmap::const_iterator i = e.begin(); + exmap::const_iterator mend = e.end(); + + if (i==mend) { + os << "{}"; + return os; + } + + os << "{"; + while (true) { + if (p == 0) + i->first.print(print_dflt(os)); + else + i->first.print(*p); + os << "=="; + if (p == 0) + i->second.print(print_dflt(os)); + else + i->second.print(*p); + ++i; + if( i==mend ) + break; + os << ","; + } + os << "}"; + + return os; +} + std::istream & operator>>(std::istream & is, ex & e) { throw (std::logic_error("expression input from streams not implemented"));