]> www.ginac.de Git - ginac.git/blob - ginac/lorentzidx.cpp
02611668313b23a7ad7ed733b18c19dc9eda2701
[ginac.git] / ginac / lorentzidx.cpp
1 /** @file lorentzidx.cpp
2  *
3  *  Implementation of GiNaC's lorentz indices.
4  *
5  *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <stdexcept>
23
24 #include "lorentzidx.h"
25 #include "utils.h"
26
27 //////////
28 // default constructor, destructor, copy constructor assignment operator and helpers
29 //////////
30
31 // public
32
33 lorentzidx::lorentzidx() : orthogonal_only(false), dim_parallel_space(0)
34 {
35     debugmsg("lorentzidx default constructor",LOGLEVEL_CONSTRUCT);
36     // serial is incremented in idx::idx()
37     name="mu"+ToString(serial);
38     tinfo_key=TINFO_lorentzidx;
39 }
40
41 lorentzidx::~lorentzidx() 
42 {
43     debugmsg("lorentzidx destructor",LOGLEVEL_DESTRUCT);
44     destroy(0);
45 }
46
47 lorentzidx::lorentzidx(lorentzidx const & other)
48 {
49     debugmsg("lorentzidx copy constructor",LOGLEVEL_CONSTRUCT);
50     copy(other);
51 }
52
53 lorentzidx const & lorentzidx::operator=(lorentzidx const & other)
54 {
55     debugmsg("lorentzidx operator=",LOGLEVEL_ASSIGNMENT);
56     if (this != &other) {
57         destroy(1);
58         copy(other);
59     }
60     return *this;
61 }
62
63 // protected
64
65 void lorentzidx::copy(lorentzidx const & other)
66 {
67     idx::copy(other);
68     orthogonal_only=other.orthogonal_only;
69     dim_parallel_space=other.dim_parallel_space;
70 }
71
72 void lorentzidx::destroy(bool call_parent)
73 {
74     if (call_parent) idx::destroy(call_parent);
75 }
76
77 //////////
78 // other constructors
79 //////////
80
81 // public
82
83 lorentzidx::lorentzidx(bool cov, bool oonly, unsigned dimp) :
84     idx(cov), orthogonal_only(oonly), dim_parallel_space(dimp)
85 {
86     debugmsg("lorentzidx constructor from bool",LOGLEVEL_CONSTRUCT);
87     // serial is incremented in idx::idx(bool)
88     if (oonly) {
89         name="muorth"+ToString(serial);
90     } else {
91         name="mu"+ToString(serial);
92     }
93     tinfo_key=TINFO_lorentzidx;
94 }
95
96 lorentzidx::lorentzidx(string const & n, bool cov, bool oonly, unsigned dimp)
97     : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
98 {
99     debugmsg("lorentzidx constructor from string,bool,bool,unsigned",
100              LOGLEVEL_CONSTRUCT);
101     tinfo_key=TINFO_lorentzidx;
102 }
103
104 lorentzidx::lorentzidx(char const * n, bool cov, bool oonly, unsigned dimp)
105     : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
106 {
107     debugmsg("lorentzidx constructor from char*,bool,bool,unsigned",
108              LOGLEVEL_CONSTRUCT);
109     tinfo_key=TINFO_lorentzidx;
110 }
111
112 lorentzidx::lorentzidx(unsigned const v, bool cov) : idx(v,cov),
113     orthogonal_only(false), dim_parallel_space(0)
114 {
115     debugmsg("lorentzidx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT);
116     tinfo_key=TINFO_lorentzidx;
117 }
118
119 //////////
120 // functions overriding virtual functions from bases classes
121 //////////
122
123 // public
124
125 basic * lorentzidx::duplicate() const
126 {
127     debugmsg("lorentzidx duplicate",LOGLEVEL_DUPLICATE);
128     return new lorentzidx(*this);
129 }
130
131 void lorentzidx::printraw(ostream & os) const
132 {
133     debugmsg("lorentzidx printraw",LOGLEVEL_PRINT);
134
135     os << "lorentzidx(";
136
137     if (symbolic) {
138         os << "symbolic,name=" << name;
139     } else {
140         os << "non symbolic,value=" << value;
141     }
142
143     if (covariant) {
144         os << ",covariant";
145     } else {
146         os << ",contravariant";
147     }
148
149     if (orthogonal_only) {
150         os << ",only orthogonal components at " << dim_parallel_space
151            << " parallel dimensions";
152     } else {
153         os << ",parallel and orthogonal components";
154     }
155
156     os << ",serial=" << serial;
157     os << ",hash=" << hashvalue << ",flags=" << flags;
158     os << ")";
159 }
160
161 void lorentzidx::printtree(ostream & os, unsigned indent) const
162 {
163     debugmsg("lorentzidx printtree",LOGLEVEL_PRINT);
164
165     os << string(indent,' ') << "lorentzidx: ";
166
167     if (symbolic) {
168         os << "symbolic,name=" << name;
169     } else {
170         os << "non symbolic,value=" << value;
171     }
172
173     if (covariant) {
174         os << ",covariant";
175     } else {
176         os << ",contravariant";
177     }
178
179     if (orthogonal_only) {
180         os << ",only orthogonal components at " << dim_parallel_space
181            << " parallel dimensions";
182     } else {
183         os << ",parallel and orthogonal components";
184     }
185
186     os << ", serial=" << serial
187        << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
188        << ", flags=" << flags << endl;
189 }
190
191 void lorentzidx::print(ostream & os, unsigned upper_precedence) const
192 {
193     debugmsg("lorentzidx print",LOGLEVEL_PRINT);
194
195     if (covariant) {
196         os << "_";
197     } else {
198         os << "~";
199     }
200     if (symbolic) {
201         os << name;
202     } else {
203         os << value;
204     }
205 }
206
207 bool lorentzidx::info(unsigned inf) const
208 {
209     if (inf==info_flags::lorentzidx) return true;
210     return idx::info(inf);
211 }
212
213 //////////
214 // new virtual functions which can be overridden by derived classes
215 //////////
216
217 // none
218
219 //////////
220 // non-virtual functions in this class
221 //////////
222
223 // public
224
225 lorentzidx lorentzidx::create_anonymous_representative(void) const
226 {
227     ASSERT(is_symbolic());
228     lorentzidx i_copy(*this);
229     i_copy.serial=0;
230     i_copy.name="anonymous_representative";
231     i_copy.covariant=false;
232     i_copy.clearflag(status_flags::dynallocated|
233                      status_flags::hash_calculated);
234     return i_copy;
235 }
236
237 //////////
238 // static member variables
239 //////////
240
241 // none
242
243 //////////
244 // global constants
245 //////////
246
247 const lorentzidx some_lorentzidx;
248 type_info const & typeid_lorentzidx=typeid(some_lorentzidx);
249
250
251