/** @file coloridx.cpp
*
- * Implementation of GiNaC's color indices.
- *
- * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ * 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
#include <stdexcept>
-#include "ginac.h"
+#include "coloridx.h"
+#include "archive.h"
#include "utils.h"
+#include "debugmsg.h"
+
+#ifndef NO_NAMESPACE_GINAC
+namespace GiNaC {
+#endif // ndef NO_NAMESPACE_GINAC
+
+GINAC_IMPLEMENT_REGISTERED_CLASS(coloridx, idx)
//////////
// default constructor, destructor, copy constructor assignment operator and helpers
coloridx::coloridx()
{
- debugmsg("coloridx default constructor",LOGLEVEL_CONSTRUCT);
- // serial is incremented in idx::idx()
- name="color"+ToString(serial);
- tinfo_key=TINFO_COLORIDX;
-}
-
-coloridx::~coloridx()
-{
- debugmsg("coloridx destructor",LOGLEVEL_DESTRUCT);
- destroy(0);
-}
-
-coloridx::coloridx(coloridx const & other)
-{
- debugmsg("coloridx copy constructor",LOGLEVEL_CONSTRUCT);
- copy(other);
-}
-
-coloridx const & coloridx::operator=(coloridx const & other)
-{
- debugmsg("coloridx operator=",LOGLEVEL_ASSIGNMENT);
- if (this != &other) {
- destroy(1);
- copy(other);
- }
- return *this;
+ debugmsg("coloridx default constructor",LOGLEVEL_CONSTRUCT);
+ // serial is incremented in idx::idx()
+ name="color"+ToString(serial);
+ tinfo_key=TINFO_coloridx;
}
// protected
-void coloridx::copy(coloridx const & other)
+void coloridx::copy(const coloridx & other)
{
- idx::copy(other);
+ inherited::copy(other);
}
void coloridx::destroy(bool call_parent)
{
- if (call_parent) idx::destroy(call_parent);
+ if (call_parent) inherited::destroy(call_parent);
}
//////////
// 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;
+ debugmsg("coloridx constructor from bool",LOGLEVEL_CONSTRUCT);
+ // serial is incremented in idx::idx(bool)
+ name="color"+ToString(serial);
+ tinfo_key=TINFO_coloridx;
}
-coloridx::coloridx(string const & n, bool cov) : idx(n,cov)
+/** 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;
+ debugmsg("coloridx constructor from string,bool",LOGLEVEL_CONSTRUCT);
+ tinfo_key=TINFO_coloridx;
}
-coloridx::coloridx(char const * n, bool cov) : idx(n,cov)
+/** 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;
+ debugmsg("coloridx constructor from char*,bool",LOGLEVEL_CONSTRUCT);
+ tinfo_key=TINFO_coloridx;
}
-coloridx::coloridx(unsigned const v, bool cov) : idx(v,cov)
+/** 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;
+ debugmsg("coloridx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT);
+ tinfo_key=TINFO_coloridx;
}
//////////
-// functions overriding virtual functions from bases classes
+// archiving
//////////
-// public
-
-basic * coloridx::duplicate() const
+/** Construct object from archive_node. */
+coloridx::coloridx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
{
- debugmsg("coloridx duplicate",LOGLEVEL_DUPLICATE);
- return new coloridx(*this);
+ debugmsg("coloridx constructor from archive_node", LOGLEVEL_CONSTRUCT);
}
-void coloridx::printraw(ostream & os) const
+/** Unarchive the object. */
+ex coloridx::unarchive(const archive_node &n, const lst &sym_lst)
{
- debugmsg("coloridx printraw",LOGLEVEL_PRINT);
-
- os << "coloridx(";
+ return (new coloridx(n, sym_lst))->setflag(status_flags::dynallocated);
+}
- if (symbolic) {
- os << "symbolic,name=" << name;
- } else {
- os << "non symbolic,value=" << value;
- }
+/** Archive the object. */
+void coloridx::archive(archive_node &n) const
+{
+ inherited::archive(n);
+}
- if (covariant) {
- os << ",covariant";
- } else {
- os << ",contravariant";
- }
+//////////
+// functions overriding virtual functions from bases classes
+//////////
- os << ",serial=" << serial;
- os << ",hash=" << hashvalue << ",flags=" << flags;
- os << ")";
-}
+// public
-void coloridx::printtree(ostream & os, unsigned indent) const
+void coloridx::printraw(std::ostream & os) const
{
- debugmsg("coloridx printtree",LOGLEVEL_PRINT);
+ debugmsg("coloridx printraw",LOGLEVEL_PRINT);
- os << string(indent,' ') << "coloridx: ";
+ os << "coloridx(";
- if (symbolic) {
- os << "symbolic,name=" << name;
- } else {
- os << "non symbolic,value=" << value;
- }
+ if (symbolic) {
+ os << "symbolic,name=" << name;
+ } else {
+ os << "non symbolic,value=" << value;
+ }
- if (covariant) {
- os << ",covariant";
- } else {
- os << ",contravariant";
- }
+ if (covariant) {
+ os << ",covariant";
+ } else {
+ os << ",contravariant";
+ }
- os << ", serial=" << serial
- << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
- << ", flags=" << flags << endl;
+ os << ",serial=" << serial;
+ os << ",hash=" << hashvalue << ",flags=" << flags;
+ os << ")";
}
-void coloridx::print(ostream & os, unsigned upper_precedence) const
+void coloridx::printtree(std::ostream & os, unsigned indent) const
{
- debugmsg("coloridx print",LOGLEVEL_PRINT);
-
- if (covariant) {
- os << "_";
- } else {
- os << "~";
- }
- if (symbolic) {
- os << name;
- } else {
- os << value;
- }
+ 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;
}
-bool coloridx::info(unsigned inf) const
+void coloridx::print(std::ostream & os, unsigned upper_precedence) const
{
- if (inf==info_flags::coloridx) return true;
- return idx::info(inf);
+ debugmsg("coloridx print",LOGLEVEL_PRINT);
+
+ if (covariant) {
+ os << "_";
+ } else {
+ os << "~";
+ }
+ if (symbolic) {
+ os << name;
+ } else {
+ os << value;
+ }
}
-//////////
-// new virtual functions which can be overridden by derived classes
-//////////
-
-// none
-
-//////////
-// non-virtual functions in this class
-//////////
-
-// none
-
-//////////
-// static member variables
-//////////
-
-// none
-
-//////////
-// global constants
-//////////
-
-const coloridx some_coloridx;
-type_info const & typeid_coloridx=typeid(some_coloridx);
-
+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);
+}
+#ifndef NO_NAMESPACE_GINAC
+} // namespace GiNaC
+#endif // ndef NO_NAMESPACE_GINAC