]> www.ginac.de Git - ginac.git/blob - ginac/coloridx.cpp
- files which are generated by perl scripts are made before compilation
[ginac.git] / ginac / coloridx.cpp
1 /** @file coloridx.cpp
2  *
3  *  Implementation of GiNaC's color indices. */
4
5 /*
6  *  GiNaC Copyright (C) 1999 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 "utils.h"
27 #include "debugmsg.h"
28
29 namespace GiNaC {
30
31 //////////
32 // default constructor, destructor, copy constructor assignment operator and helpers
33 //////////
34
35 // public
36
37 coloridx::coloridx()
38 {
39     debugmsg("coloridx default constructor",LOGLEVEL_CONSTRUCT);
40     // serial is incremented in idx::idx()
41     name="color"+ToString(serial);
42     tinfo_key=TINFO_coloridx;
43 }
44
45 coloridx::~coloridx() 
46 {
47     debugmsg("coloridx destructor",LOGLEVEL_DESTRUCT);
48     destroy(0);
49 }
50
51 coloridx::coloridx(coloridx const & other)
52 {
53     debugmsg("coloridx copy constructor",LOGLEVEL_CONSTRUCT);
54     copy(other);
55 }
56
57 coloridx const & coloridx::operator=(coloridx const & other)
58 {
59     debugmsg("coloridx operator=",LOGLEVEL_ASSIGNMENT);
60     if (this != &other) {
61         destroy(1);
62         copy(other);
63     }
64     return *this;
65 }
66
67 // protected
68
69 void coloridx::copy(coloridx const & other)
70 {
71     idx::copy(other);
72 }
73
74 void coloridx::destroy(bool call_parent)
75 {
76     if (call_parent) idx::destroy(call_parent);
77 }
78
79 //////////
80 // other constructors
81 //////////
82
83 // public
84
85 coloridx::coloridx(bool cov) : idx(cov)
86 {
87     debugmsg("coloridx constructor from bool",LOGLEVEL_CONSTRUCT);
88     // serial is incremented in idx::idx(bool)
89     name="color"+ToString(serial);
90     tinfo_key=TINFO_coloridx;
91 }
92
93 coloridx::coloridx(string const & n, bool cov) : idx(n,cov)
94 {
95     debugmsg("coloridx constructor from string,bool",LOGLEVEL_CONSTRUCT);
96     tinfo_key=TINFO_coloridx;
97 }
98
99 coloridx::coloridx(char const * n, bool cov) : idx(n,cov)
100 {
101     debugmsg("coloridx constructor from char*,bool",LOGLEVEL_CONSTRUCT);
102     tinfo_key=TINFO_coloridx;
103 }
104
105 coloridx::coloridx(unsigned const v, bool cov) : idx(v,cov)
106 {
107     debugmsg("coloridx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT);
108     tinfo_key=TINFO_coloridx;
109 }
110
111 //////////
112 // functions overriding virtual functions from bases classes
113 //////////
114
115 // public
116
117 basic * coloridx::duplicate() const
118 {
119     debugmsg("coloridx duplicate",LOGLEVEL_DUPLICATE);
120     return new coloridx(*this);
121 }
122
123 void coloridx::printraw(ostream & os) const
124 {
125     debugmsg("coloridx printraw",LOGLEVEL_PRINT);
126
127     os << "coloridx(";
128
129     if (symbolic) {
130         os << "symbolic,name=" << name;
131     } else {
132         os << "non symbolic,value=" << value;
133     }
134
135     if (covariant) {
136         os << ",covariant";
137     } else {
138         os << ",contravariant";
139     }
140
141     os << ",serial=" << serial;
142     os << ",hash=" << hashvalue << ",flags=" << flags;
143     os << ")";
144 }
145
146 void coloridx::printtree(ostream & os, unsigned indent) const
147 {
148     debugmsg("coloridx printtree",LOGLEVEL_PRINT);
149
150     os << string(indent,' ') << "coloridx: ";
151
152     if (symbolic) {
153         os << "symbolic,name=" << name;
154     } else {
155         os << "non symbolic,value=" << value;
156     }
157
158     if (covariant) {
159         os << ",covariant";
160     } else {
161         os << ",contravariant";
162     }
163
164     os << ", serial=" << serial
165        << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
166        << ", flags=" << flags << endl;
167 }
168
169 void coloridx::print(ostream & os, unsigned upper_precedence) const
170 {
171     debugmsg("coloridx print",LOGLEVEL_PRINT);
172
173     if (covariant) {
174         os << "_";
175     } else {
176         os << "~";
177     }
178     if (symbolic) {
179         os << name;
180     } else {
181         os << value;
182     }
183 }
184
185 bool coloridx::info(unsigned inf) const
186 {
187     if (inf==info_flags::coloridx) return true;
188     return idx::info(inf);
189 }
190
191 //////////
192 // new virtual functions which can be overridden by derived classes
193 //////////
194
195 // none
196
197 //////////
198 // non-virtual functions in this class
199 //////////
200
201 // none
202
203 //////////
204 // static member variables
205 //////////
206
207 // none
208
209 //////////
210 // global constants
211 //////////
212
213 const coloridx some_coloridx;
214 type_info const & typeid_coloridx=typeid(some_coloridx);
215
216 } // namespace GiNaC