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