]> www.ginac.de Git - ginac.git/blob - ginac/coloridx.cpp
- enforced GiNaC coding standards :-)
[ginac.git] / ginac / coloridx.cpp
1 /** @file coloridx.cpp
2  *
3  *  Implementation of GiNaC's color indices.
4  *
5  *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <stdexcept>
23
24 #include "ginac.h"
25 #include "utils.h"
26
27 //////////
28 // default constructor, destructor, copy constructor assignment operator and helpers
29 //////////
30
31 // public
32
33 coloridx::coloridx()
34 {
35     debugmsg("coloridx default constructor",LOGLEVEL_CONSTRUCT);
36     // serial is incremented in idx::idx()
37     name="color"+ToString(serial);
38     tinfo_key=TINFO_COLORIDX;
39 }
40
41 coloridx::~coloridx() 
42 {
43     debugmsg("coloridx destructor",LOGLEVEL_DESTRUCT);
44     destroy(0);
45 }
46
47 coloridx::coloridx(coloridx const & other)
48 {
49     debugmsg("coloridx copy constructor",LOGLEVEL_CONSTRUCT);
50     copy(other);
51 }
52
53 coloridx const & coloridx::operator=(coloridx const & other)
54 {
55     debugmsg("coloridx operator=",LOGLEVEL_ASSIGNMENT);
56     if (this != &other) {
57         destroy(1);
58         copy(other);
59     }
60     return *this;
61 }
62
63 // protected
64
65 void coloridx::copy(coloridx const & other)
66 {
67     idx::copy(other);
68 }
69
70 void coloridx::destroy(bool call_parent)
71 {
72     if (call_parent) idx::destroy(call_parent);
73 }
74
75 //////////
76 // other constructors
77 //////////
78
79 // public
80
81 coloridx::coloridx(bool cov) : idx(cov)
82 {
83     debugmsg("coloridx constructor from bool",LOGLEVEL_CONSTRUCT);
84     // serial is incremented in idx::idx(bool)
85     name="color"+ToString(serial);
86     tinfo_key=TINFO_COLORIDX;
87 }
88
89 coloridx::coloridx(string const & n, bool cov) : idx(n,cov)
90 {
91     debugmsg("coloridx constructor from string,bool",LOGLEVEL_CONSTRUCT);
92     tinfo_key=TINFO_COLORIDX;
93 }
94
95 coloridx::coloridx(char const * n, bool cov) : idx(n,cov)
96 {
97     debugmsg("coloridx constructor from char*,bool",LOGLEVEL_CONSTRUCT);
98     tinfo_key=TINFO_COLORIDX;
99 }
100
101 coloridx::coloridx(unsigned const v, bool cov) : idx(v,cov)
102 {
103     debugmsg("coloridx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT);
104     tinfo_key=TINFO_COLORIDX;
105 }
106
107 //////////
108 // functions overriding virtual functions from bases classes
109 //////////
110
111 // public
112
113 basic * coloridx::duplicate() const
114 {
115     debugmsg("coloridx duplicate",LOGLEVEL_DUPLICATE);
116     return new coloridx(*this);
117 }
118
119 void coloridx::printraw(ostream & os) const
120 {
121     debugmsg("coloridx printraw",LOGLEVEL_PRINT);
122
123     os << "coloridx(";
124
125     if (symbolic) {
126         os << "symbolic,name=" << name;
127     } else {
128         os << "non symbolic,value=" << value;
129     }
130
131     if (covariant) {
132         os << ",covariant";
133     } else {
134         os << ",contravariant";
135     }
136
137     os << ",serial=" << serial;
138     os << ",hash=" << hashvalue << ",flags=" << flags;
139     os << ")";
140 }
141
142 void coloridx::printtree(ostream & os, unsigned indent) const
143 {
144     debugmsg("coloridx printtree",LOGLEVEL_PRINT);
145
146     os << string(indent,' ') << "coloridx: ";
147
148     if (symbolic) {
149         os << "symbolic,name=" << name;
150     } else {
151         os << "non symbolic,value=" << value;
152     }
153
154     if (covariant) {
155         os << ",covariant";
156     } else {
157         os << ",contravariant";
158     }
159
160     os << ", serial=" << serial
161        << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
162        << ", flags=" << flags << endl;
163 }
164
165 void coloridx::print(ostream & os, unsigned upper_precedence) const
166 {
167     debugmsg("coloridx print",LOGLEVEL_PRINT);
168
169     if (covariant) {
170         os << "_";
171     } else {
172         os << "~";
173     }
174     if (symbolic) {
175         os << name;
176     } else {
177         os << value;
178     }
179 }
180
181 bool coloridx::info(unsigned inf) const
182 {
183     if (inf==info_flags::coloridx) return true;
184     return idx::info(inf);
185 }
186
187 //////////
188 // new virtual functions which can be overridden by derived classes
189 //////////
190
191 // none
192
193 //////////
194 // non-virtual functions in this class
195 //////////
196
197 // none
198
199 //////////
200 // static member variables
201 //////////
202
203 // none
204
205 //////////
206 // global constants
207 //////////
208
209 const coloridx some_coloridx;
210 type_info const & typeid_coloridx=typeid(some_coloridx);
211
212
213