]> www.ginac.de Git - ginac.git/blob - ginac/lorentzidx.cpp
- Inserted some more std:: to make it compile under GCC2.96.
[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 "lst.h"
27 #include "archive.h"
28 #include "utils.h"
29 #include "debugmsg.h"
30
31 #ifndef NO_NAMESPACE_GINAC
32 namespace GiNaC {
33 #endif // ndef NO_NAMESPACE_GINAC
34
35 GINAC_IMPLEMENT_REGISTERED_CLASS(lorentzidx, idx)
36
37 //////////
38 // default constructor, destructor, copy constructor assignment operator and helpers
39 //////////
40
41 // public
42
43 lorentzidx::lorentzidx() : orthogonal_only(false), dim_parallel_space(0)
44 {
45         debugmsg("lorentzidx default constructor",LOGLEVEL_CONSTRUCT);
46         // serial is incremented in idx::idx()
47         name = "mu" + ToString(serial);
48         tinfo_key = TINFO_lorentzidx;
49 }
50
51 lorentzidx::~lorentzidx() 
52 {
53         debugmsg("lorentzidx destructor",LOGLEVEL_DESTRUCT);
54         destroy(false);
55 }
56
57 lorentzidx::lorentzidx(const lorentzidx & other)
58 {
59         debugmsg("lorentzidx copy constructor",LOGLEVEL_CONSTRUCT);
60         copy(other);
61 }
62
63 const lorentzidx & lorentzidx::operator=(const lorentzidx & other)
64 {
65         debugmsg("lorentzidx operator=",LOGLEVEL_ASSIGNMENT);
66         if (this != &other) {
67                 destroy(true);
68                 copy(other);
69         }
70         return *this;
71 }
72
73 // protected
74
75 void lorentzidx::copy(const lorentzidx & other)
76 {
77         inherited::copy(other);
78         orthogonal_only=other.orthogonal_only;
79         dim_parallel_space=other.dim_parallel_space;
80 }
81
82 void lorentzidx::destroy(bool call_parent)
83 {
84         if (call_parent) inherited::destroy(call_parent);
85 }
86
87 //////////
88 // other constructors
89 //////////
90
91 // public
92
93 lorentzidx::lorentzidx(bool cov, bool oonly, unsigned dimp)
94   : idx(cov), orthogonal_only(oonly), dim_parallel_space(dimp)
95 {
96         debugmsg("lorentzidx constructor from bool",LOGLEVEL_CONSTRUCT);
97         // serial is incremented in idx::idx(bool)
98         if (oonly) {
99                 name="muorth"+ToString(serial);
100         } else {
101                 name="mu"+ToString(serial);
102         }
103         tinfo_key=TINFO_lorentzidx;
104 }
105
106 lorentzidx::lorentzidx(const std::string & n, bool cov, bool oonly, unsigned dimp)
107   : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
108 {
109         debugmsg("lorentzidx constructor from string,bool,bool,unsigned",
110                          LOGLEVEL_CONSTRUCT);
111         tinfo_key=TINFO_lorentzidx;
112 }
113
114 lorentzidx::lorentzidx(const char * n, bool cov, bool oonly, unsigned dimp)
115   : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
116 {
117         debugmsg("lorentzidx constructor from char*,bool,bool,unsigned",
118                          LOGLEVEL_CONSTRUCT);
119         tinfo_key=TINFO_lorentzidx;
120 }
121
122 lorentzidx::lorentzidx(unsigned v, bool cov)
123   : idx(v,cov), orthogonal_only(false), dim_parallel_space(0)
124 {
125         debugmsg("lorentzidx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT);
126         tinfo_key=TINFO_lorentzidx;
127 }
128
129 //////////
130 // archiving
131 //////////
132
133 /** Construct object from archive_node. */
134 lorentzidx::lorentzidx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
135 {
136         debugmsg("lorentzidx constructor from archive_node", LOGLEVEL_CONSTRUCT);
137         n.find_bool("orthogonal_only", orthogonal_only);
138         if (orthogonal_only)
139                 n.find_unsigned("pdim", dim_parallel_space);
140 }
141
142 /** Unarchive the object. */
143 ex lorentzidx::unarchive(const archive_node &n, const lst &sym_lst)
144 {
145         ex s = (new lorentzidx(n, sym_lst))->setflag(status_flags::dynallocated);
146
147         if (ex_to_lorentzidx(s).symbolic) {
148                 // If lorentzidx is in sym_lst, return the existing lorentzidx
149                 for (unsigned i=0; i<sym_lst.nops(); i++) {
150                         if (is_ex_of_type(sym_lst.op(i), lorentzidx) && (ex_to_lorentzidx(sym_lst.op(i)).name == ex_to_lorentzidx(s).name))
151                                 return sym_lst.op(i);
152                 }
153         }
154         return s;
155 }
156
157 /** Archive the object. */
158 void lorentzidx::archive(archive_node &n) const
159 {
160         inherited::archive(n);
161         n.add_bool("orthogonal_only", orthogonal_only);
162         if (orthogonal_only)
163                 n.add_unsigned("pdim", dim_parallel_space);
164 }
165
166 //////////
167 // functions overriding virtual functions from bases classes
168 //////////
169
170 // public
171
172 basic * lorentzidx::duplicate() const
173 {
174         debugmsg("lorentzidx duplicate",LOGLEVEL_DUPLICATE);
175         return new lorentzidx(*this);
176 }
177
178 void lorentzidx::printraw(std::ostream & os) const
179 {
180         debugmsg("lorentzidx printraw",LOGLEVEL_PRINT);
181
182         os << "lorentzidx(";
183
184         if (symbolic) {
185                 os << "symbolic,name=" << name;
186         } else {
187                 os << "non symbolic,value=" << value;
188         }
189
190         if (covariant) {
191                 os << ",covariant";
192         } else {
193                 os << ",contravariant";
194         }
195
196         if (orthogonal_only) {
197                 os << ",only orthogonal components at " << dim_parallel_space
198                    << " parallel dimensions";
199         } else {
200                 os << ",parallel and orthogonal components";
201         }
202
203         os << ",serial=" << serial;
204         os << ",hash=" << hashvalue << ",flags=" << flags;
205         os << ")";
206 }
207
208 void lorentzidx::printtree(std::ostream & os, unsigned indent) const
209 {
210         debugmsg("lorentzidx printtree",LOGLEVEL_PRINT);
211
212         os << std::string(indent,' ') << "lorentzidx: ";
213
214         if (symbolic) {
215                 os << "symbolic,name=" << name;
216         } else {
217                 os << "non symbolic,value=" << value;
218         }
219
220         if (covariant) {
221                 os << ",covariant";
222         } else {
223                 os << ",contravariant";
224         }
225
226         if (orthogonal_only) {
227                 os << ",only orthogonal components at " << dim_parallel_space
228                    << " parallel dimensions";
229         } else {
230                 os << ",parallel and orthogonal components";
231         }
232
233         os << ", serial=" << serial
234            << ", hash=" << hashvalue
235            << " (0x" << std::hex << hashvalue << std::dec << ")"
236            << ", flags=" << flags << std::endl;
237 }
238
239 void lorentzidx::print(std::ostream & os, unsigned upper_precedence) const
240 {
241         debugmsg("lorentzidx print",LOGLEVEL_PRINT);
242
243         if (covariant) {
244                 os << "_";
245         } else {
246                 os << "~";
247         }
248         if (symbolic) {
249                 os << name;
250         } else {
251                 os << value;
252         }
253 }
254
255 bool lorentzidx::info(unsigned inf) const
256 {
257         if (inf==info_flags::lorentzidx) return true;
258         return inherited::info(inf);
259 }
260
261 //////////
262 // new virtual functions which can be overridden by derived classes
263 //////////
264
265 // none
266
267 //////////
268 // non-virtual functions in this class
269 //////////
270
271 // public
272
273 lorentzidx lorentzidx::create_anonymous_representative(void) const
274 {
275         GINAC_ASSERT(is_symbolic());
276         lorentzidx i_copy(*this);
277         i_copy.serial=0;
278         i_copy.name="anonymous_representative";
279         i_copy.covariant=false;
280         i_copy.clearflag(status_flags::dynallocated |
281                          status_flags::hash_calculated);
282         return i_copy;
283 }
284
285 //////////
286 // static member variables
287 //////////
288
289 // none
290
291 //////////
292 // global constants
293 //////////
294
295 const lorentzidx some_lorentzidx;
296 const std::type_info & typeid_lorentzidx = typeid(some_lorentzidx);
297
298 #ifndef NO_NAMESPACE_GINAC
299 } // namespace GiNaC
300 #endif // ndef NO_NAMESPACE_GINAC