From: Christian Bauer Date: Wed, 28 Mar 2001 00:36:37 +0000 (+0000) Subject: - added skeleton implementation of color and clifford classes (don't bother X-Git-Tag: release_0-8-1~45 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=9c91319253425e66f9b6feb9e7036f841bc55e84;ds=sidebyside - added skeleton implementation of color and clifford classes (don't bother trying it, it doesn't work yet) - some macros in utils.h (DEFAULT_*) provide shorthands for implementing many required class member functions --- diff --git a/ginac/Makefile.am b/ginac/Makefile.am index fffe951c..45fe8611 100644 --- a/ginac/Makefile.am +++ b/ginac/Makefile.am @@ -7,7 +7,8 @@ libginac_la_SOURCES = add.cpp archive.cpp basic.cpp constant.cpp ex.cpp \ normal.cpp numeric.cpp operators.cpp power.cpp registrar.cpp relational.cpp \ symbol.cpp pseries.cpp utils.cpp ncmul.cpp structure.cpp exprseq_suppl.cpp \ lst.cpp lst_suppl.cpp input_parser.yy input_lexer.ll input_lexer.h \ - remember.h remember.cpp debugmsg.h utils.h idx.cpp indexed.cpp tensor.cpp + remember.h remember.cpp debugmsg.h utils.h idx.cpp indexed.cpp tensor.cpp \ + color.cpp clifford.cpp libginac_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \ -release $(LT_RELEASE) ginacincludedir = $(includedir)/ginac @@ -15,7 +16,7 @@ ginacinclude_HEADERS = ginac.h add.h archive.h basic.h constant.h ex.h \ expair.h expairseq.h exprseq.h fail.h flags.h function.h inifcns.h \ lst.h matrix.h mul.h ncmul.h normal.h numeric.h operators.h power.h \ registrar.h relational.h pseries.h structure.h symbol.h tinfos.h assertion.h \ - version.h idx.h indexed.h tensor.h + version.h idx.h indexed.h tensor.h color.h clifford.h LFLAGS = -Pginac_yy -olex.yy.c YFLAGS = -p ginac_yy -d EXTRA_DIST = container.pl function.pl structure.pl input_parser.h version.h.in diff --git a/ginac/add.cpp b/ginac/add.cpp index 6c6a1638..150b4f82 100644 --- a/ginac/add.cpp +++ b/ginac/add.cpp @@ -37,26 +37,14 @@ GINAC_IMPLEMENT_REGISTERED_CLASS(add, expairseq) // default constructor, destructor, copy constructor assignment operator and helpers ////////// -// public - add::add() { debugmsg("add default constructor",LOGLEVEL_CONSTRUCT); tinfo_key = TINFO_add; } -// protected - -/** For use by copy ctor and assignment operator. */ -void add::copy(const add & other) -{ - inherited::copy(other); -} - -void add::destroy(bool call_parent) -{ - if (call_parent) inherited::destroy(call_parent); -} +DEFAULT_COPY(add) +DEFAULT_DESTROY(add) ////////// // other constructors @@ -115,23 +103,7 @@ add::add(epvector * vp, const ex & oc) // archiving ////////// -/** Construct object from archive_node. */ -add::add(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) -{ - debugmsg("add constructor from archive_node", LOGLEVEL_CONSTRUCT); -} - -/** Unarchive the object. */ -ex add::unarchive(const archive_node &n, const lst &sym_lst) -{ - return (new add(n, sym_lst))->setflag(status_flags::dynallocated); -} - -/** Archive the object. */ -void add::archive(archive_node &n) const -{ - inherited::archive(n); -} +DEFAULT_ARCHIVING(add) ////////// // functions overriding virtual functions from bases classes diff --git a/ginac/basic.cpp b/ginac/basic.cpp index 1c6fe6fa..42d1f866 100644 --- a/ginac/basic.cpp +++ b/ginac/basic.cpp @@ -89,10 +89,7 @@ basic::basic(const archive_node &n, const lst &sym_lst) : flags(0), refcount(0) } /** Unarchive the object. */ -ex basic::unarchive(const archive_node &n, const lst &sym_lst) -{ - return (new basic(n, sym_lst))->setflag(status_flags::dynallocated); -} +DEFAULT_UNARCHIVE(basic) /** Archive the object. */ void basic::archive(archive_node &n) const diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp new file mode 100644 index 00000000..5875bbb8 --- /dev/null +++ b/ginac/clifford.cpp @@ -0,0 +1,126 @@ +/** @file clifford.cpp + * + * Implementation of GiNaC's clifford algebra (Dirac gamma) objects. */ + +/* + * 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 "clifford.h" +#include "ex.h" +#include "idx.h" +#include "ncmul.h" +#include "archive.h" +#include "debugmsg.h" +#include "utils.h" + +#include + +namespace GiNaC { + +GINAC_IMPLEMENT_REGISTERED_CLASS(clifford, indexed) +GINAC_IMPLEMENT_REGISTERED_CLASS(diracgamma, tensor) + +////////// +// default constructor, destructor, copy constructor assignment operator and helpers +////////// + +clifford::clifford() +{ + debugmsg("clifford default constructor", LOGLEVEL_CONSTRUCT); + tinfo_key = TINFO_clifford; +} + +DEFAULT_COPY(clifford) +DEFAULT_DESTROY(clifford) +DEFAULT_CTORS(diracgamma) + +////////// +// other constructors +////////// + +/** Construct object with one Lorentz index. This constructor is for internal + * use only. Use the dirac_gamma() function instead. + * @see dirac_gamma */ +clifford::clifford(const ex & b, const ex & mu) : inherited(b, mu) +{ + debugmsg("clifford constructor from ex,ex", LOGLEVEL_CONSTRUCT); + GINAC_ASSERT(is_ex_of_type(mu, varidx)); + tinfo_key = TINFO_clifford; +} + +clifford::clifford(const exvector & v, bool discardable) : inherited(indexed::unknown, v, discardable) +{ + debugmsg("clifford constructor from exvector", LOGLEVEL_CONSTRUCT); + tinfo_key = TINFO_clifford; +} + +clifford::clifford(exvector * vp) : inherited(indexed::unknown, vp) +{ + debugmsg("clifford constructor from exvector *", LOGLEVEL_CONSTRUCT); + tinfo_key = TINFO_clifford; +} + +////////// +// archiving +////////// + +DEFAULT_ARCHIVING(clifford) +DEFAULT_ARCHIVING(diracgamma) + +////////// +// functions overriding virtual functions from bases classes +////////// + +int clifford::compare_same_type(const basic & other) const +{ + return inherited::compare_same_type(other); +} + +DEFAULT_COMPARE(diracgamma) +DEFAULT_PRINT(diracgamma, "gamma") + +/** Perform automatic simplification on noncommutative product of clifford + * objects. */ +ex clifford::simplify_ncmul(const exvector & v) const +{ + //!! to be implemented + return nonsimplified_ncmul(v); +} + +ex clifford::thisexprseq(const exvector & v) const +{ + return clifford(v); +} + +ex clifford::thisexprseq(exvector * vp) const +{ + return clifford(vp); +} + +////////// +// global functions +////////// + +ex dirac_gamma(const ex & mu) +{ + if (!is_ex_of_type(mu, varidx)) + throw(std::invalid_argument("index of Dirac gamma must be of type varidx")); + return clifford(diracgamma(), mu); +} + +} // namespace GiNaC diff --git a/ginac/constant.cpp b/ginac/constant.cpp index 90025154..5b2bfebe 100644 --- a/ginac/constant.cpp +++ b/ginac/constant.cpp @@ -91,13 +91,11 @@ constant::constant(const std::string & initname, const numeric & initnumber) // archiving ////////// -/** Construct object from archive_node. */ constant::constant(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) { debugmsg("constant ctor from archive_node", LOGLEVEL_CONSTRUCT); } -/** Unarchive the object. */ ex constant::unarchive(const archive_node &n, const lst &sym_lst) { // Find constant by name (!! this is bad: 'twould be better if there @@ -116,7 +114,6 @@ ex constant::unarchive(const archive_node &n, const lst &sym_lst) throw (std::runtime_error("unnamed constant in archive")); } -/** Archive the object. */ void constant::archive(archive_node &n) const { inherited::archive(n); diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp index cfcfa16d..43754ea2 100644 --- a/ginac/expairseq.cpp +++ b/ginac/expairseq.cpp @@ -101,11 +101,7 @@ void expairseq::copy(const expairseq &other) #endif // EXPAIRSEQ_USE_HASHTAB } -void expairseq::destroy(bool call_parent) -{ - if (call_parent) - basic::destroy(call_parent); -} +DEFAULT_DESTROY(expairseq) ////////// // other ctors @@ -147,7 +143,6 @@ expairseq::expairseq(epvector *vp, const ex &oc) // archiving ////////// -/** Construct object from archive_node. */ expairseq::expairseq(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) #if EXPAIRSEQ_USE_HASHTAB , hashtabsize(0) @@ -165,13 +160,6 @@ expairseq::expairseq(const archive_node &n, const lst &sym_lst) : inherited(n, s n.find_ex("overall_coeff", overall_coeff, sym_lst); } -/** Unarchive the object. */ -ex expairseq::unarchive(const archive_node &n, const lst &sym_lst) -{ - return (new expairseq(n, sym_lst))->setflag(status_flags::dynallocated); -} - -/** Archive the object. */ void expairseq::archive(archive_node &n) const { inherited::archive(n); @@ -184,6 +172,8 @@ void expairseq::archive(archive_node &n) const n.add_ex("overall_coeff", overall_coeff); } +DEFAULT_UNARCHIVE(expairseq) + ////////// // functions overriding virtual functions from bases classes ////////// diff --git a/ginac/fail.cpp b/ginac/fail.cpp index 4fd01997..7de656a5 100644 --- a/ginac/fail.cpp +++ b/ginac/fail.cpp @@ -24,6 +24,7 @@ #include "fail.h" #include "archive.h" #include "debugmsg.h" +#include "utils.h" namespace GiNaC { @@ -33,71 +34,19 @@ GINAC_IMPLEMENT_REGISTERED_CLASS(fail, basic) // default ctor, dtor, copy ctor assignment operator and helpers ////////// -// public - -fail::fail() : inherited(TINFO_fail) -{ - debugmsg("fail default ctor",LOGLEVEL_CONSTRUCT); -} - -// protected - -void fail::copy(const fail & other) -{ - inherited::copy(other); -} - -void fail::destroy(bool call_parent) -{ - if (call_parent) inherited::destroy(call_parent); -} +DEFAULT_CTORS(fail) ////////// // archiving ////////// -/** Construct object from archive_node. */ -fail::fail(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) -{ - debugmsg("fail ctor from archive_node", LOGLEVEL_CONSTRUCT); -} - -/** Unarchive the object. */ -ex fail::unarchive(const archive_node &n, const lst &sym_lst) -{ - return (new fail(n, sym_lst))->setflag(status_flags::dynallocated); -} - -/** Archive the object. */ -void fail::archive(archive_node &n) const -{ - inherited::archive(n); -} +DEFAULT_ARCHIVING(fail) ////////// // functions overriding virtual functions from bases classes ////////// -// public - -void fail::print(std::ostream & os, unsigned upper_precedence) const -{ - debugmsg("fail print",LOGLEVEL_PRINT); - os << "FAIL"; -} - -void fail::printraw(std::ostream & os) const -{ - debugmsg("fail printraw",LOGLEVEL_PRINT); - os << "FAIL"; -} - -// protected - -int fail::compare_same_type(const basic & other) const -{ - // two fails are always identical - return 0; -} +DEFAULT_COMPARE(fail) +DEFAULT_PRINT(fail, "FAIL") } // namespace GiNaC diff --git a/ginac/fail.h b/ginac/fail.h index f3104d85..415aba59 100644 --- a/ginac/fail.h +++ b/ginac/fail.h @@ -32,24 +32,11 @@ class fail : public basic { GINAC_DECLARE_REGISTERED_CLASS(fail, basic) - // other ctors - // none - // functions overriding virtual functions from bases classes public: void print(std::ostream & os, unsigned upper_precedence=0) const; - void printraw(std::ostream & os) const; protected: unsigned return_type(void) const { return return_types::noncommutative_composite; }; - - // new virtual functions which can be overridden by derived classes - // none - - // non-virtual functions in this class - // none - - // member variables - // none }; } // namespace GiNaC diff --git a/ginac/ginac.h b/ginac/ginac.h index 5e08ce33..a21eb1c9 100644 --- a/ginac/ginac.h +++ b/ginac/ginac.h @@ -58,6 +58,8 @@ #include "idx.h" #include "indexed.h" #include "tensor.h" +#include "color.h" +#include "clifford.h" #endif // ndef GINAC_BASE_ONLY #ifdef __MAKECINT__ diff --git a/ginac/idx.cpp b/ginac/idx.cpp index 89373cc4..994d532e 100644 --- a/ginac/idx.cpp +++ b/ginac/idx.cpp @@ -62,17 +62,8 @@ void varidx::copy(const varidx & other) covariant = other.covariant; } -void idx::destroy(bool call_parent) -{ - if (call_parent) - inherited::destroy(call_parent); -} - -void varidx::destroy(bool call_parent) -{ - if (call_parent) - inherited::destroy(call_parent); -} +DEFAULT_DESTROY(idx) +DEFAULT_DESTROY(varidx) ////////// // other constructors @@ -109,16 +100,6 @@ varidx::varidx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst n.find_bool("covariant", covariant); } -ex idx::unarchive(const archive_node &n, const lst &sym_lst) -{ - return (new idx(n, sym_lst))->setflag(status_flags::dynallocated); -} - -ex varidx::unarchive(const archive_node &n, const lst &sym_lst) -{ - return (new varidx(n, sym_lst))->setflag(status_flags::dynallocated); -} - void idx::archive(archive_node &n) const { inherited::archive(n); @@ -132,6 +113,9 @@ void varidx::archive(archive_node &n) const n.add_bool("covariant", covariant); } +DEFAULT_UNARCHIVE(idx) +DEFAULT_UNARCHIVE(varidx) + ////////// // functions overriding virtual functions from bases classes ////////// diff --git a/ginac/indexed.cpp b/ginac/indexed.cpp index 27379fec..dfd9a381 100644 --- a/ginac/indexed.cpp +++ b/ginac/indexed.cpp @@ -52,11 +52,7 @@ void indexed::copy(const indexed & other) symmetry = other.symmetry; } -void indexed::destroy(bool call_parent) -{ - if (call_parent) - inherited::destroy(call_parent); -} +DEFAULT_DESTROY(indexed) ////////// // other constructors @@ -159,7 +155,6 @@ indexed::indexed(symmetry_type symm, exvector * vp) : inherited(vp), symmetry(sy // archiving ////////// -/** Construct object from archive_node. */ indexed::indexed(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) { debugmsg("indexed constructor from archive_node", LOGLEVEL_CONSTRUCT); @@ -168,19 +163,14 @@ indexed::indexed(const archive_node &n, const lst &sym_lst) : inherited(n, sym_l throw (std::runtime_error("unknown indexed symmetry type in archive")); } -/** Unarchive the object. */ -ex indexed::unarchive(const archive_node &n, const lst &sym_lst) -{ - return (new indexed(n, sym_lst))->setflag(status_flags::dynallocated); -} - -/** Archive the object. */ void indexed::archive(archive_node &n) const { inherited::archive(n); n.add_unsigned("symmetry", symmetry); } +DEFAULT_UNARCHIVE(indexed) + ////////// // functions overriding virtual functions from bases classes ////////// diff --git a/ginac/matrix.cpp b/ginac/matrix.cpp index cc80f7ca..380a45e7 100644 --- a/ginac/matrix.cpp +++ b/ginac/matrix.cpp @@ -44,8 +44,6 @@ GINAC_IMPLEMENT_REGISTERED_CLASS(matrix, basic) // default ctor, dtor, copy ctor, assignment operator and helpers: ////////// -// public - /** Default ctor. Initializes to 1 x 1-dimensional zero-matrix. */ matrix::matrix() : inherited(TINFO_matrix), row(1), col(1) { @@ -53,9 +51,6 @@ matrix::matrix() : inherited(TINFO_matrix), row(1), col(1) m.push_back(_ex0()); } -// protected - -/** For use by copy ctor and assignment operator. */ void matrix::copy(const matrix & other) { inherited::copy(other); @@ -64,10 +59,7 @@ void matrix::copy(const matrix & other) m = other.m; // STL's vector copying invoked here } -void matrix::destroy(bool call_parent) -{ - if (call_parent) inherited::destroy(call_parent); -} +DEFAULT_DESTROY(matrix) ////////// // other ctors @@ -118,7 +110,6 @@ matrix::matrix(unsigned r, unsigned c, const lst & l) // archiving ////////// -/** Construct object from archive_node. */ matrix::matrix(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) { debugmsg("matrix ctor from archive_node", LOGLEVEL_CONSTRUCT); @@ -134,13 +125,6 @@ matrix::matrix(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst } } -/** Unarchive the object. */ -ex matrix::unarchive(const archive_node &n, const lst &sym_lst) -{ - return (new matrix(n, sym_lst))->setflag(status_flags::dynallocated); -} - -/** Archive the object. */ void matrix::archive(archive_node &n) const { inherited::archive(n); @@ -153,6 +137,8 @@ void matrix::archive(archive_node &n) const } } +DEFAULT_UNARCHIVE(matrix) + ////////// // functions overriding virtual functions from bases classes ////////// diff --git a/ginac/mul.cpp b/ginac/mul.cpp index 8eef9176..e156a0ff 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -38,26 +38,14 @@ GINAC_IMPLEMENT_REGISTERED_CLASS(mul, expairseq) // default ctor, dctor, copy ctor assignment operator and helpers ////////// -// public - mul::mul() { debugmsg("mul default ctor",LOGLEVEL_CONSTRUCT); tinfo_key = TINFO_mul; } -// protected - -/** For use by copy ctor and assignment operator. */ -void mul::copy(const mul & other) -{ - inherited::copy(other); -} - -void mul::destroy(bool call_parent) -{ - if (call_parent) inherited::destroy(call_parent); -} +DEFAULT_COPY(mul) +DEFAULT_DESTROY(mul) ////////// // other ctors @@ -130,23 +118,7 @@ mul::mul(const ex & lh, const ex & mh, const ex & rh) // archiving ////////// -/** Construct object from archive_node. */ -mul::mul(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) -{ - debugmsg("mul ctor from archive_node", LOGLEVEL_CONSTRUCT); -} - -/** Unarchive the object. */ -ex mul::unarchive(const archive_node &n, const lst &sym_lst) -{ - return (new mul(n, sym_lst))->setflag(status_flags::dynallocated); -} - -/** Archive the object. */ -void mul::archive(archive_node &n) const -{ - inherited::archive(n); -} +DEFAULT_ARCHIVING(mul) ////////// // functions overriding virtual functions from bases classes diff --git a/ginac/ncmul.cpp b/ginac/ncmul.cpp index 44c5d30e..12c1d5e4 100644 --- a/ginac/ncmul.cpp +++ b/ginac/ncmul.cpp @@ -40,25 +40,14 @@ GINAC_IMPLEMENT_REGISTERED_CLASS(ncmul, exprseq) // default constructor, destructor, copy constructor assignment operator and helpers ////////// -// public - ncmul::ncmul() { debugmsg("ncmul default constructor",LOGLEVEL_CONSTRUCT); tinfo_key = TINFO_ncmul; } -// protected - -void ncmul::copy(const ncmul & other) -{ - inherited::copy(other); -} - -void ncmul::destroy(bool call_parent) -{ - if (call_parent) inherited::destroy(call_parent); -} +DEFAULT_COPY(ncmul) +DEFAULT_DESTROY(ncmul) ////////// // other constructors @@ -115,24 +104,7 @@ ncmul::ncmul(exvector * vp) : inherited(vp) // archiving ////////// -/** Construct object from archive_node. */ -ncmul::ncmul(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) -{ - debugmsg("ncmul constructor from archive_node", LOGLEVEL_CONSTRUCT); -} - -/** Unarchive the object. */ -ex ncmul::unarchive(const archive_node &n, const lst &sym_lst) -{ - return (new ncmul(n, sym_lst))->setflag(status_flags::dynallocated); -} - -/** Archive the object. */ -void ncmul::archive(archive_node &n) const -{ - inherited::archive(n); -} - +DEFAULT_ARCHIVING(ncmul) ////////// // functions overriding virtual functions from bases classes @@ -336,7 +308,7 @@ ex ncmul::eval(int level) const // *(c1,c2,ncmul(...)) (pull out commutative elements) // ncmul(x1,y1,x2,y2) -> *(ncmul(x1,x2),ncmul(y1,y2)) // (collect elements of same type) - // ncmul(x1,x2,x3,...) -> x::eval_ncmul(x1,x2,x3,...) + // ncmul(x1,x2,x3,...) -> x::simplify_ncmul(x1,x2,x3,...) // the following rule would be nice, but produces a recursion, // which must be trapped by introducing a flag that the sub-ncmuls() // are already evaluated (maybe later...) diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp index 995672e3..a4a40c8c 100644 --- a/ginac/numeric.cpp +++ b/ginac/numeric.cpp @@ -72,8 +72,6 @@ GINAC_IMPLEMENT_REGISTERED_CLASS(numeric, basic) // operator and helpers ////////// -// public - /** default ctor. Numerically it initializes to an integer zero. */ numeric::numeric() : basic(TINFO_numeric) { @@ -82,19 +80,13 @@ numeric::numeric() : basic(TINFO_numeric) setflag(status_flags::evaluated | status_flags::expanded); } -// protected - -/** For use by copy ctor and assignment operator. */ void numeric::copy(const numeric &other) { inherited::copy(other); value = other.value; } -void numeric::destroy(bool call_parent) -{ - if (call_parent) inherited::destroy(call_parent); -} +DEFAULT_DESTROY(numeric) ////////// // other ctors @@ -266,7 +258,6 @@ numeric::numeric(const cln::cl_N &z) : basic(TINFO_numeric) // archiving ////////// -/** Construct object from archive_node. */ numeric::numeric(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) { debugmsg("numeric ctor from archive_node", LOGLEVEL_CONSTRUCT); @@ -304,13 +295,6 @@ numeric::numeric(const archive_node &n, const lst &sym_lst) : inherited(n, sym_l setflag(status_flags::evaluated | status_flags::expanded); } -/** Unarchive the object. */ -ex numeric::unarchive(const archive_node &n, const lst &sym_lst) -{ - return (new numeric(n, sym_lst))->setflag(status_flags::dynallocated); -} - -/** Archive the object. */ void numeric::archive(archive_node &n) const { inherited::archive(n); @@ -348,6 +332,8 @@ void numeric::archive(archive_node &n) const #endif } +DEFAULT_UNARCHIVE(numeric) + ////////// // functions overriding virtual functions from bases classes ////////// diff --git a/ginac/power.cpp b/ginac/power.cpp index b0f9cd2d..14fac0ad 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -46,15 +46,11 @@ typedef std::vector intvector; // default ctor, dtor, copy ctor assignment operator and helpers ////////// -// public - power::power() : basic(TINFO_power) { debugmsg("power default ctor",LOGLEVEL_CONSTRUCT); } -// protected - void power::copy(const power & other) { inherited::copy(other); @@ -62,17 +58,12 @@ void power::copy(const power & other) exponent = other.exponent; } -void power::destroy(bool call_parent) -{ - if (call_parent) inherited::destroy(call_parent); -} +DEFAULT_DESTROY(power) ////////// // other ctors ////////// -// public - power::power(const ex & lh, const ex & rh) : basic(TINFO_power), basis(lh), exponent(rh) { debugmsg("power ctor from ex,ex",LOGLEVEL_CONSTRUCT); @@ -89,7 +80,6 @@ power::power(const ex & lh, const numeric & rh) : basic(TINFO_power), basis(lh), // archiving ////////// -/** Construct object from archive_node. */ power::power(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) { debugmsg("power ctor from archive_node", LOGLEVEL_CONSTRUCT); @@ -97,13 +87,6 @@ power::power(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) n.find_ex("exponent", exponent, sym_lst); } -/** Unarchive the object. */ -ex power::unarchive(const archive_node &n, const lst &sym_lst) -{ - return (new power(n, sym_lst))->setflag(status_flags::dynallocated); -} - -/** Archive the object. */ void power::archive(archive_node &n) const { inherited::archive(n); @@ -111,6 +94,8 @@ void power::archive(archive_node &n) const n.add_ex("exponent", exponent); } +DEFAULT_UNARCHIVE(power) + ////////// // functions overriding virtual functions from bases classes ////////// diff --git a/ginac/pseries.cpp b/ginac/pseries.cpp index 3b2ac701..5a922183 100644 --- a/ginac/pseries.cpp +++ b/ginac/pseries.cpp @@ -39,6 +39,7 @@ namespace GiNaC { GINAC_IMPLEMENT_REGISTERED_CLASS(pseries, basic) + /* * Default ctor, dtor, copy ctor, assignment operator and helpers */ @@ -56,11 +57,7 @@ void pseries::copy(const pseries &other) point = other.point; } -void pseries::destroy(bool call_parent) -{ - if (call_parent) - inherited::destroy(call_parent); -} +DEFAULT_DESTROY(pseries) /* @@ -90,7 +87,6 @@ pseries::pseries(const ex &rel_, const epvector &ops_) : basic(TINFO_pseries), s * Archiving */ -/** Construct object from archive_node. */ pseries::pseries(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) { debugmsg("pseries ctor from archive_node", LOGLEVEL_CONSTRUCT); @@ -106,13 +102,6 @@ pseries::pseries(const archive_node &n, const lst &sym_lst) : inherited(n, sym_l n.find_ex("point", point, sym_lst); } -/** Unarchive the object. */ -ex pseries::unarchive(const archive_node &n, const lst &sym_lst) -{ - return (new pseries(n, sym_lst))->setflag(status_flags::dynallocated); -} - -/** Archive the object. */ void pseries::archive(archive_node &n) const { inherited::archive(n); @@ -126,6 +115,8 @@ void pseries::archive(archive_node &n) const n.add_ex("point", point); } +DEFAULT_UNARCHIVE(pseries) + ////////// // functions overriding virtual functions from bases classes ////////// diff --git a/ginac/relational.cpp b/ginac/relational.cpp index 20ff40b8..6c417dea 100644 --- a/ginac/relational.cpp +++ b/ginac/relational.cpp @@ -36,15 +36,11 @@ GINAC_IMPLEMENT_REGISTERED_CLASS(relational, basic) // default ctor, dtor, copy ctor assignment operator and helpers ////////// -// public - relational::relational() : basic(TINFO_relational) { debugmsg("relational default ctor",LOGLEVEL_CONSTRUCT); } -// protected - void relational::copy(const relational & other) { basic::copy(other); @@ -53,10 +49,7 @@ void relational::copy(const relational & other) o=other.o; } -void relational::destroy(bool call_parent) -{ - if (call_parent) basic::destroy(call_parent); -} +DEFAULT_DESTROY(relational) ////////// // other ctors @@ -76,7 +69,6 @@ relational::relational(const ex & lhs, const ex & rhs, operators oper) : basic(T // archiving ////////// -/** Construct object from archive_node. */ relational::relational(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) { debugmsg("relational ctor from archive_node", LOGLEVEL_CONSTRUCT); @@ -88,13 +80,6 @@ relational::relational(const archive_node &n, const lst &sym_lst) : inherited(n, n.find_ex("rh", rh, sym_lst); } -/** Unarchive the object. */ -ex relational::unarchive(const archive_node &n, const lst &sym_lst) -{ - return (new relational(n, sym_lst))->setflag(status_flags::dynallocated); -} - -/** Archive the object. */ void relational::archive(archive_node &n) const { inherited::archive(n); @@ -103,6 +88,8 @@ void relational::archive(archive_node &n) const n.add_unsigned("op", o); } +DEFAULT_UNARCHIVE(relational) + ////////// // functions overriding virtual functions from bases classes ////////// diff --git a/ginac/structure.cpp b/ginac/structure.cpp index e9c3b021..0bd1d4fb 100644 --- a/ginac/structure.cpp +++ b/ginac/structure.cpp @@ -25,6 +25,7 @@ #include "structure.h" #include "archive.h" #include "debugmsg.h" +#include "utils.h" namespace GiNaC { @@ -34,60 +35,18 @@ GINAC_IMPLEMENT_REGISTERED_CLASS(structure, basic) // default ctor, dtor, copy ctor assignment operator and helpers ////////// -// public - -structure::structure() -{ - debugmsg("structure default ctor",LOGLEVEL_CONSTRUCT); - tinfo_key = TINFO_structure; -} - -// protected - -void structure::copy(const structure & other) -{ - basic::copy(other); -} - -void structure::destroy(bool call_parent) -{ - if (call_parent) basic::destroy(call_parent); -} - -////////// -// other ctors -////////// - -// none +DEFAULT_CTORS(structure) ////////// // archiving ////////// -/** Construct object from archive_node. */ -structure::structure(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) -{ - debugmsg("structure ctor from archive_node", LOGLEVEL_CONSTRUCT); -} - -/** Unarchive the object. */ -ex structure::unarchive(const archive_node &n, const lst &sym_lst) -{ - return (new structure(n, sym_lst))->setflag(status_flags::dynallocated); -} - -/** Archive the object. */ -void structure::archive(archive_node &n) const -{ - inherited::archive(n); -} +DEFAULT_ARCHIVING(structure) ////////// -// structures overriding virtual structures from bases classes +// functions overriding virtual functions from bases classes ////////// -// public - void structure::printraw(std::ostream & os) const { debugmsg("structure printraw",LOGLEVEL_PRINT); @@ -121,11 +80,7 @@ void structure::printcsrc(std::ostream & os, unsigned type, unsigned upper_prece // protected -int structure::compare_same_type(const basic & other) const -{ - GINAC_ASSERT(is_of_type(other, structure)); - return 0; // all structures are the same -} +DEFAULT_COMPARE(structure) bool structure::is_equal_same_type(const basic & other) const { @@ -134,13 +89,7 @@ bool structure::is_equal_same_type(const basic & other) const } ////////// -// new virtual structures which can be overridden by derived classes -////////// - -// none - -////////// -// non-virtual structures in this class +// non-virtual functions in this class ////////// // protected diff --git a/ginac/structure.h b/ginac/structure.h index 12b86d1c..9ad049fd 100644 --- a/ginac/structure.h +++ b/ginac/structure.h @@ -41,9 +41,6 @@ class structure : public basic { GINAC_DECLARE_REGISTERED_CLASS(structure, basic) - // other ctors - // none - // functions overriding virtual functions from bases classes public: void printraw(std::ostream & os) const; @@ -53,18 +50,11 @@ public: protected: bool is_equal_same_type(const basic & other) const; - // new virtual functions which can be overridden by derived classes - // none - // non-virtual functions in this class protected: static std::vector & registered_structures(void); public: static unsigned register_new(const char * nm); - -// member variables -// none - }; } // namespace GiNaC diff --git a/ginac/tensor.cpp b/ginac/tensor.cpp index 0e6b1162..ed6ad9dc 100644 --- a/ginac/tensor.cpp +++ b/ginac/tensor.cpp @@ -44,24 +44,6 @@ GINAC_IMPLEMENT_REGISTERED_CLASS(tensepsilon, tensor) // default constructor, destructor, copy constructor assignment operator and helpers ////////// -#define DEFAULT_DESTROY(classname) \ -void classname::destroy(bool call_parent) \ -{ \ - if (call_parent) \ - inherited::destroy(call_parent); \ -} - -#define DEFAULT_CTORS(classname) \ -classname::classname() : inherited(TINFO_##classname) \ -{ \ - debugmsg(#classname " default constructor", LOGLEVEL_CONSTRUCT); \ -} \ -void classname::copy(const classname & other) \ -{ \ - inherited::copy(other); \ -} \ -DEFAULT_DESTROY(classname) - tensor::tensor(unsigned ti) : inherited(ti) { debugmsg("tensor constructor from unsigned", LOGLEVEL_CONSTRUCT); \ @@ -114,23 +96,6 @@ void tensepsilon::copy(const tensepsilon & other) // archiving ////////// -#define DEFAULT_UNARCHIVE(classname) \ -ex classname::unarchive(const archive_node &n, const lst &sym_lst) \ -{ \ - return (new classname(n, sym_lst))->setflag(status_flags::dynallocated); \ -} - -#define DEFAULT_ARCHIVING(classname) \ -classname::classname(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) \ -{ \ - debugmsg(#classname " constructor from archive_node", LOGLEVEL_CONSTRUCT); \ -} \ -DEFAULT_UNARCHIVE(classname) \ -void classname::archive(archive_node &n) const \ -{ \ - inherited::archive(n); \ -} - DEFAULT_ARCHIVING(tensor) DEFAULT_ARCHIVING(tensdelta) DEFAULT_ARCHIVING(tensmetric) @@ -167,13 +132,6 @@ void tensepsilon::archive(archive_node &n) const // functions overriding virtual functions from bases classes ////////// -#define DEFAULT_COMPARE(classname) \ -int classname::compare_same_type(const basic & other) const \ -{ \ - /* by default, two tensors of the same class are always identical */ \ - return 0; \ -} - DEFAULT_COMPARE(tensor) DEFAULT_COMPARE(tensdelta) DEFAULT_COMPARE(tensmetric) @@ -202,29 +160,10 @@ int tensepsilon::compare_same_type(const basic & other) const return inherited::compare_same_type(other); } -void tensdelta::print(std::ostream & os, unsigned upper_precedence) const -{ - debugmsg("tensdelta print",LOGLEVEL_PRINT); - os << "delta"; -} - -void tensmetric::print(std::ostream & os, unsigned upper_precedence) const -{ - debugmsg("tensmetric print",LOGLEVEL_PRINT); - os << "g"; -} - -void minkmetric::print(std::ostream & os, unsigned upper_precedence) const -{ - debugmsg("minkmetric print",LOGLEVEL_PRINT); - os << "eta"; -} - -void tensepsilon::print(std::ostream & os, unsigned upper_precedence) const -{ - debugmsg("tensepsilon print",LOGLEVEL_PRINT); - os << "eps"; -} +DEFAULT_PRINT(tensdelta, "delta") +DEFAULT_PRINT(tensmetric, "g") +DEFAULT_PRINT(minkmetric, "eta") +DEFAULT_PRINT(tensepsilon, "eps") /** Automatic symbolic evaluation of an indexed delta tensor. */ ex tensdelta::eval_indexed(const basic & i) const diff --git a/ginac/tinfos.h b/ginac/tinfos.h index 2b189595..76728557 100644 --- a/ginac/tinfos.h +++ b/ginac/tinfos.h @@ -53,6 +53,8 @@ const unsigned TINFO_numeric = 0x00090001U; const unsigned TINFO_pseries = 0x000a0001U; const unsigned TINFO_indexed = 0x000b0001U; +const unsigned TINFO_color = 0x000b1001U; +const unsigned TINFO_clifford = 0x000b1002U; const unsigned TINFO_structure = 0x000c0001U; // reserved up to 0x000cffffU @@ -66,6 +68,11 @@ const unsigned TINFO_tensdelta = 0x000e1001U; const unsigned TINFO_tensmetric = 0x000e1002U; const unsigned TINFO_minkmetric = 0x000e2001U; const unsigned TINFO_tensepsilon = 0x000e1003U; +const unsigned TINFO_su3one = 0x000e1008U; +const unsigned TINFO_su3t = 0x000e1009U; +const unsigned TINFO_su3f = 0x000e100aU; +const unsigned TINFO_su3d = 0x000e100bU; +const unsigned TINFO_diracgamma = 0x000e100cU; } // namespace GiNaC diff --git a/ginac/utils.h b/ginac/utils.h index 5f34d025..6e1d3ae8 100644 --- a/ginac/utils.h +++ b/ginac/utils.h @@ -243,6 +243,61 @@ const ex & _ex60(void); const numeric & _num120(void); // 120 const ex & _ex120(void); + +// Helper macros for class implementations (mostly useful for trivial classes) + +#define DEFAULT_COPY(classname) \ +void classname::copy(const classname & other) \ +{ \ + inherited::copy(other); \ +} + +#define DEFAULT_DESTROY(classname) \ +void classname::destroy(bool call_parent) \ +{ \ + if (call_parent) \ + inherited::destroy(call_parent); \ +} + +#define DEFAULT_CTORS(classname) \ +classname::classname() : inherited(TINFO_##classname) \ +{ \ + debugmsg(#classname " default constructor", LOGLEVEL_CONSTRUCT); \ +} \ +DEFAULT_COPY(classname) \ +DEFAULT_DESTROY(classname) + +#define DEFAULT_UNARCHIVE(classname) \ +ex classname::unarchive(const archive_node &n, const lst &sym_lst) \ +{ \ + return (new classname(n, sym_lst))->setflag(status_flags::dynallocated); \ +} + +#define DEFAULT_ARCHIVING(classname) \ +classname::classname(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) \ +{ \ + debugmsg(#classname " constructor from archive_node", LOGLEVEL_CONSTRUCT); \ +} \ +DEFAULT_UNARCHIVE(classname) \ +void classname::archive(archive_node &n) const \ +{ \ + inherited::archive(n); \ +} + +#define DEFAULT_COMPARE(classname) \ +int classname::compare_same_type(const basic & other) const \ +{ \ + /* by default, the objects are always identical */ \ + return 0; \ +} + +#define DEFAULT_PRINT(classname, text) \ +void classname::print(std::ostream & os, unsigned upper_precedence) const \ +{ \ + debugmsg(#classname " print", LOGLEVEL_PRINT); \ + os << text; \ +} + } // namespace GiNaC #endif // ndef __GINAC_UTILS_H__