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