]> www.ginac.de Git - ginac.git/blobdiff - ginac/isospin.cpp
- Added version.h to the list of files to be installed.
[ginac.git] / ginac / isospin.cpp
index 3cc6b5e12219a0582dbbecb49c27616be027b504..8ff6b916ae8354ac58261d04597fe727a92a14cc 100644 (file)
@@ -4,7 +4,7 @@
  *  No real implementation yet, to be done.     */
 
 /*
- *  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
 #include "isospin.h"
 #include "ex.h"
 #include "ncmul.h"
+#include "lst.h"
+#include "archive.h"
 #include "utils.h"
+#include "debugmsg.h"
+
+#ifndef NO_NAMESPACE_GINAC
+namespace GiNaC {
+#endif // ndef NO_NAMESPACE_GINAC
+
+GINAC_IMPLEMENT_REGISTERED_CLASS(isospin, indexed)
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
@@ -48,13 +57,13 @@ isospin::~isospin()
     destroy(0);
 }
 
-isospin::isospin(isospin const & other)
+isospin::isospin(const isospin & other)
 {
     debugmsg("isospin copy constructor",LOGLEVEL_CONSTRUCT);
     copy (other);
 }
 
-isospin const & isospin::operator=(isospin const & other)
+const isospin & isospin::operator=(const isospin & other)
 {
     debugmsg("isospin operator=",LOGLEVEL_ASSIGNMENT);
     if (this != &other) {
@@ -66,9 +75,9 @@ isospin const & isospin::operator=(isospin const & other)
 
 // protected
 
-void isospin::copy(isospin const & other)
+void isospin::copy(const isospin & other)
 {
-    indexed::copy(other);
+    inherited::copy(other);
     name=other.name;
     serial=other.serial;
 }
@@ -76,7 +85,7 @@ void isospin::copy(isospin const & other)
 void isospin::destroy(bool call_parent)
 {
     if (call_parent) {
-        indexed::destroy(call_parent);
+        inherited::destroy(call_parent);
     }
 }
 
@@ -86,7 +95,7 @@ void isospin::destroy(bool call_parent)
 
 // public
 
-isospin::isospin(string const & initname)
+isospin::isospin(const string & initname)
 {
     debugmsg("isospin constructor from string",LOGLEVEL_CONSTRUCT);
     name=initname;
@@ -94,6 +103,40 @@ isospin::isospin(string const & initname)
     tinfo_key=TINFO_isospin;
 }
 
+//////////
+// archiving
+//////////
+
+/** Construct object from archive_node. */
+isospin::isospin(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
+{
+    debugmsg("isospin constructor from archive_node", LOGLEVEL_CONSTRUCT);
+    serial = next_serial++;
+    if (!(n.find_string("name", name)))
+        name = autoname_prefix() + ToString(serial);
+    tinfo_key = TINFO_isospin;
+}
+
+/** Unarchive the object. */
+ex isospin::unarchive(const archive_node &n, const lst &sym_lst)
+{
+    ex s = (new isospin(n, sym_lst))->setflag(status_flags::dynallocated);
+
+    // If isospin is in sym_lst, return the existing isospin
+    for (unsigned i=0; i<sym_lst.nops(); i++) {
+        if (is_ex_of_type(sym_lst.op(i), isospin) && (ex_to_isospin(sym_lst.op(i)).name == ex_to_isospin(s).name))
+            return sym_lst.op(i);
+    }
+    return s;
+}
+
+/** Archive the object. */
+void isospin::archive(archive_node &n) const
+{
+    inherited::archive(n);
+    n.add_string("name", name);
+}
+
 //////////
 // functions overriding virtual functions from bases classes
 //////////
@@ -141,22 +184,22 @@ void isospin::printcsrc(ostream & os, unsigned type, unsigned upper_precedence)
 
 bool isospin::info(unsigned inf) const
 {
-    return indexed::info(inf);
+    return inherited::info(inf);
 }
 
 // protected
 
-int isospin::compare_same_type(basic const & other) const
+int isospin::compare_same_type(const basic & other) const
 {
-    ASSERT(other.tinfo() == TINFO_isospin);
+    GINAC_ASSERT(other.tinfo() == TINFO_isospin);
     const isospin *o = static_cast<const isospin *>(&other);
     if (serial==o->serial) {
-        return indexed::compare_same_type(other);
+        return inherited::compare_same_type(other);
     }
     return serial < o->serial ? -1 : 1;
 }
 
-ex isospin::simplify_ncmul(exvector const & v) const
+ex isospin::simplify_ncmul(const exvector & v) const
 {
     return simplified_ncmul(v);
 }
@@ -180,7 +223,7 @@ unsigned isospin::calchash(void) const
 // non-virtual functions in this class
 //////////
 
-void isospin::setname(string const & n)
+void isospin::setname(const string & n)
 {
     name=n;
 }
@@ -206,5 +249,9 @@ unsigned isospin::next_serial=0;
 //////////
 
 const isospin some_isospin;
-type_info const & typeid_isospin=typeid(some_isospin);
+const type_info & typeid_isospin=typeid(some_isospin);
+
+#ifndef NO_NAMESPACE_GINAC
+} // namespace GiNaC
+#endif // ndef NO_NAMESPACE_GINAC