]> www.ginac.de Git - ginac.git/blob - ginac/isospin.cpp
- is_zero() is now called on expanded expressions in gcd()
[ginac.git] / ginac / isospin.cpp
1 /** @file isospin.cpp
2  *
3  *  Implementation of GiNaC's isospin objects.
4  *  No real implementation yet, to be done.     */
5
6 /*
7  *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
8  *
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.
13  *
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.
18  *
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
22  */
23
24 #include <string>
25
26 #include "isospin.h"
27 #include "ex.h"
28 #include "ncmul.h"
29 #include "utils.h"
30 #include "debugmsg.h"
31
32 namespace GiNaC {
33
34 //////////
35 // default constructor, destructor, copy constructor assignment operator and helpers
36 //////////
37
38 // public
39
40 isospin::isospin()
41 {
42     debugmsg("isospin default constructor",LOGLEVEL_CONSTRUCT);
43     serial=next_serial++;
44     name=autoname_prefix()+ToString(serial);
45     tinfo_key=TINFO_isospin;
46 }
47
48 isospin::~isospin()
49 {
50     debugmsg("isospin destructor",LOGLEVEL_DESTRUCT);
51     destroy(0);
52 }
53
54 isospin::isospin(isospin const & other)
55 {
56     debugmsg("isospin copy constructor",LOGLEVEL_CONSTRUCT);
57     copy (other);
58 }
59
60 isospin const & isospin::operator=(isospin const & other)
61 {
62     debugmsg("isospin operator=",LOGLEVEL_ASSIGNMENT);
63     if (this != &other) {
64         destroy(1);
65         copy(other);
66     }
67     return *this;
68 }
69
70 // protected
71
72 void isospin::copy(isospin const & other)
73 {
74     indexed::copy(other);
75     name=other.name;
76     serial=other.serial;
77 }
78
79 void isospin::destroy(bool call_parent)
80 {
81     if (call_parent) {
82         indexed::destroy(call_parent);
83     }
84 }
85
86 //////////
87 // other constructors
88 //////////
89
90 // public
91
92 isospin::isospin(string const & initname)
93 {
94     debugmsg("isospin constructor from string",LOGLEVEL_CONSTRUCT);
95     name=initname;
96     serial=next_serial++;
97     tinfo_key=TINFO_isospin;
98 }
99
100 //////////
101 // functions overriding virtual functions from bases classes
102 //////////
103
104 // public
105
106 basic * isospin::duplicate() const
107 {
108     debugmsg("isospin duplicate",LOGLEVEL_DUPLICATE);
109     return new isospin(*this);
110 }
111
112 void isospin::printraw(ostream & os) const
113 {
114     debugmsg("isospin printraw",LOGLEVEL_PRINT);
115     os << "isospin(" << "name=" << name << ",serial=" << serial
116        << ",indices=";
117     printrawindices(os);
118     os << ",hash=" << hashvalue << ",flags=" << flags << ")";
119 }
120
121 void isospin::printtree(ostream & os, unsigned indent) const
122 {
123     debugmsg("isospin printtree",LOGLEVEL_PRINT);
124     os << string(indent,' ') << name << " (isospin): "
125        << "serial=" << serial << ","
126        << seq.size() << "indices=";
127     printtreeindices(os,indent);
128     os << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
129        << ", flags=" << flags << endl;
130 }
131
132 void isospin::print(ostream & os, unsigned upper_precedence) const
133 {
134     debugmsg("isospin print",LOGLEVEL_PRINT);
135     os << name;
136     printindices(os);
137 }
138
139 void isospin::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) const
140 {
141     debugmsg("isospin print csrc",LOGLEVEL_PRINT);
142     print(os,upper_precedence);
143 }
144
145 bool isospin::info(unsigned inf) const
146 {
147     return indexed::info(inf);
148 }
149
150 // protected
151
152 int isospin::compare_same_type(basic const & other) const
153 {
154     ASSERT(other.tinfo() == TINFO_isospin);
155     const isospin *o = static_cast<const isospin *>(&other);
156     if (serial==o->serial) {
157         return indexed::compare_same_type(other);
158     }
159     return serial < o->serial ? -1 : 1;
160 }
161
162 ex isospin::simplify_ncmul(exvector const & v) const
163 {
164     return simplified_ncmul(v);
165 }
166
167 unsigned isospin::calchash(void) const
168 {
169     hashvalue=golden_ratio_hash(golden_ratio_hash(0x55555556U ^
170                                                   golden_ratio_hash(tinfo_key) ^
171                                                   serial));
172     setflag(status_flags::hash_calculated);
173     return hashvalue;
174 }
175
176 //////////
177 // virtual functions which can be overridden by derived classes
178 //////////
179
180 // none
181
182 //////////
183 // non-virtual functions in this class
184 //////////
185
186 void isospin::setname(string const & n)
187 {
188     name=n;
189 }
190
191 // private
192
193 string & isospin::autoname_prefix(void)
194 {
195     static string * s=new string("isospin");
196     return *s;
197 }
198
199 //////////
200 // static member variables
201 //////////
202
203 // private
204
205 unsigned isospin::next_serial=0;
206
207 //////////
208 // global constants
209 //////////
210
211 const isospin some_isospin;
212 type_info const & typeid_isospin=typeid(some_isospin);
213
214 } // namespace GiNaC