From: Christian Bauer Date: Wed, 6 Aug 2003 19:07:46 +0000 (+0000) Subject: use new-style print methods X-Git-Tag: release_1-0-15~2 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=b66548802c56b34d6b212a0196d622937841ca61 use new-style print methods --- diff --git a/ginac/idx.cpp b/ginac/idx.cpp index 1b4bf6f5..4dd4d1af 100644 --- a/ginac/idx.cpp +++ b/ginac/idx.cpp @@ -134,7 +134,7 @@ DEFAULT_UNARCHIVE(spinidx) // functions overriding virtual functions from base classes ////////// -void idx::do_print_idx(const print_context & c, unsigned level) const +void idx::print_index(const print_context & c, unsigned level) const { bool need_parens = !(is_exactly_a(value) || is_a(value)); if (need_parens) @@ -152,13 +152,13 @@ void idx::do_print_idx(const print_context & c, unsigned level) const void idx::do_print(const print_context & c, unsigned level) const { c.s << "."; - do_print_idx(c, level); + print_index(c, level); } void idx::do_print_latex(const print_latex & c, unsigned level) const { c.s << "{"; - do_print_idx(c, level); + print_index(c, level); c.s << "}"; } @@ -177,7 +177,7 @@ void varidx::do_print(const print_context & c, unsigned level) const c.s << "."; else c.s << "~"; - do_print_idx(c, level); + print_index(c, level); } void varidx::do_print_tree(const print_tree & c, unsigned level) const @@ -198,7 +198,7 @@ void spinidx::do_print(const print_context & c, unsigned level) const c.s << "~"; if (dotted) c.s << "*"; - do_print_idx(c, level); + print_index(c, level); } void spinidx::do_print_latex(const print_latex & c, unsigned level) const @@ -207,7 +207,7 @@ void spinidx::do_print_latex(const print_latex & c, unsigned level) const c.s << "\\dot{"; else c.s << "{"; - do_print_idx(c, level); + print_index(c, level); c.s << "}"; } diff --git a/ginac/idx.h b/ginac/idx.h index 16c515f2..13004fd4 100644 --- a/ginac/idx.h +++ b/ginac/idx.h @@ -94,7 +94,7 @@ public: ex minimal_dim(const idx & other) const; protected: - void do_print_idx(const print_context & c, unsigned level) const; + void print_index(const print_context & c, unsigned level) const; void do_print(const print_context & c, unsigned level) const; void do_print_latex(const print_latex & c, unsigned level) const; void do_print_tree(const print_tree & c, unsigned level) const; diff --git a/ginac/matrix.cpp b/ginac/matrix.cpp index 4828bb93..c9b3521a 100644 --- a/ginac/matrix.cpp +++ b/ginac/matrix.cpp @@ -37,13 +37,16 @@ #include "symbol.h" #include "operators.h" #include "normal.h" -#include "print.h" #include "archive.h" #include "utils.h" namespace GiNaC { -GINAC_IMPLEMENT_REGISTERED_CLASS(matrix, basic) +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(matrix, basic, + print_func(&matrix::do_print). + print_func(&matrix::do_print_latex). + print_func(&basic::do_print_tree). + print_func(&matrix::do_print_python_repr)) ////////// // default constructor @@ -134,54 +137,41 @@ DEFAULT_UNARCHIVE(matrix) // public -void matrix::print(const print_context & c, unsigned level) const +void matrix::print_elements(const print_context & c, const std::string & row_start, const std::string & row_end, const std::string & row_sep, const std::string & col_sep) const { - if (is_a(c)) { - - inherited::print(c, level); - - } else { - - if (is_a(c)) - c.s << class_name() << '('; - - if (is_a(c)) - c.s << "\\left(\\begin{array}{" << std::string(col,'c') << "}"; - else - c.s << "["; - - for (unsigned ro=0; ro(c)) - c.s << "["; - for (unsigned co=0; co(c)) - c.s << "&"; - else - c.s << ","; - } else { - if (!is_a(c)) - c.s << "]"; - } - } - if (ro(c)) - c.s << "\\\\"; - else - c.s << ","; - } + for (unsigned ro=0; ro(c)) - c.s << "\\end{array}\\right)"; - else - c.s << "]"; +void matrix::do_print(const print_context & c, unsigned level) const +{ + c.s << "["; + print_elements(c, "[", "]", ",", ","); + c.s << "]"; +} - if (is_a(c)) - c.s << ')'; +void matrix::do_print_latex(const print_latex & c, unsigned level) const +{ + c.s << "\\left(\\begin{array}{" << std::string(col,'c') << "}"; + print_elements(c, "", "", "\\\\", "&"); + c.s << "\\end{array}\\right)"; +} - } +void matrix::do_print_python_repr(const print_python_repr & c, unsigned level) const +{ + c.s << class_name() << '('; + print_elements(c, "[", "]", ",", ","); + c.s << ')'; } /** nops is defined to be rows x columns. */ diff --git a/ginac/matrix.h b/ginac/matrix.h index f951850c..f5cd5de8 100644 --- a/ginac/matrix.h +++ b/ginac/matrix.h @@ -43,7 +43,6 @@ public: // functions overriding virtual functions from base classes public: - void print(const print_context & c, unsigned level = 0) const; size_t nops() const; ex op(size_t i) const; ex & let_op(size_t i); @@ -87,6 +86,11 @@ protected: int division_free_elimination(const bool det = false); int fraction_free_elimination(const bool det = false); int pivot(unsigned ro, unsigned co, bool symbolic = true); + + void print_elements(const print_context & c, const std::string & row_start, const std::string & row_end, const std::string & row_sep, const std::string & col_sep) const; + void do_print(const print_context & c, unsigned level) const; + void do_print_latex(const print_latex & c, unsigned level) const; + void do_print_python_repr(const print_python_repr & c, unsigned level) const; // member variables protected: diff --git a/ginac/relational.cpp b/ginac/relational.cpp index 453b4c00..05fe56e8 100644 --- a/ginac/relational.cpp +++ b/ginac/relational.cpp @@ -26,13 +26,15 @@ #include "relational.h" #include "operators.h" #include "numeric.h" -#include "print.h" #include "archive.h" #include "utils.h" namespace GiNaC { -GINAC_IMPLEMENT_REGISTERED_CLASS(relational, basic) +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(relational, basic, + print_func(&relational::do_print). + print_func(&basic::do_print_tree). + print_func(&relational::do_print_python_repr)) ////////// // default constructor @@ -78,57 +80,55 @@ DEFAULT_UNARCHIVE(relational) // public -void relational::print(const print_context & c, unsigned level) const +static void print_operator(const print_context & c, relational::operators o) { - if (is_a(c)) { - - inherited::print(c, level); - - } else { - - if (is_a(c)) { - c.s << class_name() << '('; - lh.print(c); - c.s << ','; - rh.print(c); - c.s << ",'"; - } else { - if (precedence() <= level) - c.s << "("; - lh.print(c, precedence()); - } - switch (o) { - case equal: - c.s << "=="; - break; - case not_equal: - c.s << "!="; - break; - case less: - c.s << "<"; - break; - case less_or_equal: - c.s << "<="; - break; - case greater: - c.s << ">"; - break; - case greater_or_equal: - c.s << ">="; - break; - default: - c.s << "(INVALID RELATIONAL OPERATOR)"; - } - if (is_a(c)) - c.s << "')"; - else { - rh.print(c, precedence()); - if (precedence() <= level) - c.s << ")"; - } + switch (o) { + case relational::equal: + c.s << "=="; + break; + case relational::not_equal: + c.s << "!="; + break; + case relational::less: + c.s << "<"; + break; + case relational::less_or_equal: + c.s << "<="; + break; + case relational::greater: + c.s << ">"; + break; + case relational::greater_or_equal: + c.s << ">="; + break; + default: + c.s << "(INVALID RELATIONAL OPERATOR)"; + break; } } +void relational::do_print(const print_context & c, unsigned level) const +{ + if (precedence() <= level) + c.s << "("; + lh.print(c, precedence()); + print_operator(c, o); + rh.print(c, precedence()); + if (precedence() <= level) + c.s << ")"; +} + +void relational::do_print_python_repr(const print_python_repr & c, unsigned level) const +{ + c.s << class_name() << '('; + lh.print(c); + c.s << ','; + rh.print(c); + c.s << ",'"; + print_operator(c, o); + c.s << "')"; +} + bool relational::info(unsigned inf) const { switch (inf) { diff --git a/ginac/relational.h b/ginac/relational.h index cbe51468..a6727de1 100644 --- a/ginac/relational.h +++ b/ginac/relational.h @@ -51,7 +51,6 @@ public: // functions overriding virtual functions from base classes public: - void print(const print_context & c, unsigned level = 0) const; unsigned precedence() const {return 20;} bool info(unsigned inf) const; size_t nops() const; @@ -68,6 +67,10 @@ protected: unsigned calchash() const; // new virtual functions which can be overridden by derived classes +protected: + void do_print(const print_context & c, unsigned level) const; + void do_print_python_repr(const print_python_repr & c, unsigned level) const; + public: virtual ex lhs() const; virtual ex rhs() const;