3 * Implementation of GiNaC's isospin objects.
4 * No real implementation yet, to be done. */
7 * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 GINAC_IMPLEMENT_REGISTERED_CLASS(isospin, indexed)
39 // default constructor, destructor, copy constructor assignment operator and helpers
46 debugmsg("isospin default constructor",LOGLEVEL_CONSTRUCT);
48 name=autoname_prefix()+ToString(serial);
49 tinfo_key=TINFO_isospin;
54 void isospin::copy(const isospin & other)
56 inherited::copy(other);
61 void isospin::destroy(bool call_parent)
64 inherited::destroy(call_parent);
74 isospin::isospin(const std::string & initname)
76 debugmsg("isospin constructor from string",LOGLEVEL_CONSTRUCT);
79 tinfo_key=TINFO_isospin;
86 /** Construct object from archive_node. */
87 isospin::isospin(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
89 debugmsg("isospin constructor from archive_node", LOGLEVEL_CONSTRUCT);
90 serial = next_serial++;
91 if (!(n.find_string("name", name)))
92 name = autoname_prefix() + ToString(serial);
93 tinfo_key = TINFO_isospin;
96 /** Unarchive the object. */
97 ex isospin::unarchive(const archive_node &n, const lst &sym_lst)
99 ex s = (new isospin(n, sym_lst))->setflag(status_flags::dynallocated);
101 // If isospin is in sym_lst, return the existing isospin
102 for (unsigned i=0; i<sym_lst.nops(); i++) {
103 if (is_ex_of_type(sym_lst.op(i), isospin) && (ex_to_isospin(sym_lst.op(i)).name == ex_to_isospin(s).name))
104 return sym_lst.op(i);
109 /** Archive the object. */
110 void isospin::archive(archive_node &n) const
112 inherited::archive(n);
113 n.add_string("name", name);
117 // functions overriding virtual functions from bases classes
122 void isospin::printraw(std::ostream & os) const
124 debugmsg("isospin printraw",LOGLEVEL_PRINT);
125 os << "isospin(" << "name=" << name << ",serial=" << serial
128 os << ",hash=" << hashvalue << ",flags=" << flags << ")";
131 void isospin::printtree(std::ostream & os, unsigned indent) const
133 debugmsg("isospin printtree",LOGLEVEL_PRINT);
134 os << std::string(indent,' ') << name << " (isospin): "
135 << "serial=" << serial << ","
136 << seq.size() << "indices=";
137 printtreeindices(os,indent);
138 os << ", hash=" << hashvalue
139 << " (0x" << std::hex << hashvalue << std::dec << ")"
140 << ", flags=" << flags << std::endl;
143 void isospin::print(std::ostream & os, unsigned upper_precedence) const
145 debugmsg("isospin print",LOGLEVEL_PRINT);
150 void isospin::printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const
152 debugmsg("isospin print csrc",LOGLEVEL_PRINT);
153 print(os,upper_precedence);
156 bool isospin::info(unsigned inf) const
158 return inherited::info(inf);
163 int isospin::compare_same_type(const basic & other) const
165 GINAC_ASSERT(other.tinfo() == TINFO_isospin);
166 const isospin *o = static_cast<const isospin *>(&other);
167 if (serial==o->serial) {
168 return inherited::compare_same_type(other);
170 return serial < o->serial ? -1 : 1;
173 ex isospin::simplify_ncmul(const exvector & v) const
175 return simplified_ncmul(v);
178 unsigned isospin::calchash(void) const
180 hashvalue = golden_ratio_hash(golden_ratio_hash(0x55555556U ^
181 golden_ratio_hash(tinfo_key) ^ serial));
182 setflag(status_flags::hash_calculated);
187 // virtual functions which can be overridden by derived classes
193 // non-virtual functions in this class
196 void isospin::setname(const std::string & n)
203 std::string & isospin::autoname_prefix(void)
205 static std::string * s = new std::string("isospin");
210 // static member variables
215 unsigned isospin::next_serial = 0;