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