]> www.ginac.de Git - ginac.git/blobdiff - ginac/container.pl
- implemented global class registry (for class basic and derived classes)
[ginac.git] / ginac / container.pl
index 4f838e6802ced17bc7569c602b0fd0a99193525f..c9ff5e4f57eee4dd29d5137a9ecaddf3bb74c897 100755 (executable)
@@ -72,8 +72,8 @@ if ($let_op) {
     $LET_OP_IMPLEMENTATION=<<END_OF_LET_OP_IMPLEMENTATION
 ex & ${CONTAINER}::let_op(int const i)
 {
-    ASSERT(i>=0);
-    ASSERT(i<nops());
+    GINAC_ASSERT(i>=0);
+    GINAC_ASSERT(i<nops());
 
     ${STLT}::iterator it=seq.begin();
     for (int j=0; j<i; j++) {
@@ -89,7 +89,9 @@ END_OF_LET_OP_IMPLEMENTATION
 $interface=<<END_OF_INTERFACE;
 /** \@file ${CONTAINER}.h
  *
- *  Definition of GiNaC's ${CONTAINER}. 
+ *  Definition of GiNaC's ${CONTAINER}. */
+
+/*
  *  This file was generated automatically by container.pl.
  *  Please do not modify it directly, edit the perl script instead!
  *  container.pl options: \$CONTAINER=${CONTAINER}
@@ -100,7 +102,7 @@ $interface=<<END_OF_INTERFACE;
  *                        \$open_bracket=${open_bracket}
  *                        \$close_bracket=${close_bracket}
  *
- *  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
@@ -121,12 +123,23 @@ $interface=<<END_OF_INTERFACE;
 #define __GINAC_${CONTAINER_UC}_H__
 
 #include <${STLHEADER}>
+
+// CINT needs <algorithm> to work properly with <vector> and <list> 
+#include <algorithm>
+
 #include <ginac/basic.h>
+#include <ginac/ex.h>
 
-typedef ${STLHEADER}<ex> ${STLT};
+#ifndef NO_GINAC_NAMESPACE
+namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
+
+// typedef ${STLHEADER}<ex> ${STLT};
+typedef ${STLHEADER}<ex,malloc_alloc> ${STLT}; // CINT does not like ${STLHEADER}<...,default_alloc>
 
 class ${CONTAINER} : public basic
 {
+    GINAC_DECLARE_REGISTERED_CLASS(${CONTAINER}, basic)
 
 public:
     ${CONTAINER}();
@@ -169,7 +182,7 @@ public:
     void print(ostream & os, unsigned upper_precedence=0) const;
     void printtree(ostream & os, unsigned indent) const;
     bool info(unsigned inf) const;
-    int nops() const;
+    unsigned nops() const;
     ex & let_op(int const i);
     ex expand(unsigned options=0) const;
     bool has(ex const & other) const;
@@ -212,9 +225,15 @@ protected:
 extern const ${CONTAINER} some_${CONTAINER};
 extern type_info const & typeid_${CONTAINER};
 
-// macros
+// utility functions
+inline const ${CONTAINER} &ex_to_${CONTAINER}(const ex &e)
+{
+    return static_cast<const ${CONTAINER} &>(*e.bp);
+}
 
-#define ex_to_${CONTAINER}(X) (static_cast<${CONTAINER} const &>(*(X).bp))
+#ifndef NO_GINAC_NAMESPACE
+} // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE
 
 #endif // ndef __GINAC_${CONTAINER_UC}_H__
 
@@ -223,7 +242,9 @@ END_OF_INTERFACE
 $implementation=<<END_OF_IMPLEMENTATION;
 /** \@file ${CONTAINER}.cpp
  *
- *  Implementation of GiNaC's ${CONTAINER}. 
+ *  Implementation of GiNaC's ${CONTAINER}. */
+
+/*
  *  This file was generated automatically by container.pl.
  *  Please do not modify it directly, edit the perl script instead!
  *  container.pl options: \$CONTAINER=${CONTAINER}
@@ -234,7 +255,7 @@ $implementation=<<END_OF_IMPLEMENTATION;
  *                        \$open_bracket=${open_bracket}
  *                        \$close_bracket=${close_bracket}
  *
- *  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
@@ -256,6 +277,14 @@ $implementation=<<END_OF_IMPLEMENTATION;
 
 #include "${CONTAINER}.h"
 #include "ex.h"
+#include "archive.h"
+#include "debugmsg.h"
+
+#ifndef NO_GINAC_NAMESPACE
+namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
+
+GINAC_IMPLEMENT_REGISTERED_CLASS(${CONTAINER}, basic)
 
 ${RESERVE_IMPLEMENTATION}
 
@@ -296,14 +325,14 @@ ${CONTAINER} const & ${CONTAINER}::operator=(${CONTAINER} const & other)
 
 void ${CONTAINER}::copy(${CONTAINER} const & other)
 {
-    basic::copy(other);
+    inherited::copy(other);
     seq=other.seq;
 }
 
 void ${CONTAINER}::destroy(bool call_parent)
 {
     seq.clear();
-    if (call_parent) basic::destroy(call_parent);
+    if (call_parent) inherited::destroy(call_parent);
 }
 
 //////////
@@ -326,7 +355,7 @@ ${CONTAINER}::${CONTAINER}(${STLT} const & s, bool discardable) :  basic(TINFO_$
 ${CONTAINER}::${CONTAINER}(${STLT} * vp) : basic(TINFO_${CONTAINER})
 {
     debugmsg("${CONTAINER} constructor from ${STLT} *",LOGLEVEL_CONSTRUCT);
-    ASSERT(vp!=0);
+    GINAC_ASSERT(vp!=0);
     seq.swap(*vp);
     delete vp;
 }
@@ -472,6 +501,40 @@ ${CONTAINER}::${CONTAINER}(ex const & e1, ex const & e2, ex const & e3,
     seq.push_back(e10);
 }
 
+//////////
+// archiving
+//////////
+
+/** Construct object from archive_node. */
+${CONTAINER}::${CONTAINER}(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
+{
+    debugmsg("${CONTAINER} constructor from archive_node", LOGLEVEL_CONSTRUCT);
+    for (unsigned int i=0; true; i++) {
+        ex e;
+        if (n.find_ex("seq", e, sym_lst, i))
+            seq.push_back(e);
+        else
+            break;
+    }
+}
+
+/** Unarchive the object. */
+ex ${CONTAINER}::unarchive(const archive_node &n, const lst &sym_lst)
+{
+    return (new ${CONTAINER}(n, sym_lst))->setflag(status_flags::dynallocated);
+}
+
+/** Archive the object. */
+void ${CONTAINER}::archive(archive_node &n) const
+{
+    inherited::archive(n);
+    ${STLT}::const_iterator i = seq.begin(), iend = seq.end();
+    while (i != iend) {
+        n.add_ex("seq", *i);
+        i++;
+    }
+}
+
 //////////
 // functions overriding virtual functions from bases classes
 //////////
@@ -519,7 +582,7 @@ void ${CONTAINER}::printtree(ostream & os, unsigned indent) const
 
 // ${CONTAINER}::info() will be implemented by user elsewhere";
 
-int ${CONTAINER}::nops() const
+unsigned ${CONTAINER}::nops() const
 {
     return seq.size();
 }
@@ -541,7 +604,7 @@ ex ${CONTAINER}::expand(unsigned options) const
 
 bool ${CONTAINER}::has(ex const & other) const
 {
-    ASSERT(other.bp!=0);
+    GINAC_ASSERT(other.bp!=0);
     if (is_equal(*other.bp)) return true;
     for (${STLT}::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
         if ((*it).has(other)) return true;
@@ -589,7 +652,7 @@ ex ${CONTAINER}::subs(lst const & ls, lst const & lr) const
 
 int ${CONTAINER}::compare_same_type(basic const & other) const
 {
-    ASSERT(is_of_type(other,${CONTAINER}));
+    GINAC_ASSERT(is_of_type(other,${CONTAINER}));
     ${CONTAINER} const & o=static_cast<${CONTAINER} const &>
                                     (const_cast<basic &>(other));
     int cmpval;
@@ -610,7 +673,7 @@ int ${CONTAINER}::compare_same_type(basic const & other) const
 
 bool ${CONTAINER}::is_equal_same_type(basic const & other) const
 {
-    ASSERT(is_of_type(other,${CONTAINER}));
+    GINAC_ASSERT(is_of_type(other,${CONTAINER}));
     ${CONTAINER} const & o=static_cast<${CONTAINER} const &>
                                     (const_cast<basic &>(other));
     if (seq.size()!=o.seq.size()) return false;
@@ -833,6 +896,10 @@ unsigned ${CONTAINER}::precedence=10;
 const ${CONTAINER} some_${CONTAINER};
 type_info const & typeid_${CONTAINER}=typeid(some_${CONTAINER});
 
+#ifndef NO_GINAC_NAMESPACE
+} // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE
+
 END_OF_IMPLEMENTATION
 
 print "Creating interface file ${CONTAINER}.h...";