]> www.ginac.de Git - ginac.git/blob - ginac/clifford.cpp
- enforced GiNaC coding standards :-)
[ginac.git] / ginac / clifford.cpp
1 /** @file clifford.cpp
2  *
3  *  Implementation of GiNaC's clifford objects.
4  *  No real implementation yet, to be done.    
5  *
6  *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include <string>
24
25 #include "ginac.h"
26 #include "utils.h"
27
28 //////////
29 // default constructor, destructor, copy constructor assignment operator and helpers
30 //////////
31
32 // public
33
34 clifford::clifford()
35 {
36     debugmsg("clifford default constructor",LOGLEVEL_CONSTRUCT);
37     serial=next_serial++;
38     name=autoname_prefix()+ToString(serial);
39     tinfo_key=TINFO_CLIFFORD;
40 }
41
42 clifford::~clifford()
43 {
44     debugmsg("clifford destructor",LOGLEVEL_DESTRUCT);
45     destroy(0);
46 }
47
48 clifford::clifford(clifford const & other)
49 {
50     debugmsg("clifford copy constructor",LOGLEVEL_CONSTRUCT);
51     copy (other);
52 }
53
54 clifford const & clifford::operator=(clifford const & other)
55 {
56     debugmsg("clifford operator=",LOGLEVEL_ASSIGNMENT);
57     if (this != &other) {
58         destroy(1);
59         copy(other);
60     }
61     return *this;
62 }
63
64 // protected
65
66 void clifford::copy(clifford const & other)
67 {
68     indexed::copy(other);
69     name=other.name;
70     serial=other.serial;
71 }
72
73 void clifford::destroy(bool call_parent)
74 {
75     if (call_parent) {
76         indexed::destroy(call_parent);
77     }
78 }
79
80 //////////
81 // other constructors
82 //////////
83
84 // public
85
86 clifford::clifford(string const & initname)
87 {
88     debugmsg("clifford constructor from string",LOGLEVEL_CONSTRUCT);
89     name=initname;
90     serial=next_serial++;
91     tinfo_key=TINFO_CLIFFORD;
92 }
93
94 //////////
95 // functions overriding virtual functions from bases classes
96 //////////
97
98 // public
99
100 basic * clifford::duplicate() const
101 {
102     debugmsg("clifford duplicate",LOGLEVEL_DUPLICATE);
103     return new clifford(*this);
104 }
105
106 void clifford::printraw(ostream & os) const
107 {
108     debugmsg("clifford printraw",LOGLEVEL_PRINT);
109     os << "clifford(" << "name=" << name << ",serial=" << serial
110        << ",indices=";
111     printrawindices(os);
112     os << ",hash=" << hashvalue << ",flags=" << flags << ")";
113 }
114
115 void clifford::printtree(ostream & os, unsigned indent) const
116 {
117     debugmsg("clifford printtree",LOGLEVEL_PRINT);
118     os << string(indent,' ') << name << " (clifford): "
119        << "serial=" << serial << ","
120        << seq.size() << "indices=";
121     printtreeindices(os,indent);
122     os << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
123        << ", flags=" << flags << endl;
124 }
125
126 void clifford::print(ostream & os, unsigned upper_precedence) const
127 {
128     debugmsg("clifford print",LOGLEVEL_PRINT);
129     os << name;
130     printindices(os);
131 }
132
133 void clifford::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) const
134 {
135     debugmsg("clifford print csrc",LOGLEVEL_PRINT);
136     print(os,upper_precedence);
137 }
138
139 bool clifford::info(unsigned inf) const
140 {
141     return indexed::info(inf);
142 }
143
144 // protected
145
146 int clifford::compare_same_type(basic const & other) const
147 {
148     ASSERT(other.tinfo() == TINFO_CLIFFORD);
149     const clifford *o = static_cast<const clifford *>(&other);
150     if (serial==o->serial) {
151         return indexed::compare_same_type(other);
152     }
153     return serial < o->serial ? -1 : 1;
154 }
155
156 ex clifford::simplify_ncmul(exvector const & v) const
157 {
158     return simplified_ncmul(v);
159 }
160
161 unsigned clifford::calchash(void) const
162 {
163     hashvalue=golden_ratio_hash(golden_ratio_hash(0x55555556U ^
164                                                   golden_ratio_hash(tinfo_key) ^
165                                                   serial));
166     setflag(status_flags::hash_calculated);
167     return hashvalue;
168 }
169
170 //////////
171 // virtual functions which can be overridden by derived classes
172 //////////
173
174 // none
175
176 //////////
177 // non-virtual functions in this class
178 //////////
179
180 void clifford::setname(string const & n)
181 {
182     name=n;
183 }
184
185 // private
186
187 string & clifford::autoname_prefix(void)
188 {
189     static string * s=new string("clifford");
190     return *s;
191 }
192
193 //////////
194 // static member variables
195 //////////
196
197 // private
198
199 unsigned clifford::next_serial=0;
200
201 //////////
202 // global constants
203 //////////
204
205 const clifford some_clifford;
206 type_info const & typeid_clifford=typeid(some_clifford);
207