/** @file coloridx.cpp * * Implementation of GiNaC's color indices. */ /* * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include "coloridx.h" #include "archive.h" #include "utils.h" #include "debugmsg.h" namespace GiNaC { GINAC_IMPLEMENT_REGISTERED_CLASS(coloridx, idx) ////////// // default constructor, destructor, copy constructor assignment operator and helpers ////////// // public coloridx::coloridx() { debugmsg("coloridx default constructor",LOGLEVEL_CONSTRUCT); // serial is incremented in idx::idx() name="color"+ToString(serial); tinfo_key=TINFO_coloridx; } // protected void coloridx::copy(const coloridx & other) { inherited::copy(other); } void coloridx::destroy(bool call_parent) { if (call_parent) inherited::destroy(call_parent); } ////////// // other constructors ////////// // public /** Construct symbolic color index, using an automatically generated unique name. * * @param cov Index is covariant (contravariant otherwise) * @return newly constructed index */ coloridx::coloridx(bool cov) : idx(cov) { debugmsg("coloridx constructor from bool",LOGLEVEL_CONSTRUCT); // serial is incremented in idx::idx(bool) name="color"+ToString(serial); tinfo_key=TINFO_coloridx; } /** Construct symbolic color index with specified name. * * @param n Symbolic index name * @param cov Index is covariant (contravariant otherwise) * @return newly constructed index */ coloridx::coloridx(const std::string & n, bool cov) : idx(n,cov) { debugmsg("coloridx constructor from string,bool",LOGLEVEL_CONSTRUCT); tinfo_key=TINFO_coloridx; } /** Construct symbolic color index with specified name. * * @param n Symbolic index name * @param cov Index is covariant (contravariant otherwise) * @return newly constructed index */ coloridx::coloridx(const char * n, bool cov) : idx(n,cov) { debugmsg("coloridx constructor from char*,bool",LOGLEVEL_CONSTRUCT); tinfo_key=TINFO_coloridx; } /** Construct numeric color index with specified value. * * @param v Numeric index value * @param cov Index is covariant (contravariant otherwise) * @return newly constructed index */ coloridx::coloridx(unsigned v, bool cov) : idx(v,cov) { debugmsg("coloridx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT); tinfo_key=TINFO_coloridx; } ////////// // archiving ////////// /** Construct object from archive_node. */ coloridx::coloridx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) { debugmsg("coloridx constructor from archive_node", LOGLEVEL_CONSTRUCT); } /** Unarchive the object. */ ex coloridx::unarchive(const archive_node &n, const lst &sym_lst) { return (new coloridx(n, sym_lst))->setflag(status_flags::dynallocated); } /** Archive the object. */ void coloridx::archive(archive_node &n) const { inherited::archive(n); } ////////// // functions overriding virtual functions from bases classes ////////// // public void coloridx::printraw(std::ostream & os) const { debugmsg("coloridx printraw",LOGLEVEL_PRINT); os << "coloridx("; if (symbolic) { os << "symbolic,name=" << name; } else { os << "non symbolic,value=" << value; } if (covariant) { os << ",covariant"; } else { os << ",contravariant"; } os << ",serial=" << serial; os << ",hash=" << hashvalue << ",flags=" << flags; os << ")"; } void coloridx::printtree(std::ostream & os, unsigned indent) const { debugmsg("coloridx printtree",LOGLEVEL_PRINT); os << std::string(indent,' ') << "coloridx: "; if (symbolic) { os << "symbolic,name=" << name; } else { os << "non symbolic,value=" << value; } if (covariant) { os << ",covariant"; } else { os << ",contravariant"; } os << ", serial=" << serial << ", hash=" << hashvalue << " (0x" << std::hex << hashvalue << std::dec << ")" << ", flags=" << flags << std::endl; } void coloridx::print(std::ostream & os, unsigned upper_precedence) const { debugmsg("coloridx print",LOGLEVEL_PRINT); if (covariant) { os << "_"; } else { os << "~"; } if (symbolic) { os << name; } else { os << value; } } bool coloridx::info(unsigned inf) const { if (inf==info_flags::coloridx) return true; return idx::info(inf); } int coloridx::compare_same_type(const basic & other) const { return inherited::compare_same_type(other); } } // namespace GiNaC