]> www.ginac.de Git - ginac.git/blobdiff - ginac/basic.cpp
more efficient constructors
[ginac.git] / ginac / basic.cpp
index 66e6c90182cdfef57bc2ccec12ec55c3caa0b43d..09d9b79b996d66def75002892060c9ed16f28997 100644 (file)
@@ -124,9 +124,19 @@ void basic::archive(archive_node &n) const
  *  @param level value that is used to identify the precedence or indentation
  *               level for placing parentheses and formatting */
 void basic::print(const print_context & c, unsigned level) const
+{
+       print_dispatch(get_class_info(), c, level);
+}
+
+/** Like print(), but dispatch to the specified class. Can be used by
+ *  implementations of print methods to dispatch to the method of the
+ *  superclass.
+ *
+ *  @see basic::print */
+void basic::print_dispatch(const registered_class_info & ri, const print_context & c, unsigned level) const
 {
        // Double dispatch on object type and print_context type
-       const registered_class_info * reg_info = &get_class_info();
+       const registered_class_info * reg_info = &ri;
        const print_context_class_info * pc_info = &c.get_class_info();
 
 next_class:
@@ -175,9 +185,10 @@ void basic::do_print(const print_context & c, unsigned level) const
 void basic::do_print_tree(const print_tree & c, unsigned level) const
 {
        c.s << std::string(level, ' ') << class_name()
-           << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
-           << ", nops=" << nops()
-           << std::endl;
+           << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec;
+       if (nops())
+               c.s << ", nops=" << nops();
+       c.s << std::endl;
        for (size_t i=0; i<nops(); ++i)
                op(i).print(c, level + c.delta_indent);
 }