1 /** @file lorentzidx.cpp
3 * Implementation of GiNaC's lorentz indices. */
6 * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
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.
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.
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
25 #include "lorentzidx.h"
31 #ifndef NO_NAMESPACE_GINAC
33 #endif // ndef NO_NAMESPACE_GINAC
35 GINAC_IMPLEMENT_REGISTERED_CLASS(lorentzidx, idx)
38 // default constructor, destructor, copy constructor assignment operator and helpers
43 lorentzidx::lorentzidx() : orthogonal_only(false), dim_parallel_space(0)
45 debugmsg("lorentzidx default constructor",LOGLEVEL_CONSTRUCT);
46 // serial is incremented in idx::idx()
47 name="mu"+ToString(serial);
48 tinfo_key=TINFO_lorentzidx;
51 lorentzidx::~lorentzidx()
53 debugmsg("lorentzidx destructor",LOGLEVEL_DESTRUCT);
57 lorentzidx::lorentzidx(const lorentzidx & other)
59 debugmsg("lorentzidx copy constructor",LOGLEVEL_CONSTRUCT);
63 const lorentzidx & lorentzidx::operator=(const lorentzidx & other)
65 debugmsg("lorentzidx operator=",LOGLEVEL_ASSIGNMENT);
75 void lorentzidx::copy(const lorentzidx & other)
77 inherited::copy(other);
78 orthogonal_only=other.orthogonal_only;
79 dim_parallel_space=other.dim_parallel_space;
82 void lorentzidx::destroy(bool call_parent)
84 if (call_parent) inherited::destroy(call_parent);
93 lorentzidx::lorentzidx(bool cov, bool oonly, unsigned dimp) :
94 idx(cov), orthogonal_only(oonly), dim_parallel_space(dimp)
96 debugmsg("lorentzidx constructor from bool",LOGLEVEL_CONSTRUCT);
97 // serial is incremented in idx::idx(bool)
99 name="muorth"+ToString(serial);
101 name="mu"+ToString(serial);
103 tinfo_key=TINFO_lorentzidx;
106 lorentzidx::lorentzidx(const std::string & n, bool cov, bool oonly, unsigned dimp)
107 : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
109 debugmsg("lorentzidx constructor from string,bool,bool,unsigned",
111 tinfo_key=TINFO_lorentzidx;
114 lorentzidx::lorentzidx(const char * n, bool cov, bool oonly, unsigned dimp)
115 : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
117 debugmsg("lorentzidx constructor from char*,bool,bool,unsigned",
119 tinfo_key=TINFO_lorentzidx;
122 lorentzidx::lorentzidx(unsigned v, bool cov) : idx(v,cov),
123 orthogonal_only(false), dim_parallel_space(0)
125 debugmsg("lorentzidx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT);
126 tinfo_key=TINFO_lorentzidx;
133 /** Construct object from archive_node. */
134 lorentzidx::lorentzidx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
136 debugmsg("lorentzidx constructor from archive_node", LOGLEVEL_CONSTRUCT);
137 n.find_bool("orthogonal_only", orthogonal_only);
139 n.find_unsigned("pdim", dim_parallel_space);
142 /** Unarchive the object. */
143 ex lorentzidx::unarchive(const archive_node &n, const lst &sym_lst)
145 ex s = (new lorentzidx(n, sym_lst))->setflag(status_flags::dynallocated);
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);
157 /** Archive the object. */
158 void lorentzidx::archive(archive_node &n) const
160 inherited::archive(n);
161 n.add_bool("orthogonal_only", orthogonal_only);
163 n.add_unsigned("pdim", dim_parallel_space);
167 // functions overriding virtual functions from bases classes
172 basic * lorentzidx::duplicate() const
174 debugmsg("lorentzidx duplicate",LOGLEVEL_DUPLICATE);
175 return new lorentzidx(*this);
178 void lorentzidx::printraw(std::ostream & os) const
180 debugmsg("lorentzidx printraw",LOGLEVEL_PRINT);
185 os << "symbolic,name=" << name;
187 os << "non symbolic,value=" << value;
193 os << ",contravariant";
196 if (orthogonal_only) {
197 os << ",only orthogonal components at " << dim_parallel_space
198 << " parallel dimensions";
200 os << ",parallel and orthogonal components";
203 os << ",serial=" << serial;
204 os << ",hash=" << hashvalue << ",flags=" << flags;
208 void lorentzidx::printtree(std::ostream & os, unsigned indent) const
210 debugmsg("lorentzidx printtree",LOGLEVEL_PRINT);
212 os << std::string(indent,' ') << "lorentzidx: ";
215 os << "symbolic,name=" << name;
217 os << "non symbolic,value=" << value;
223 os << ",contravariant";
226 if (orthogonal_only) {
227 os << ",only orthogonal components at " << dim_parallel_space
228 << " parallel dimensions";
230 os << ",parallel and orthogonal components";
233 os << ", serial=" << serial
234 << ", hash=" << hashvalue
235 << " (0x" << std::hex << hashvalue << std::dec << ")"
236 << ", flags=" << flags << std::endl;
239 void lorentzidx::print(std::ostream & os, unsigned upper_precedence) const
241 debugmsg("lorentzidx print",LOGLEVEL_PRINT);
255 bool lorentzidx::info(unsigned inf) const
257 if (inf==info_flags::lorentzidx) return true;
258 return inherited::info(inf);
262 // new virtual functions which can be overridden by derived classes
268 // non-virtual functions in this class
273 lorentzidx lorentzidx::create_anonymous_representative(void) const
275 GINAC_ASSERT(is_symbolic());
276 lorentzidx i_copy(*this);
278 i_copy.name="anonymous_representative";
279 i_copy.covariant=false;
280 i_copy.clearflag(status_flags::dynallocated|
281 status_flags::hash_calculated);
286 // static member variables
295 const lorentzidx some_lorentzidx;
296 const type_info & typeid_lorentzidx=typeid(some_lorentzidx);
298 #ifndef NO_NAMESPACE_GINAC
300 #endif // ndef NO_NAMESPACE_GINAC