]> www.ginac.de Git - ginac.git/blobdiff - ginac/ncmul.cpp
generous use of auto_ptr to provide better exception safety and make the code
[ginac.git] / ginac / ncmul.cpp
index dd0c7bdc07d0fee84c03ade49504b13375c16a3c..e3a6b552f7e6d0294022fb69603083325ec40b4f 100644 (file)
 #include "add.h"
 #include "mul.h"
 #include "matrix.h"
 #include "add.h"
 #include "mul.h"
 #include "matrix.h"
-#include "print.h"
 #include "archive.h"
 #include "utils.h"
 
 namespace GiNaC {
 
 #include "archive.h"
 #include "utils.h"
 
 namespace GiNaC {
 
-GINAC_IMPLEMENT_REGISTERED_CLASS(ncmul, exprseq)
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(ncmul, exprseq,
+  print_func<print_context>(&ncmul::do_print).
+  print_func<print_tree>(&basic::do_print_tree).
+  print_func<print_csrc>(&ncmul::do_print_csrc).
+  print_func<print_python_repr>(&ncmul::do_print_csrc))
+
 
 //////////
 // default constructor
 
 //////////
 // default constructor
@@ -85,7 +89,7 @@ ncmul::ncmul(const exvector & v, bool discardable) : inherited(v,discardable)
        tinfo_key = TINFO_ncmul;
 }
 
        tinfo_key = TINFO_ncmul;
 }
 
-ncmul::ncmul(exvector * vp) : inherited(vp)
+ncmul::ncmul(std::auto_ptr<exvector> vp) : inherited(vp)
 {
        tinfo_key = TINFO_ncmul;
 }
 {
        tinfo_key = TINFO_ncmul;
 }
@@ -102,26 +106,15 @@ DEFAULT_ARCHIVING(ncmul)
 
 // public
 
 
 // public
 
-void ncmul::print(const print_context & c, unsigned level) const
+void ncmul::do_print(const print_context & c, unsigned level) const
 {
 {
-       if (is_a<print_tree>(c)) {
-
-               inherited::print(c, level);
-
-       } else if (is_a<print_csrc>(c) || is_a<print_python_repr>(c)) {
-
-               c.s << class_name() << "(";
-               exvector::const_iterator it = seq.begin(), itend = seq.end()-1;
-               while (it != itend) {
-                       it->print(c, precedence());
-                       c.s << ",";
-                       it++;
-               }
-               it->print(c, precedence());
-               c.s << ")";
+       printseq(c, '(', '*', ')', precedence(), level);
+}
 
 
-       } else
-               printseq(c, '(', '*', ')', precedence(), level);
+void ncmul::do_print_csrc(const print_context & c, unsigned level) const
+{
+       c.s << class_name();
+       printseq(c, '(', ',', ')', precedence(), precedence());
 }
 
 bool ncmul::info(unsigned inf) const
 }
 
 bool ncmul::info(unsigned inf) const
@@ -427,7 +420,7 @@ ex ncmul::eval(int level) const
 ex ncmul::evalm() const
 {
        // Evaluate children first
 ex ncmul::evalm() const
 {
        // Evaluate children first
-       exvector *s = new exvector;
+       std::auto_ptr<exvector> s(new exvector);
        s->reserve(seq.size());
        exvector::const_iterator it = seq.begin(), itend = seq.end();
        while (it != itend) {
        s->reserve(seq.size());
        exvector::const_iterator it = seq.begin(), itend = seq.end();
        while (it != itend) {
@@ -446,7 +439,6 @@ ex ncmul::evalm() const
                        prod = prod.mul(ex_to<matrix>(*it));
                        it++;
                }
                        prod = prod.mul(ex_to<matrix>(*it));
                        it++;
                }
-               delete s;
                return prod;
        }
 
                return prod;
        }
 
@@ -459,7 +451,7 @@ ex ncmul::thiscontainer(const exvector & v) const
        return (new ncmul(v))->setflag(status_flags::dynallocated);
 }
 
        return (new ncmul(v))->setflag(status_flags::dynallocated);
 }
 
-ex ncmul::thiscontainer(exvector * vp) const
+ex ncmul::thiscontainer(std::auto_ptr<exvector> vp) const
 {
        return (new ncmul(vp))->setflag(status_flags::dynallocated);
 }
 {
        return (new ncmul(vp))->setflag(status_flags::dynallocated);
 }