]> www.ginac.de Git - ginac.git/blobdiff - ginac/function.pl
- Use newer fig2dev which supports eps (old ones are broken now!)
[ginac.git] / ginac / function.pl
index 6493042b7753d5f0583aad1805faab91fe58d33b..e2b4374f4e745701a82a87038ce7a3b23d879def 100755 (executable)
@@ -44,7 +44,7 @@ END_OF_DECLARE_FUNCTION_MACRO_NAMESPACE
 $declare_function_macro_no_namespace=generate(
     <<'END_OF_DECLARE_FUNCTION_MACRO_NO_NAMESPACE','ex const & p${N}','p${N}');
 #define DECLARE_FUNCTION_${N}P(NAME) \\
-extern unsigned function_index_##NAME; \\
+extern const unsigned function_index_##NAME; \\
 inline function NAME(${SEQ1}) { \\
     return function(function_index_##NAME, ${SEQ2}); \\
 }
@@ -110,7 +110,12 @@ END_OF_DIFF_SWITCH_STATEMENT
 $series_switch_statement=generate(
     <<'END_OF_SERIES_SWITCH_STATEMENT','seq[${N}-1]','');
     case ${N}:
-        return ((series_funcp_${N})(registered_functions()[serial].s))(${SEQ1},s,point,order);
+        try {
+            res = ((series_funcp_${N})(registered_functions()[serial].s))(${SEQ1},s,point,order);
+        } catch (do_taylor) {
+            res = basic::series(s, point, order);
+        }
+        return res;
         break;
 END_OF_SERIES_SWITCH_STATEMENT
 
@@ -136,7 +141,7 @@ $interface=<<END_OF_INTERFACE;
  *  Please do not modify it directly, edit the perl script instead!
  *  function.pl options: \$maxargs=${maxargs}
  *
- *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -183,11 +188,11 @@ $declare_function_macro_no_namespace
 #ifndef NO_GINAC_NAMESPACE
 
 #define REGISTER_FUNCTION(NAME,E,EF,D,S) \\
-
 const unsigned function_index_##NAME=GiNaC::function::register_new(#NAME,E,EF,D,S);
 
 #else // ndef NO_GINAC_NAMESPACE
 
+#define REGISTER_FUNCTION(NAME,E,EF,D,S) \\
 const unsigned function_index_##NAME=function::register_new(#NAME,E,EF,D,S);
 
 #endif // ndef NO_GINAC_NAMESPACE
@@ -254,6 +259,8 @@ struct registered_function_info {
     and user defined functions */
 class function : public exprseq
 {
+    GINAC_DECLARE_REGISTERED_CLASS(function, exprseq)
+
     // CINT has a linking problem
     friend void ginsh_get_ginac_functions(void);
 
@@ -355,7 +362,7 @@ $implementation=<<END_OF_IMPLEMENTATION;
  *  Please do not modify it directly, edit the perl script instead!
  *  function.pl options: \$maxargs=${maxargs}
  *
- *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -377,12 +384,16 @@ $implementation=<<END_OF_IMPLEMENTATION;
 
 #include "function.h"
 #include "ex.h"
+#include "archive.h"
+#include "utils.h"
 #include "debugmsg.h"
 
 #ifndef NO_GINAC_NAMESPACE
 namespace GiNaC {
 #endif // ndef NO_GINAC_NAMESPACE
 
+GINAC_IMPLEMENT_REGISTERED_CLASS(function, exprseq)
+
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
 //////////
@@ -466,6 +477,46 @@ function::function(unsigned ser, exvector * vp)
     tinfo_key = TINFO_function;
 }
 
+//////////
+// archiving
+//////////
+
+/** Construct object from archive_node. */
+function::function(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
+{
+    debugmsg("function constructor from archive_node", LOGLEVEL_CONSTRUCT);
+
+    // Find serial number by function name
+    string s;
+    if (n.find_string("name", s)) {
+        unsigned int ser = 0;
+        vector<registered_function_info>::const_iterator i = registered_functions().begin(), iend = registered_functions().end();
+        while (i != iend) {
+            if (s == i->name) {
+                serial = ser;
+                return;
+            }
+            i++; ser++;
+        }
+        throw (std::runtime_error("unknown function '" + s + "' in archive"));
+    } else
+        throw (std::runtime_error("unnamed function in archive"));
+}
+
+/** Unarchive the object. */
+ex function::unarchive(const archive_node &n, const lst &sym_lst)
+{
+    return (new function(n, sym_lst))->setflag(status_flags::dynallocated);
+}
+
+/** Archive the object. */
+void function::archive(archive_node &n) const
+{
+    inherited::archive(n);
+    GINAC_ASSERT(serial < registered_functions().size());
+    n.add_string("name", registered_functions()[serial].name);
+}
+
 //////////
 // functions overriding virtual functions from bases classes
 //////////
@@ -513,7 +564,7 @@ void function::printtree(ostream & os, unsigned indent) const
        << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
        << ", flags=" << flags
        << ", nops=" << nops() << endl;
-    for (int i=0; i<nops(); ++i) {
+    for (unsigned i=0; i<nops(); ++i) {
         seq[i].printtree(os,indent+delta_indent);
     }
     os << string(indent+delta_indent,' ') << "=====" << endl;
@@ -602,6 +653,7 @@ ex function::series(symbol const & s, ex const & point, int order) const
     if (registered_functions()[serial].s==0) {
         return basic::series(s, point, order);
     }
+    ex res;
     switch (registered_functions()[serial].nparams) {
         // the following lines have been generated for max. ${maxargs} parameters
 ${series_switch_statement}