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