]> www.ginac.de Git - ginac.git/blobdiff - ginac/isospin.cpp
* New funny timing added: compute an antipode in Yukawa theory.
[ginac.git] / ginac / isospin.cpp
index e5ac27b32149b313f7b56f637483ff9a9bf25adc..2a2a254dcd827371a47f10fef4edb91af26445bb 100644 (file)
@@ -4,7 +4,7 @@
  *  No real implementation yet, to be done.     */
 
 /*
- *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2001 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_GINAC_NAMESPACE
 namespace GiNaC {
-#endif // ndef NO_GINAC_NAMESPACE
+
+GINAC_IMPLEMENT_REGISTERED_CLASS(isospin, indexed)
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
@@ -41,48 +43,26 @@ namespace GiNaC {
 
 isospin::isospin()
 {
-    debugmsg("isospin default constructor",LOGLEVEL_CONSTRUCT);
-    serial=next_serial++;
-    name=autoname_prefix()+ToString(serial);
-    tinfo_key=TINFO_isospin;
-}
-
-isospin::~isospin()
-{
-    debugmsg("isospin destructor",LOGLEVEL_DESTRUCT);
-    destroy(0);
-}
-
-isospin::isospin(isospin const & other)
-{
-    debugmsg("isospin copy constructor",LOGLEVEL_CONSTRUCT);
-    copy (other);
-}
-
-isospin const & isospin::operator=(isospin const & other)
-{
-    debugmsg("isospin operator=",LOGLEVEL_ASSIGNMENT);
-    if (this != &other) {
-        destroy(1);
-        copy(other);
-    }
-    return *this;
+       debugmsg("isospin default constructor",LOGLEVEL_CONSTRUCT);
+       serial=next_serial++;
+       name=autoname_prefix()+ToString(serial);
+       tinfo_key=TINFO_isospin;
 }
 
 // protected
 
-void isospin::copy(isospin const & other)
+void isospin::copy(const isospin & other)
 {
-    indexed::copy(other);
-    name=other.name;
-    serial=other.serial;
+       inherited::copy(other);
+       name=other.name;
+       serial=other.serial;
 }
 
 void isospin::destroy(bool call_parent)
 {
-    if (call_parent) {
-        indexed::destroy(call_parent);
-    }
+       if (call_parent) {
+               inherited::destroy(call_parent);
+       }
 }
 
 //////////
@@ -91,88 +71,116 @@ void isospin::destroy(bool call_parent)
 
 // public
 
-isospin::isospin(string const & initname)
+isospin::isospin(const std::string & initname)
 {
-    debugmsg("isospin constructor from string",LOGLEVEL_CONSTRUCT);
-    name=initname;
-    serial=next_serial++;
-    tinfo_key=TINFO_isospin;
+       debugmsg("isospin constructor from string",LOGLEVEL_CONSTRUCT);
+       name=initname;
+       serial=next_serial++;
+       tinfo_key=TINFO_isospin;
 }
 
 //////////
-// functions overriding virtual functions from bases classes
+// archiving
 //////////
 
-// public
+/** 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;
+}
 
-basic * isospin::duplicate() const
+/** Unarchive the object. */
+ex isospin::unarchive(const archive_node &n, const lst &sym_lst)
 {
-    debugmsg("isospin duplicate",LOGLEVEL_DUPLICATE);
-    return new isospin(*this);
+       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);
 }
 
-void isospin::printraw(ostream & os) const
+//////////
+// functions overriding virtual functions from bases classes
+//////////
+
+// public
+
+void isospin::printraw(std::ostream & os) const
 {
-    debugmsg("isospin printraw",LOGLEVEL_PRINT);
-    os << "isospin(" << "name=" << name << ",serial=" << serial
-       << ",indices=";
-    printrawindices(os);
-    os << ",hash=" << hashvalue << ",flags=" << flags << ")";
+       debugmsg("isospin printraw",LOGLEVEL_PRINT);
+       os << "isospin(" << "name=" << name << ",serial=" << serial
+          << ",indices=";
+       printrawindices(os);
+       os << ",hash=" << hashvalue << ",flags=" << flags << ")";
 }
 
-void isospin::printtree(ostream & os, unsigned indent) const
+void isospin::printtree(std::ostream & os, unsigned indent) const
 {
-    debugmsg("isospin printtree",LOGLEVEL_PRINT);
-    os << string(indent,' ') << name << " (isospin): "
-       << "serial=" << serial << ","
-       << seq.size() << "indices=";
-    printtreeindices(os,indent);
-    os << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
-       << ", flags=" << flags << endl;
+       debugmsg("isospin printtree",LOGLEVEL_PRINT);
+       os << std::string(indent,' ') << name << " (isospin): "
+          << "serial=" << serial << ","
+          << seq.size() << "indices=";
+       printtreeindices(os,indent);
+       os << ", hash=" << hashvalue
+          << " (0x" << std::hex << hashvalue << std::dec << ")"
+          << ", flags=" << flags << std::endl;
 }
 
-void isospin::print(ostream & os, unsigned upper_precedence) const
+void isospin::print(std::ostream & os, unsigned upper_precedence) const
 {
-    debugmsg("isospin print",LOGLEVEL_PRINT);
-    os << name;
-    printindices(os);
+       debugmsg("isospin print",LOGLEVEL_PRINT);
+       os << name;
+       printindices(os);
 }
 
-void isospin::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) const
+void isospin::printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const
 {
-    debugmsg("isospin print csrc",LOGLEVEL_PRINT);
-    print(os,upper_precedence);
+       debugmsg("isospin print csrc",LOGLEVEL_PRINT);
+       print(os,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
 {
-    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 serial < o->serial ? -1 : 1;
+       GINAC_ASSERT(other.tinfo() == TINFO_isospin);
+       const isospin *o = static_cast<const isospin *>(&other);
+       if (serial==o->serial) {
+               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);
+       return simplified_ncmul(v);
 }
 
 unsigned isospin::calchash(void) const
 {
-    hashvalue=golden_ratio_hash(golden_ratio_hash(0x55555556U ^
-                                                  golden_ratio_hash(tinfo_key) ^
-                                                  serial));
-    setflag(status_flags::hash_calculated);
-    return hashvalue;
+       hashvalue = golden_ratio_hash(golden_ratio_hash(0x55555556U ^
+                   golden_ratio_hash(tinfo_key) ^ serial));
+       setflag(status_flags::hash_calculated);
+       return hashvalue;
 }
 
 //////////
@@ -185,17 +193,17 @@ unsigned isospin::calchash(void) const
 // non-virtual functions in this class
 //////////
 
-void isospin::setname(string const & n)
+void isospin::setname(const std::string & n)
 {
-    name=n;
+       name = n;
 }
 
 // private
 
-string & isospin::autoname_prefix(void)
+std::string & isospin::autoname_prefix(void)
 {
-    static string * s=new string("isospin");
-    return *s;
+       static std::string * s = new std::string("isospin");
+       return *s;
 }
 
 //////////
@@ -204,16 +212,7 @@ string & isospin::autoname_prefix(void)
 
 // private
 
-unsigned isospin::next_serial=0;
-
-//////////
-// global constants
-//////////
-
-const isospin some_isospin;
-type_info const & typeid_isospin=typeid(some_isospin);
+unsigned isospin::next_serial = 0;
 
-#ifndef NO_GINAC_NAMESPACE
 } // namespace GiNaC
-#endif // ndef NO_GINAC_NAMESPACE