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