]> 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 a55daa47d0fd2edaa5b41614fdd451f5538bbaea..e2b4374f4e745701a82a87038ce7a3b23d879def 100755 (executable)
@@ -141,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
@@ -259,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);
 
@@ -360,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
@@ -382,6 +384,7 @@ $implementation=<<END_OF_IMPLEMENTATION;
 
 #include "function.h"
 #include "ex.h"
+#include "archive.h"
 #include "utils.h"
 #include "debugmsg.h"
 
@@ -389,6 +392,8 @@ $implementation=<<END_OF_IMPLEMENTATION;
 namespace GiNaC {
 #endif // ndef NO_GINAC_NAMESPACE
 
+GINAC_IMPLEMENT_REGISTERED_CLASS(function, exprseq)
+
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
 //////////
@@ -472,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
 //////////
@@ -519,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;