3 * Implementation of GiNaC's color indices. */
6 * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
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.
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.
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
32 GINAC_IMPLEMENT_REGISTERED_CLASS(coloridx, idx)
35 // default constructor, destructor, copy constructor assignment operator and helpers
42 debugmsg("coloridx default constructor",LOGLEVEL_CONSTRUCT);
43 // serial is incremented in idx::idx()
44 name="color"+ToString(serial);
45 tinfo_key=TINFO_coloridx;
50 void coloridx::copy(const coloridx & other)
52 inherited::copy(other);
55 void coloridx::destroy(bool call_parent)
57 if (call_parent) inherited::destroy(call_parent);
66 /** Construct symbolic color index, using an automatically generated unique name.
68 * @param cov Index is covariant (contravariant otherwise)
69 * @return newly constructed index */
70 coloridx::coloridx(bool cov) : idx(cov)
72 debugmsg("coloridx constructor from bool",LOGLEVEL_CONSTRUCT);
73 // serial is incremented in idx::idx(bool)
74 name="color"+ToString(serial);
75 tinfo_key=TINFO_coloridx;
78 /** Construct symbolic color index with specified name.
80 * @param n Symbolic index name
81 * @param cov Index is covariant (contravariant otherwise)
82 * @return newly constructed index */
83 coloridx::coloridx(const std::string & n, bool cov) : idx(n,cov)
85 debugmsg("coloridx constructor from string,bool",LOGLEVEL_CONSTRUCT);
86 tinfo_key=TINFO_coloridx;
89 /** Construct symbolic color index with specified name.
91 * @param n Symbolic index name
92 * @param cov Index is covariant (contravariant otherwise)
93 * @return newly constructed index */
94 coloridx::coloridx(const char * n, bool cov) : idx(n,cov)
96 debugmsg("coloridx constructor from char*,bool",LOGLEVEL_CONSTRUCT);
97 tinfo_key=TINFO_coloridx;
100 /** Construct numeric color index with specified value.
102 * @param v Numeric index value
103 * @param cov Index is covariant (contravariant otherwise)
104 * @return newly constructed index */
105 coloridx::coloridx(unsigned v, bool cov) : idx(v,cov)
107 debugmsg("coloridx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT);
108 tinfo_key=TINFO_coloridx;
115 /** Construct object from archive_node. */
116 coloridx::coloridx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
118 debugmsg("coloridx constructor from archive_node", LOGLEVEL_CONSTRUCT);
121 /** Unarchive the object. */
122 ex coloridx::unarchive(const archive_node &n, const lst &sym_lst)
124 return (new coloridx(n, sym_lst))->setflag(status_flags::dynallocated);
127 /** Archive the object. */
128 void coloridx::archive(archive_node &n) const
130 inherited::archive(n);
134 // functions overriding virtual functions from bases classes
139 void coloridx::printraw(std::ostream & os) const
141 debugmsg("coloridx printraw",LOGLEVEL_PRINT);
146 os << "symbolic,name=" << name;
148 os << "non symbolic,value=" << value;
154 os << ",contravariant";
157 os << ",serial=" << serial;
158 os << ",hash=" << hashvalue << ",flags=" << flags;
162 void coloridx::printtree(std::ostream & os, unsigned indent) const
164 debugmsg("coloridx printtree",LOGLEVEL_PRINT);
166 os << std::string(indent,' ') << "coloridx: ";
169 os << "symbolic,name=" << name;
171 os << "non symbolic,value=" << value;
177 os << ",contravariant";
180 os << ", serial=" << serial
181 << ", hash=" << hashvalue
182 << " (0x" << std::hex << hashvalue << std::dec << ")"
183 << ", flags=" << flags << std::endl;
186 void coloridx::print(std::ostream & os, unsigned upper_precedence) const
188 debugmsg("coloridx print",LOGLEVEL_PRINT);
202 bool coloridx::info(unsigned inf) const
204 if (inf==info_flags::coloridx) return true;
205 return idx::info(inf);
208 int coloridx::compare_same_type(const basic & other) const
210 return inherited::compare_same_type(other);