Make it possible to print exmaps and exvectors.
authorChris Dams <Chris.Dams@mi.infn.it>
Fri, 7 Jul 2006 11:55:52 +0000 (11:55 +0000)
committerChris Dams <Chris.Dams@mi.infn.it>
Fri, 7 Jul 2006 11:55:52 +0000 (11:55 +0000)
ginac/ex.h
ginac/operators.cpp

index 1e56e82373046828423e8d14c31c37230734115e..228b44e5450474754253f38eae94041f5b66270e 100644 (file)
@@ -678,6 +678,10 @@ struct ex_swap : public std::binary_function<ex, ex, void> {
        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(); }
index 0ad960d4aaac5c582df8953f69c55e8a4dc9ad2d..1a1b6de497232d0b0cb5b8b34bc23318198ccbc4 100644 (file)
@@ -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"));