- switched to automake build environment
[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 #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 clifford::clifford()
18 {
19     debugmsg("clifford default constructor",LOGLEVEL_CONSTRUCT);
20     serial=next_serial++;
21     name=autoname_prefix()+ToString(serial);
22     tinfo_key=TINFO_CLIFFORD;
23 }
24
25 clifford::~clifford()
26 {
27     debugmsg("clifford destructor",LOGLEVEL_DESTRUCT);
28     destroy(0);
29 }
30
31 clifford::clifford(clifford const & other)
32 {
33     debugmsg("clifford copy constructor",LOGLEVEL_CONSTRUCT);
34     copy (other);
35 }
36
37 clifford const & clifford::operator=(clifford const & other)
38 {
39     debugmsg("clifford operator=",LOGLEVEL_ASSIGNMENT);
40     if (this != &other) {
41         destroy(1);
42         copy(other);
43     }
44     return *this;
45 }
46
47 // protected
48
49 void clifford::copy(clifford const & other)
50 {
51     indexed::copy(other);
52     name=other.name;
53     serial=other.serial;
54 }
55
56 void clifford::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 clifford::clifford(string const & initname)
70 {
71     debugmsg("clifford constructor from string",LOGLEVEL_CONSTRUCT);
72     name=initname;
73     serial=next_serial++;
74     tinfo_key=TINFO_CLIFFORD;
75 }
76
77 //////////
78 // functions overriding virtual functions from bases classes
79 //////////
80
81 // public
82
83 basic * clifford::duplicate() const
84 {
85     debugmsg("clifford duplicate",LOGLEVEL_DUPLICATE);
86     return new clifford(*this);
87 }
88
89 void clifford::printraw(ostream & os) const
90 {
91     debugmsg("clifford printraw",LOGLEVEL_PRINT);
92     os << "clifford(" << "name=" << name << ",serial=" << serial
93        << ",indices=";
94     printrawindices(os);
95     os << ",hash=" << hashvalue << ",flags=" << flags << ")";
96 }
97
98 void clifford::printtree(ostream & os, unsigned indent) const
99 {
100     debugmsg("clifford printtree",LOGLEVEL_PRINT);
101     os << string(indent,' ') << name << " (clifford): "
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 clifford::print(ostream & os, unsigned upper_precedence) const
110 {
111     debugmsg("clifford print",LOGLEVEL_PRINT);
112     os << name;
113     printindices(os);
114 }
115
116 void clifford::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) const
117 {
118     debugmsg("clifford print csrc",LOGLEVEL_PRINT);
119     print(os,upper_precedence);
120 }
121
122 bool clifford::info(unsigned inf) const
123 {
124     return indexed::info(inf);
125 }
126
127 // protected
128
129 int clifford::compare_same_type(basic const & other) const
130 {
131     ASSERT(other.tinfo() == TINFO_CLIFFORD);
132     const clifford *o = static_cast<const clifford *>(&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 clifford::simplify_ncmul(exvector const & v) const
140 {
141     return simplified_ncmul(v);
142 }
143
144 unsigned clifford::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 clifford::setname(string const & n)
164 {
165     name=n;
166 }
167
168 // private
169
170 string & clifford::autoname_prefix(void)
171 {
172     static string * s=new string("clifford");
173     return *s;
174 }
175
176 //////////
177 // static member variables
178 //////////
179
180 // private
181
182 unsigned clifford::next_serial=0;
183
184 //////////
185 // global constants
186 //////////
187
188 const clifford some_clifford;
189 type_info const & typeid_clifford=typeid(some_clifford);
190