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