+// public
+
+void function::print(const print_context & c, unsigned level) const
+{
+ GINAC_ASSERT(serial<registered_functions().size());
+ const function_options &opt = registered_functions()[serial];
+ const std::vector<print_funcp> &pdt = opt.print_dispatch_table;
+
+ // Dynamically dispatch on print_context type
+ const print_context_class_info *pc_info = &c.get_class_info();
+
+next_context:
+ unsigned id = pc_info->options.get_id();
+ if (id >= pdt.size() || pdt[id] == NULL) {
+
+ // Method not found, try parent print_context class
+ const print_context_class_info *parent_pc_info = pc_info->get_parent();
+ if (parent_pc_info) {
+ pc_info = parent_pc_info;
+ goto next_context;
+ }
+
+ // Method still not found, use default output
+ if (is_a<print_tree>(c)) {
+
+ c.s << std::string(level, ' ') << class_name() << " "
+ << opt.name << " @" << this
+ << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
+ << ", nops=" << nops()
+ << std::endl;
+ unsigned delta_indent = static_cast<const print_tree &>(c).delta_indent;
+ for (size_t i=0; i<seq.size(); ++i)
+ seq[i].print(c, level + delta_indent);
+ c.s << std::string(level + delta_indent, ' ') << "=====" << std::endl;
+
+ } else if (is_a<print_csrc>(c)) {
+
+ // Print function name in lowercase
+ std::string lname = opt.name;
+ size_t num = lname.size();
+ for (size_t i=0; i<num; i++)
+ lname[i] = tolower(lname[i]);
+ c.s << lname;
+ printseq(c, '(', ',', ')', exprseq::precedence(), function::precedence());
+
+ } else if (is_a<print_latex>(c)) {
+ c.s << opt.TeX_name;
+ printseq(c, '(', ',', ')', exprseq::precedence(), function::precedence());
+ } else {
+ c.s << opt.name;
+ printseq(c, '(', ',', ')', exprseq::precedence(), function::precedence());
+ }
+
+ } else {
+
+ // Method found, call it
+ current_serial = serial;
+ if (opt.print_use_exvector_args)
+ ((print_funcp_exvector)pdt[id])(seq, c);
+ else switch (opt.nparams) {
+ // the following lines have been generated for max. ${maxargs} parameters
+${print_switch_statement}
+ // end of generated lines
+ default:
+ throw(std::logic_error("function::print(): invalid nparams"));
+ }
+ }