// 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<numeric>(value) || is_a<symbol>(value));
if (need_parens)
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 << "}";
}
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
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
c.s << "\\dot{";
else
c.s << "{";
- do_print_idx(c, level);
+ print_index(c, level);
c.s << "}";
}
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;
#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<print_context>(&matrix::do_print).
+ print_func<print_latex>(&matrix::do_print_latex).
+ print_func<print_tree>(&basic::do_print_tree).
+ print_func<print_python_repr>(&matrix::do_print_python_repr))
//////////
// default constructor
// 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<print_tree>(c)) {
-
- inherited::print(c, level);
-
- } else {
-
- if (is_a<print_python_repr>(c))
- c.s << class_name() << '(';
-
- if (is_a<print_latex>(c))
- c.s << "\\left(\\begin{array}{" << std::string(col,'c') << "}";
- else
- c.s << "[";
-
- for (unsigned ro=0; ro<row; ++ro) {
- if (!is_a<print_latex>(c))
- c.s << "[";
- for (unsigned co=0; co<col; ++co) {
- m[ro*col+co].print(c);
- if (co<col-1) {
- if (is_a<print_latex>(c))
- c.s << "&";
- else
- c.s << ",";
- } else {
- if (!is_a<print_latex>(c))
- c.s << "]";
- }
- }
- if (ro<row-1) {
- if (is_a<print_latex>(c))
- c.s << "\\\\";
- else
- c.s << ",";
- }
+ for (unsigned ro=0; ro<row; ++ro) {
+ c.s << row_start;
+ for (unsigned co=0; co<col; ++co) {
+ m[ro*col+co].print(c);
+ if (co < col-1)
+ c.s << col_sep;
+ else
+ c.s << row_end;
}
+ if (ro < row-1)
+ c.s << row_sep;
+ }
+}
- if (is_a<print_latex>(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<print_python_repr>(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. */
// 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);
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:
#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<print_context>(&relational::do_print).
+ print_func<print_tree>(&basic::do_print_tree).
+ print_func<print_python_repr>(&relational::do_print_python_repr))
//////////
// default constructor
// 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<print_tree>(c)) {
-
- inherited::print(c, level);
-
- } else {
-
- if (is_a<print_python_repr>(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<print_python_repr>(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) {
// 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;
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;