]> www.ginac.de Git - ginac.git/blob - ginac/lorentzidx.cpp
e53d8a859011d8cd7d11e6b59fc5ec96414f254d
[ginac.git] / ginac / lorentzidx.cpp
1 /** @file lorentzidx.cpp
2  *
3  *  Implementation of GiNaC's lorentz indices. */
4
5 #include <stdexcept>
6
7 #include "ginac.h"
8 #include "utils.h"
9
10 //////////
11 // default constructor, destructor, copy constructor assignment operator and helpers
12 //////////
13
14 // public
15
16 lorentzidx::lorentzidx() : orthogonal_only(false), dim_parallel_space(0)
17 {
18     debugmsg("lorentzidx default constructor",LOGLEVEL_CONSTRUCT);
19     // serial is incremented in idx::idx()
20     name="mu"+ToString(serial);
21     tinfo_key=TINFO_LORENTZIDX;
22 }
23
24 lorentzidx::~lorentzidx() 
25 {
26     debugmsg("lorentzidx destructor",LOGLEVEL_DESTRUCT);
27     destroy(0);
28 }
29
30 lorentzidx::lorentzidx(lorentzidx const & other)
31 {
32     debugmsg("lorentzidx copy constructor",LOGLEVEL_CONSTRUCT);
33     copy(other);
34 }
35
36 lorentzidx const & lorentzidx::operator=(lorentzidx const & other)
37 {
38     debugmsg("lorentzidx operator=",LOGLEVEL_ASSIGNMENT);
39     if (this != &other) {
40         destroy(1);
41         copy(other);
42     }
43     return *this;
44 }
45
46 // protected
47
48 void lorentzidx::copy(lorentzidx const & other)
49 {
50     idx::copy(other);
51     orthogonal_only=other.orthogonal_only;
52     dim_parallel_space=other.dim_parallel_space;
53 }
54
55 void lorentzidx::destroy(bool call_parent)
56 {
57     if (call_parent) idx::destroy(call_parent);
58 }
59
60 //////////
61 // other constructors
62 //////////
63
64 // public
65
66 lorentzidx::lorentzidx(bool cov, bool oonly, unsigned dimp) :
67     idx(cov), orthogonal_only(oonly), dim_parallel_space(dimp)
68 {
69     debugmsg("lorentzidx constructor from bool",LOGLEVEL_CONSTRUCT);
70     // serial is incremented in idx::idx(bool)
71     if (oonly) {
72         name="muorth"+ToString(serial);
73     } else {
74         name="mu"+ToString(serial);
75     }
76     tinfo_key=TINFO_LORENTZIDX;
77 }
78
79 lorentzidx::lorentzidx(string const & n, bool cov, bool oonly, unsigned dimp)
80     : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
81 {
82     debugmsg("lorentzidx constructor from string,bool,bool,unsigned",
83              LOGLEVEL_CONSTRUCT);
84     tinfo_key=TINFO_LORENTZIDX;
85 }
86
87 lorentzidx::lorentzidx(char const * n, bool cov, bool oonly, unsigned dimp)
88     : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
89 {
90     debugmsg("lorentzidx constructor from char*,bool,bool,unsigned",
91              LOGLEVEL_CONSTRUCT);
92     tinfo_key=TINFO_LORENTZIDX;
93 }
94
95 lorentzidx::lorentzidx(unsigned const v, bool cov) : idx(v,cov),
96     orthogonal_only(false), dim_parallel_space(0)
97 {
98     debugmsg("lorentzidx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT);
99     tinfo_key=TINFO_LORENTZIDX;
100 }
101
102 //////////
103 // functions overriding virtual functions from bases classes
104 //////////
105
106 // public
107
108 basic * lorentzidx::duplicate() const
109 {
110     debugmsg("lorentzidx duplicate",LOGLEVEL_DUPLICATE);
111     return new lorentzidx(*this);
112 }
113
114 void lorentzidx::printraw(ostream & os) const
115 {
116     debugmsg("lorentzidx printraw",LOGLEVEL_PRINT);
117
118     os << "lorentzidx(";
119
120     if (symbolic) {
121         os << "symbolic,name=" << name;
122     } else {
123         os << "non symbolic,value=" << value;
124     }
125
126     if (covariant) {
127         os << ",covariant";
128     } else {
129         os << ",contravariant";
130     }
131
132     if (orthogonal_only) {
133         os << ",only orthogonal components at " << dim_parallel_space
134            << " parallel dimensions";
135     } else {
136         os << ",parallel and orthogonal components";
137     }
138
139     os << ",serial=" << serial;
140     os << ",hash=" << hashvalue << ",flags=" << flags;
141     os << ")";
142 }
143
144 void lorentzidx::printtree(ostream & os, unsigned indent) const
145 {
146     debugmsg("lorentzidx printtree",LOGLEVEL_PRINT);
147
148     os << string(indent,' ') << "lorentzidx: ";
149
150     if (symbolic) {
151         os << "symbolic,name=" << name;
152     } else {
153         os << "non symbolic,value=" << value;
154     }
155
156     if (covariant) {
157         os << ",covariant";
158     } else {
159         os << ",contravariant";
160     }
161
162     if (orthogonal_only) {
163         os << ",only orthogonal components at " << dim_parallel_space
164            << " parallel dimensions";
165     } else {
166         os << ",parallel and orthogonal components";
167     }
168
169     os << ", serial=" << serial
170        << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
171        << ", flags=" << flags << endl;
172 }
173
174 void lorentzidx::print(ostream & os, unsigned upper_precedence) const
175 {
176     debugmsg("lorentzidx print",LOGLEVEL_PRINT);
177
178     if (covariant) {
179         os << "_";
180     } else {
181         os << "~";
182     }
183     if (symbolic) {
184         os << name;
185     } else {
186         os << value;
187     }
188 }
189
190 bool lorentzidx::info(unsigned inf) const
191 {
192     if (inf==info_flags::lorentzidx) return true;
193     return idx::info(inf);
194 }
195
196 //////////
197 // new virtual functions which can be overridden by derived classes
198 //////////
199
200 // none
201
202 //////////
203 // non-virtual functions in this class
204 //////////
205
206 // public
207
208 lorentzidx lorentzidx::create_anonymous_representative(void) const
209 {
210     ASSERT(is_symbolic());
211     lorentzidx i_copy(*this);
212     i_copy.serial=0;
213     i_copy.name="anonymous_representative";
214     i_copy.covariant=false;
215     i_copy.clearflag(status_flags::dynallocated|
216                      status_flags::hash_calculated);
217     return i_copy;
218 }
219
220 //////////
221 // static member variables
222 //////////
223
224 // none
225
226 //////////
227 // global constants
228 //////////
229
230 const lorentzidx some_lorentzidx;
231 type_info const & typeid_lorentzidx=typeid(some_lorentzidx);
232
233
234