]> www.ginac.de Git - ginac.git/blobdiff - ginac/container.pl
- Made determinant_algo (in flags.h) really work.
[ginac.git] / ginac / container.pl
index f04c7067bf0809c49e0c2e5e609a0ad19e3deb83..9dac1847530c3797ec530fcb5b68e5873ac340ee 100755 (executable)
@@ -1,7 +1,5 @@
-#!/usr/bin/perl -w
-
-if ($#ARGV!=0) {
-    die 'usage: container.pl type (type=lst or exprseq)';
+if (($#ARGV!=0) and ($#ARGV!=1)) {
+    die 'usage: container.pl type [maxargs] (type=lst or exprseq)';
 }
 
 if ($ARGV[0] eq 'lst') {
@@ -12,8 +10,11 @@ if ($ARGV[0] eq 'lst') {
     die 'only lst and exprseq supported';
 }
 
-#$type='lst';
-#$type='exprseq';
+if ($#ARGV==1) {
+    $maxargs=$ARGV[1];
+} else {
+    $maxargs=15; # must be greater or equal than the value used in function.pl
+}
 
 if ($type eq 'exprseq') {
 
@@ -86,6 +87,57 @@ END_OF_LET_OP_IMPLEMENTATION
     $LET_OP_IMPLEMENTATION="// ${CONTAINER}::let_op() will be implemented by user elsewhere";
 }
 
+sub generate_seq {
+    my ($seq_template,$n,$separator)=@_;
+    my ($res,$N);
+    
+    $res='';
+    for ($N=1; $N<=$n; $N++) {
+        $res .= eval('"' . $seq_template . '"');
+        if ($N!=$n) {
+            $res .= $separator;
+        }
+    }
+    return $res;
+}
+
+sub generate_from_to {
+    my ($template,$seq_template1,$seq_separator1,$seq_template2,
+        $seq_separator2,$from,$to)=@_;
+    my ($res,$N,$SEQ);
+
+    $res='';
+    for ($N=$from; $N<=$to; $N++) {
+        $SEQ1=generate_seq($seq_template1,$N,$seq_separator1);
+        $SEQ2=generate_seq($seq_template2,$N,$seq_separator2);
+        $res .= eval('"' . $template . '"');
+        $SEQ1=''; # to avoid main::SEQ1 used only once warning
+        $SEQ2=''; # same as above
+    }
+    return $res;
+}
+
+sub generate {
+    my ($template,$seq_template1,$seq_separator1,$seq_template2,
+        $seq_separator2)=@_;
+    return generate_from_to($template,$seq_template1,$seq_separator1,
+                            $seq_template2,$seq_separator2,1,$maxargs);
+}
+
+$constructors_interface=generate(
+'    explicit ${CONTAINER}(${SEQ1});'."\n",
+'const ex & param${N}',', ','','');
+
+$constructors_implementation=generate(
+    <<'END_OF_CONSTRUCTORS_IMPLEMENTATION','const ex & param${N}',', ','    seq.push_back(param${N});',"\n");
+${CONTAINER}::${CONTAINER}(${SEQ1}) : basic(TINFO_${CONTAINER})
+{
+    debugmsg(\"${CONTAINER} constructor from ${N}*ex\",LOGLEVEL_CONSTRUCT);
+    RESERVE(seq,${N});
+${SEQ2}
+}
+END_OF_CONSTRUCTORS_IMPLEMENTATION
+
 $interface=<<END_OF_INTERFACE;
 /** \@file ${CONTAINER}.h
  *
@@ -101,6 +153,7 @@ $interface=<<END_OF_INTERFACE;
  *                        \$let_op=${let_op}
  *                        \$open_bracket=${open_bracket}
  *                        \$close_bracket=${close_bracket}
+ *                        \$maxargs=${maxargs}
  *
  *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
  *
@@ -127,15 +180,15 @@ $interface=<<END_OF_INTERFACE;
 // CINT needs <algorithm> to work properly with <vector> and <list> 
 #include <algorithm>
 
-#include <ginac/basic.h>
-#include <ginac/ex.h>
+#include "basic.h"
+#include "ex.h"
 
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
 namespace GiNaC {
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC
 
-// typedef ${STLHEADER}<ex> ${STLT};
-typedef ${STLHEADER}<ex,malloc_alloc> ${STLT}; // CINT does not like ${STLHEADER}<...,default_alloc>
+// typedef std::${STLHEADER}<ex> ${STLT};
+typedef std::${STLHEADER}<ex,malloc_alloc> ${STLT}; // CINT does not like ${STLHEADER}<...,default_alloc>
 
 class ${CONTAINER} : public basic
 {
@@ -153,34 +206,13 @@ protected:
 public:
     ${CONTAINER}(${STLT} const & s, bool discardable=0);
     ${CONTAINER}(${STLT} * vp); // vp will be deleted
-    explicit ${CONTAINER}(const ex & e1);
-    explicit ${CONTAINER}(const ex & e1, const ex & e2);
-    explicit ${CONTAINER}(const ex & e1, const ex & e2, const ex & e3);
-    explicit ${CONTAINER}(const ex & e1, const ex & e2, const ex & e3,
-             const ex & e4);
-    explicit ${CONTAINER}(const ex & e1, const ex & e2, const ex & e3,
-             const ex & e4, const ex & e5);
-    explicit ${CONTAINER}(const ex & e1, const ex & e2, const ex & e3,
-             const ex & e4, const ex & e5, const ex & e6);
-    explicit ${CONTAINER}(const ex & e1, const ex & e2, const ex & e3,
-             const ex & e4, const ex & e5, const ex & e6,
-             const ex & e7);
-    explicit ${CONTAINER}(const ex & e1, const ex & e2, const ex & e3,
-             const ex & e4, const ex & e5, const ex & e6,
-             const ex & e7, const ex & e8);
-    explicit ${CONTAINER}(const ex & e1, const ex & e2, const ex & e3,
-             const ex & e4, const ex & e5, const ex & e6,
-             const ex & e7, const ex & e8, const ex & e9);
-    explicit ${CONTAINER}(const ex & e1, const ex & e2, const ex & e3,
-             const ex & e4, const ex & e5, const ex & e6,
-             const ex & e7, const ex & e8, const ex & e9,
-             const ex &e10);
+${constructors_interface}
 
 public:
     basic * duplicate() const;
-    void printraw(ostream & os) const;
-    void print(ostream & os, unsigned upper_precedence=0) const;
-    void printtree(ostream & os, unsigned indent) const;
+    void printraw(std::ostream & os) const;
+    void print(std::ostream & os, unsigned upper_precedence=0) const;
+    void printtree(std::ostream & os, unsigned indent) const;
     bool info(unsigned inf) const;
     unsigned nops() const;
     ex & let_op(int i);
@@ -189,7 +221,7 @@ public:
     ex eval(int level=0) const;
     ex evalf(int level=0) const;
     ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
-    ex diff(const symbol & s) const;
+    ex derivative(const symbol & s) const;
     ex subs(const lst & ls, const lst & lr) const;
 protected:
     int compare_same_type(const basic & other) const;
@@ -201,7 +233,7 @@ public:
     virtual ${CONTAINER} & append(const ex & b);
 ${PREPEND_INTERFACE}
 protected:
-    virtual void printseq(ostream & os, char openbracket, char delim,
+    virtual void printseq(std::ostream & os, char openbracket, char delim,
                           char closebracket, unsigned this_precedence,
                           unsigned upper_precedence=0) const;
     virtual ex this${CONTAINER}(${STLT} const & v) const;
@@ -231,9 +263,14 @@ inline const ${CONTAINER} &ex_to_${CONTAINER}(const ex &e)
     return static_cast<const ${CONTAINER} &>(*e.bp);
 }
 
-#ifndef NO_GINAC_NAMESPACE
+inline ${CONTAINER} &ex_to_nonconst_${CONTAINER}(const ex &e)
+{
+    return static_cast<${CONTAINER} &>(*e.bp);
+}
+
+#ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC
 
 #endif // ndef __GINAC_${CONTAINER_UC}_H__
 
@@ -254,6 +291,7 @@ $implementation=<<END_OF_IMPLEMENTATION;
  *                        \$let_op=${let_op}
  *                        \$open_bracket=${open_bracket}
  *                        \$close_bracket=${close_bracket}
+ *                        \$maxargs=${maxargs}
  *
  *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
  *
@@ -280,9 +318,9 @@ $implementation=<<END_OF_IMPLEMENTATION;
 #include "archive.h"
 #include "debugmsg.h"
 
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
 namespace GiNaC {
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC
 
 GINAC_IMPLEMENT_REGISTERED_CLASS(${CONTAINER}, basic)
 
@@ -360,146 +398,7 @@ ${CONTAINER}::${CONTAINER}(${STLT} * vp) : basic(TINFO_${CONTAINER})
     delete vp;
 }
 
-${CONTAINER}::${CONTAINER}(const ex & e1) :  basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 1 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,1);
-    seq.push_back(e1);
-}
-
-${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2) : basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 2 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,2);
-    seq.push_back(e1);
-    seq.push_back(e2);
-}
-
-${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3)
-    : basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 3 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,3);
-    seq.push_back(e1);
-    seq.push_back(e2);
-    seq.push_back(e3);
-}
-
-${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3,
-                     const ex & e4) : basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 4 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,4);
-    seq.push_back(e1);
-    seq.push_back(e2);
-    seq.push_back(e3);
-    seq.push_back(e4);
-}
-
-${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3,
-                     const ex & e4, const ex & e5) : basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 5 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,5);
-    seq.push_back(e1);
-    seq.push_back(e2);
-    seq.push_back(e3);
-    seq.push_back(e4);
-    seq.push_back(e5);
-}
-
-${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3,
-                     const ex & e4, const ex & e5, const ex & e6)
-    : basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 6 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,6);
-    seq.push_back(e1);
-    seq.push_back(e2);
-    seq.push_back(e3);
-    seq.push_back(e4);
-    seq.push_back(e5);
-    seq.push_back(e6);
-}
-
-${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3,
-                     const ex & e4, const ex & e5, const ex & e6,
-                     const ex & e7) : basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 7 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,7);
-    seq.push_back(e1);
-    seq.push_back(e2);
-    seq.push_back(e3);
-    seq.push_back(e4);
-    seq.push_back(e5);
-    seq.push_back(e6);
-    seq.push_back(e7);
-}
-
-${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3,
-                     const ex & e4, const ex & e5, const ex & e6,
-                     const ex & e7, const ex & e8) : basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 8 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,8);
-    seq.push_back(e1);
-    seq.push_back(e2);
-    seq.push_back(e3);
-    seq.push_back(e4);
-    seq.push_back(e5);
-    seq.push_back(e6);
-    seq.push_back(e7);
-    seq.push_back(e8);
-}
-
-${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3,
-                     const ex & e4, const ex & e5, const ex & e6,
-                     const ex & e7, const ex & e8, const ex & e9)
-    : basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 9 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,9);
-    seq.push_back(e1);
-    seq.push_back(e2);
-    seq.push_back(e3);
-    seq.push_back(e4);
-    seq.push_back(e5);
-    seq.push_back(e6);
-    seq.push_back(e7);
-    seq.push_back(e8);
-    seq.push_back(e9);
-}
-
-${CONTAINER}::${CONTAINER}(const ex & e1, const ex & e2, const ex & e3,
-                     const ex & e4, const ex & e5, const ex & e6,
-                     const ex & e7, const ex & e8, const ex & e9,
-                     const ex &e10)
-    : basic(TINFO_${CONTAINER})
-{
-    debugmsg("${CONTAINER} constructor from 10 ex",
-             LOGLEVEL_CONSTRUCT);
-    RESERVE(seq,10);
-    seq.push_back(e1);
-    seq.push_back(e2);
-    seq.push_back(e3);
-    seq.push_back(e4);
-    seq.push_back(e5);
-    seq.push_back(e6);
-    seq.push_back(e7);
-    seq.push_back(e8);
-    seq.push_back(e9);
-    seq.push_back(e10);
-}
+${constructors_implementation}
 
 //////////
 // archiving
@@ -547,7 +446,7 @@ basic * ${CONTAINER}::duplicate() const
     return new ${CONTAINER}(*this);
 }
 
-void ${CONTAINER}::printraw(ostream & os) const
+void ${CONTAINER}::printraw(std::ostream & os) const
 {
     debugmsg("${CONTAINER} printraw",LOGLEVEL_PRINT);
 
@@ -559,25 +458,26 @@ void ${CONTAINER}::printraw(ostream & os) const
     os << ")";
 }
 
-void ${CONTAINER}::print(ostream & os, unsigned upper_precedence) const
+void ${CONTAINER}::print(std::ostream & os, unsigned upper_precedence) const
 {
     debugmsg("${CONTAINER} print",LOGLEVEL_PRINT);
     // always print brackets around seq, ignore upper_precedence
     printseq(os,'${open_bracket}',',','${close_bracket}',precedence,precedence+1);
 }
 
-void ${CONTAINER}::printtree(ostream & os, unsigned indent) const
+void ${CONTAINER}::printtree(std::ostream & os, unsigned indent) const
 {
     debugmsg("${CONTAINER} printtree",LOGLEVEL_PRINT);
 
-    os << string(indent,' ') << "type=" << typeid(*this).name()
-       << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
+    os << std::string(indent,' ') << "type=" << typeid(*this).name()
+       << ", hash=" << hashvalue 
+       << " (0x" << std::hex << hashvalue << std::dec << ")"
        << ", flags=" << flags
-       << ", nops=" << nops() << endl;
+       << ", nops=" << nops() << std::endl;
     for (${STLT}::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
         (*cit).printtree(os,indent+delta_indent);
     }
-    os << string(indent+delta_indent,' ') << "=====" << endl;
+    os << std::string(indent+delta_indent,' ') << "=====" << std::endl;
 }
 
 // ${CONTAINER}::info() will be implemented by user elsewhere";
@@ -634,7 +534,7 @@ ex ${CONTAINER}::normal(lst &sym_lst, lst &repl_lst, int level) const
     return n.bp->basic::normal(sym_lst,repl_lst,level);
 }
 
-ex ${CONTAINER}::diff(const symbol & s) const
+ex ${CONTAINER}::derivative(const symbol & s) const
 {
     return this${CONTAINER}(diffchildren(s));
 }
@@ -710,7 +610,7 @@ ${PREPEND_IMPLEMENTATION}
 
 // protected
 
-void ${CONTAINER}::printseq(ostream & os, char openbracket, char delim,
+void ${CONTAINER}::printseq(std::ostream & os, char openbracket, char delim,
                          char closebracket, unsigned this_precedence,
                          unsigned upper_precedence) const
 {
@@ -758,7 +658,7 @@ bool ${CONTAINER}::is_canonical() const
     for (++it; it!=seq.end(); it_last=it, ++it) {
         if ((*it_last).compare(*it)>0) {
             if ((*it_last).compare(*it)>0) {
-                cout << *it_last << ">" << *it << "\\n";
+                std::cout << *it_last << ">" << *it << "\\n";
                 return 0;
                }
         }
@@ -896,9 +796,9 @@ unsigned ${CONTAINER}::precedence=10;
 const ${CONTAINER} some_${CONTAINER};
 const type_info & typeid_${CONTAINER}=typeid(some_${CONTAINER});
 
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC
 
 END_OF_IMPLEMENTATION