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