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
30 #ifndef NO_NAMESPACE_GINAC
32 #endif // ndef NO_NAMESPACE_GINAC
34 GINAC_IMPLEMENT_REGISTERED_CLASS(coloridx, idx)
37 // default constructor, destructor, copy constructor assignment operator and helpers
44 debugmsg("coloridx default constructor",LOGLEVEL_CONSTRUCT);
45 // serial is incremented in idx::idx()
46 name="color"+ToString(serial);
47 tinfo_key=TINFO_coloridx;
52 void coloridx::copy(const coloridx & other)
54 inherited::copy(other);
57 void coloridx::destroy(bool call_parent)
59 if (call_parent) inherited::destroy(call_parent);
68 /** Construct symbolic color index, using an automatically generated unique name.
70 * @param cov Index is covariant (contravariant otherwise)
71 * @return newly constructed index */
72 coloridx::coloridx(bool cov) : idx(cov)
74 debugmsg("coloridx constructor from bool",LOGLEVEL_CONSTRUCT);
75 // serial is incremented in idx::idx(bool)
76 name="color"+ToString(serial);
77 tinfo_key=TINFO_coloridx;
80 /** Construct symbolic color index with specified name.
82 * @param n Symbolic index name
83 * @param cov Index is covariant (contravariant otherwise)
84 * @return newly constructed index */
85 coloridx::coloridx(const std::string & n, bool cov) : idx(n,cov)
87 debugmsg("coloridx constructor from string,bool",LOGLEVEL_CONSTRUCT);
88 tinfo_key=TINFO_coloridx;
91 /** Construct symbolic color index with specified name.
93 * @param n Symbolic index name
94 * @param cov Index is covariant (contravariant otherwise)
95 * @return newly constructed index */
96 coloridx::coloridx(const char * n, bool cov) : idx(n,cov)
98 debugmsg("coloridx constructor from char*,bool",LOGLEVEL_CONSTRUCT);
99 tinfo_key=TINFO_coloridx;
102 /** Construct numeric color index with specified value.
104 * @param v Numeric index value
105 * @param cov Index is covariant (contravariant otherwise)
106 * @return newly constructed index */
107 coloridx::coloridx(unsigned v, bool cov) : idx(v,cov)
109 debugmsg("coloridx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT);
110 tinfo_key=TINFO_coloridx;
117 /** Construct object from archive_node. */
118 coloridx::coloridx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
120 debugmsg("coloridx constructor from archive_node", LOGLEVEL_CONSTRUCT);
123 /** Unarchive the object. */
124 ex coloridx::unarchive(const archive_node &n, const lst &sym_lst)
126 return (new coloridx(n, sym_lst))->setflag(status_flags::dynallocated);
129 /** Archive the object. */
130 void coloridx::archive(archive_node &n) const
132 inherited::archive(n);
136 // functions overriding virtual functions from bases classes
141 basic * coloridx::duplicate() const
143 debugmsg("coloridx duplicate",LOGLEVEL_DUPLICATE);
144 return new coloridx(*this);
147 void coloridx::printraw(std::ostream & os) const
149 debugmsg("coloridx printraw",LOGLEVEL_PRINT);
154 os << "symbolic,name=" << name;
156 os << "non symbolic,value=" << value;
162 os << ",contravariant";
165 os << ",serial=" << serial;
166 os << ",hash=" << hashvalue << ",flags=" << flags;
170 void coloridx::printtree(std::ostream & os, unsigned indent) const
172 debugmsg("coloridx printtree",LOGLEVEL_PRINT);
174 os << std::string(indent,' ') << "coloridx: ";
177 os << "symbolic,name=" << name;
179 os << "non symbolic,value=" << value;
185 os << ",contravariant";
188 os << ", serial=" << serial
189 << ", hash=" << hashvalue
190 << " (0x" << std::hex << hashvalue << std::dec << ")"
191 << ", flags=" << flags << std::endl;
194 void coloridx::print(std::ostream & os, unsigned upper_precedence) const
196 debugmsg("coloridx print",LOGLEVEL_PRINT);
210 bool coloridx::info(unsigned inf) const
212 if (inf==info_flags::coloridx) return true;
213 return idx::info(inf);
216 #ifndef NO_NAMESPACE_GINAC
218 #endif // ndef NO_NAMESPACE_GINAC