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