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