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 debugmsg("coloridx destructor",LOGLEVEL_DESTRUCT);
56 coloridx::coloridx(const coloridx & other)
58 debugmsg("coloridx copy constructor",LOGLEVEL_CONSTRUCT);
62 const coloridx & coloridx::operator=(const coloridx & other)
64 debugmsg("coloridx operator=",LOGLEVEL_ASSIGNMENT);
74 void coloridx::copy(const coloridx & other)
76 inherited::copy(other);
79 void coloridx::destroy(bool call_parent)
81 if (call_parent) inherited::destroy(call_parent);
90 /** Construct symbolic color index, using an automatically generated unique name.
92 * @param cov Index is covariant (contravariant otherwise)
93 * @return newly constructed index */
94 coloridx::coloridx(bool cov) : idx(cov)
96 debugmsg("coloridx constructor from bool",LOGLEVEL_CONSTRUCT);
97 // serial is incremented in idx::idx(bool)
98 name="color"+ToString(serial);
99 tinfo_key=TINFO_coloridx;
102 /** Construct symbolic color index with specified name.
104 * @param n Symbolic index name
105 * @param cov Index is covariant (contravariant otherwise)
106 * @return newly constructed index */
107 coloridx::coloridx(const std::string & n, bool cov) : idx(n,cov)
109 debugmsg("coloridx constructor from string,bool",LOGLEVEL_CONSTRUCT);
110 tinfo_key=TINFO_coloridx;
113 /** Construct symbolic color index with specified name.
115 * @param n Symbolic index name
116 * @param cov Index is covariant (contravariant otherwise)
117 * @return newly constructed index */
118 coloridx::coloridx(const char * n, bool cov) : idx(n,cov)
120 debugmsg("coloridx constructor from char*,bool",LOGLEVEL_CONSTRUCT);
121 tinfo_key=TINFO_coloridx;
124 /** Construct numeric color index with specified value.
126 * @param v Numeric index value
127 * @param cov Index is covariant (contravariant otherwise)
128 * @return newly constructed index */
129 coloridx::coloridx(unsigned v, bool cov) : idx(v,cov)
131 debugmsg("coloridx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT);
132 tinfo_key=TINFO_coloridx;
139 /** Construct object from archive_node. */
140 coloridx::coloridx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
142 debugmsg("coloridx constructor from archive_node", LOGLEVEL_CONSTRUCT);
145 /** Unarchive the object. */
146 ex coloridx::unarchive(const archive_node &n, const lst &sym_lst)
148 return (new coloridx(n, sym_lst))->setflag(status_flags::dynallocated);
151 /** Archive the object. */
152 void coloridx::archive(archive_node &n) const
154 inherited::archive(n);
158 // functions overriding virtual functions from bases classes
163 basic * coloridx::duplicate() const
165 debugmsg("coloridx duplicate",LOGLEVEL_DUPLICATE);
166 return new coloridx(*this);
169 void coloridx::printraw(std::ostream & os) const
171 debugmsg("coloridx printraw",LOGLEVEL_PRINT);
176 os << "symbolic,name=" << name;
178 os << "non symbolic,value=" << value;
184 os << ",contravariant";
187 os << ",serial=" << serial;
188 os << ",hash=" << hashvalue << ",flags=" << flags;
192 void coloridx::printtree(std::ostream & os, unsigned indent) const
194 debugmsg("coloridx printtree",LOGLEVEL_PRINT);
196 os << std::string(indent,' ') << "coloridx: ";
199 os << "symbolic,name=" << name;
201 os << "non symbolic,value=" << value;
207 os << ",contravariant";
210 os << ", serial=" << serial
211 << ", hash=" << hashvalue
212 << " (0x" << std::hex << hashvalue << std::dec << ")"
213 << ", flags=" << flags << std::endl;
216 void coloridx::print(std::ostream & os, unsigned upper_precedence) const
218 debugmsg("coloridx print",LOGLEVEL_PRINT);
232 bool coloridx::info(unsigned inf) const
234 if (inf==info_flags::coloridx) return true;
235 return idx::info(inf);
239 // new virtual functions which can be overridden by derived classes
245 // non-virtual functions in this class
251 // static member variables
260 const coloridx some_coloridx;
261 const std::type_info & typeid_coloridx = typeid(some_coloridx);
263 #ifndef NO_NAMESPACE_GINAC
265 #endif // ndef NO_NAMESPACE_GINAC