From: Christian Bauer Date: Fri, 16 Feb 2001 20:25:47 +0000 (+0000) Subject: GINAC_DECLARE_REGISTERED_CLASS declares duplicate() and compare_same_type(), X-Git-Tag: release_0-7-2~4 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=1bd972bf8e4eeeb8aec6081100876e81a7f18450 GINAC_DECLARE_REGISTERED_CLASS declares duplicate() and compare_same_type(), GINAC_IMPLEMENT_REGISTERED_CLASS implements duplicate() --- diff --git a/ginac/add.cpp b/ginac/add.cpp index 574a8e8e..9cc2cc01 100644 --- a/ginac/add.cpp +++ b/ginac/add.cpp @@ -157,12 +157,6 @@ void add::archive(archive_node &n) const // public -basic * add::duplicate() const -{ - debugmsg("add duplicate",LOGLEVEL_DUPLICATE); - return new add(*this); -} - void add::print(std::ostream & os, unsigned upper_precedence) const { debugmsg("add print",LOGLEVEL_PRINT); diff --git a/ginac/add.h b/ginac/add.h index 924eb407..0c8e37ca 100644 --- a/ginac/add.h +++ b/ginac/add.h @@ -49,7 +49,6 @@ public: // functions overriding virtual functions from bases classes public: - basic * duplicate() const; void print(std::ostream & os, unsigned upper_precedence=0) const; void printraw(std::ostream & os) const; void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence=0) const; @@ -67,7 +66,6 @@ public: ex simplify_ncmul(const exvector & v) const; protected: ex derivative(const symbol & s) const; - int compare_same_type(const basic & other) const; bool is_equal_same_type(const basic & other) const; unsigned return_type(void) const; unsigned return_type_tinfo(void) const; diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp index c3c0d9f3..0dc0518d 100644 --- a/ginac/clifford.cpp +++ b/ginac/clifford.cpp @@ -114,12 +114,6 @@ void clifford::archive(archive_node &n) const // public -basic * clifford::duplicate() const -{ - debugmsg("clifford duplicate",LOGLEVEL_DUPLICATE); - return new clifford(*this); -} - void clifford::printraw(std::ostream & os) const { debugmsg("clifford printraw",LOGLEVEL_PRINT); diff --git a/ginac/clifford.h b/ginac/clifford.h index 2d02ebcb..aed2b166 100644 --- a/ginac/clifford.h +++ b/ginac/clifford.h @@ -50,14 +50,12 @@ public: // functions overriding virtual functions from base classes public: - basic * duplicate() const; void printraw(std::ostream & os) const; void printtree(std::ostream & os, unsigned indent) const; void print(std::ostream & os, unsigned upper_precedence=0) const; bool info(unsigned inf) const; // ex eval(int level=0) const; protected: - int compare_same_type(const basic & other) const; bool is_equal_same_type(const basic & other) const; ex simplify_ncmul(const exvector & v) const; ex thisexprseq(const exvector & v) const; diff --git a/ginac/color.cpp b/ginac/color.cpp index 4b59877a..f2360c3d 100644 --- a/ginac/color.cpp +++ b/ginac/color.cpp @@ -181,12 +181,6 @@ void color::archive(archive_node &n) const // public -basic * color::duplicate() const -{ - debugmsg("color duplicate",LOGLEVEL_DUPLICATE); - return new color(*this); -} - void color::printraw(std::ostream & os) const { debugmsg("color printraw",LOGLEVEL_PRINT); diff --git a/ginac/color.h b/ginac/color.h index 2d44aa8f..6f126a34 100644 --- a/ginac/color.h +++ b/ginac/color.h @@ -106,14 +106,12 @@ protected: // functions overriding virtual functions from base classes public: - basic * duplicate() const; void printraw(std::ostream & os) const; void printtree(std::ostream & os, unsigned indent) const; void print(std::ostream & os, unsigned upper_precedence=0) const; bool info(unsigned inf) const; ex eval(int level=0) const; protected: - int compare_same_type(const basic & other) const; bool is_equal_same_type(const basic & other) const; ex simplify_ncmul(const exvector & v) const; ex thisexprseq(const exvector & v) const; diff --git a/ginac/coloridx.cpp b/ginac/coloridx.cpp index 221e86b6..d034ba48 100644 --- a/ginac/coloridx.cpp +++ b/ginac/coloridx.cpp @@ -138,12 +138,6 @@ void coloridx::archive(archive_node &n) const // public -basic * coloridx::duplicate() const -{ - debugmsg("coloridx duplicate",LOGLEVEL_DUPLICATE); - return new coloridx(*this); -} - void coloridx::printraw(std::ostream & os) const { debugmsg("coloridx printraw",LOGLEVEL_PRINT); @@ -213,6 +207,11 @@ bool coloridx::info(unsigned inf) const 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 diff --git a/ginac/coloridx.h b/ginac/coloridx.h index 780aac42..a727b912 100644 --- a/ginac/coloridx.h +++ b/ginac/coloridx.h @@ -54,7 +54,6 @@ public: // functions overriding virtual functions from bases classes public: - basic * duplicate() const; void printraw(std::ostream & os) const; void printtree(std::ostream & os, unsigned indent) const; void print(std::ostream & os, unsigned upper_precedence=0) const; diff --git a/ginac/constant.cpp b/ginac/constant.cpp index ae71579c..bc1179c5 100644 --- a/ginac/constant.cpp +++ b/ginac/constant.cpp @@ -129,12 +129,6 @@ void constant::archive(archive_node &n) const // public -basic * constant::duplicate() const -{ - debugmsg("constant duplicate",LOGLEVEL_DUPLICATE); - return new constant(*this); -} - void constant::print(std::ostream & os, unsigned upper_precedence) const { debugmsg("constant print",LOGLEVEL_PRINT); diff --git a/ginac/constant.h b/ginac/constant.h index 0c9394f8..cf31814f 100644 --- a/ginac/constant.h +++ b/ginac/constant.h @@ -49,7 +49,6 @@ public: // functions overriding virtual functions from bases classes public: - basic * duplicate() const; void print(std::ostream & os, unsigned upper_precedence=0) const; void printraw(std::ostream & os) const; void printtree(std::ostream & os, unsigned indent) const; @@ -57,7 +56,6 @@ public: ex evalf(int level=0) const; protected: ex derivative(const symbol & s) const; - int compare_same_type(const basic & other) const; bool is_equal_same_type(const basic & other) const; // new virtual functions which can be overridden by derived classes diff --git a/ginac/container.pl b/ginac/container.pl index 232d299c..d2c5bb44 100755 --- a/ginac/container.pl +++ b/ginac/container.pl @@ -206,7 +206,6 @@ public: ${constructors_interface} public: - basic * duplicate() const; void printraw(std::ostream & os) const; void print(std::ostream & os, unsigned upper_precedence=0) const; void printtree(std::ostream & os, unsigned indent) const; @@ -221,7 +220,6 @@ public: ex derivative(const symbol & s) const; ex subs(const lst & ls, const lst & lr) const; protected: - int compare_same_type(const basic & other) const; bool is_equal_same_type(const basic & other) const; unsigned return_type(void) const; @@ -414,12 +412,6 @@ void ${CONTAINER}::archive(archive_node &n) const // public -basic * ${CONTAINER}::duplicate() const -{ - debugmsg("${CONTAINER} duplicate",LOGLEVEL_DUPLICATE); - return new ${CONTAINER}(*this); -} - void ${CONTAINER}::printraw(std::ostream & os) const { debugmsg("${CONTAINER} printraw",LOGLEVEL_PRINT); diff --git a/ginac/fail.cpp b/ginac/fail.cpp index c1118040..0bbe01c6 100644 --- a/ginac/fail.cpp +++ b/ginac/fail.cpp @@ -82,12 +82,6 @@ void fail::archive(archive_node &n) const // public -basic * fail::duplicate() const -{ - debugmsg("fail duplicate",LOGLEVEL_DUPLICATE); - return new fail(*this); -} - void fail::print(std::ostream & os, unsigned upper_precedence) const { debugmsg("fail print",LOGLEVEL_PRINT); diff --git a/ginac/fail.h b/ginac/fail.h index 248c593c..c2942cc7 100644 --- a/ginac/fail.h +++ b/ginac/fail.h @@ -39,11 +39,9 @@ class fail : public basic // functions overriding virtual functions from bases classes public: - basic * duplicate() const; void print(std::ostream & os, unsigned upper_precedence=0) const; void printraw(std::ostream & os) const; protected: - int compare_same_type(const basic & other) const; unsigned return_type(void) const { return return_types::noncommutative_composite; }; // new virtual functions which can be overridden by derived classes diff --git a/ginac/function.pl b/ginac/function.pl index 8a96a329..de453fe5 100755 --- a/ginac/function.pl +++ b/ginac/function.pl @@ -398,7 +398,6 @@ $constructors_interface // functions overriding virtual functions from bases classes public: - basic * duplicate() const; void printraw(std::ostream & os) const; void print(std::ostream & os, unsigned upper_precedence=0) const; void printtree(std::ostream & os, unsigned indent) const; @@ -411,7 +410,6 @@ public: ex thisexprseq(exvector * vp) const; protected: ex derivative(const symbol & s) const; - int compare_same_type(const basic & other) const; bool is_equal_same_type(const basic & other) const; unsigned return_type(void) const; unsigned return_type_tinfo(void) const; @@ -715,12 +713,6 @@ void function::archive(archive_node &n) const // public -basic * function::duplicate() const -{ - debugmsg("function duplicate",LOGLEVEL_DUPLICATE); - return new function(*this); -} - void function::printraw(std::ostream & os) const { debugmsg("function printraw",LOGLEVEL_PRINT); diff --git a/ginac/idx.cpp b/ginac/idx.cpp index af463a80..480da0f2 100644 --- a/ginac/idx.cpp +++ b/ginac/idx.cpp @@ -170,12 +170,6 @@ void idx::archive(archive_node &n) const // public -basic * idx::duplicate() const -{ - debugmsg("idx duplicate",LOGLEVEL_DUPLICATE); - return new idx(*this); -} - void idx::printraw(std::ostream & os) const { debugmsg("idx printraw",LOGLEVEL_PRINT); @@ -268,7 +262,7 @@ ex idx::subs(const lst & ls, const lst & lr) const int idx::compare_same_type(const basic & other) const { GINAC_ASSERT(is_of_type(other,idx)); - const idx &o = static_cast(&other); + const idx &o = static_cast(other); if (covariant!=o.covariant) { // different co/contravariant diff --git a/ginac/idx.h b/ginac/idx.h index 981fee68..3c8ec34e 100644 --- a/ginac/idx.h +++ b/ginac/idx.h @@ -49,13 +49,11 @@ public: // functions overriding virtual functions from bases classes public: - basic * duplicate() const; void printraw(std::ostream & os) const; void printtree(std::ostream & os, unsigned indent) const; void print(std::ostream & os, unsigned upper_precedence=0) const; bool info(unsigned inf) const; protected: - int compare_same_type(const basic & other) const; bool is_equal_same_type(const basic & other) const; unsigned calchash(void) const; ex subs(const lst & ls, const lst & lr) const; diff --git a/ginac/indexed.cpp b/ginac/indexed.cpp index 7127e9a4..be4a7cb7 100644 --- a/ginac/indexed.cpp +++ b/ginac/indexed.cpp @@ -169,12 +169,6 @@ void indexed::archive(archive_node &n) const // public -basic * indexed::duplicate() const -{ - debugmsg("indexed duplicate",LOGLEVEL_DUPLICATE); - return new indexed(*this); -} - void indexed::printraw(std::ostream & os) const { debugmsg("indexed printraw",LOGLEVEL_PRINT); diff --git a/ginac/indexed.h b/ginac/indexed.h index b1d8844a..cc604f13 100644 --- a/ginac/indexed.h +++ b/ginac/indexed.h @@ -47,7 +47,6 @@ public: // functions overriding virtual functions from base classes public: - basic * duplicate() const; void printraw(std::ostream & os) const; void printtree(std::ostream & os, unsigned indent) const; void print(std::ostream & os, unsigned upper_precedence=0) const; @@ -59,7 +58,6 @@ public: protected: ex derivative(const symbol & s) const; - int compare_same_type(const basic & other) const; bool is_equal_same_type(const basic & other) const; unsigned return_type(void) const; unsigned return_type_tinfo(void) const; diff --git a/ginac/isospin.cpp b/ginac/isospin.cpp index a74e05f7..1be79d59 100644 --- a/ginac/isospin.cpp +++ b/ginac/isospin.cpp @@ -121,12 +121,6 @@ void isospin::archive(archive_node &n) const // public -basic * isospin::duplicate() const -{ - debugmsg("isospin duplicate",LOGLEVEL_DUPLICATE); - return new isospin(*this); -} - void isospin::printraw(std::ostream & os) const { debugmsg("isospin printraw",LOGLEVEL_PRINT); diff --git a/ginac/isospin.h b/ginac/isospin.h index 3facb90b..d9d93a84 100644 --- a/ginac/isospin.h +++ b/ginac/isospin.h @@ -41,14 +41,12 @@ public: // functions overriding virtual functions from base classes public: - basic * duplicate() const; void printraw(std::ostream & os) const; void printtree(std::ostream & os, unsigned indent) const; void print(std::ostream & os, unsigned upper_precedence=0) const; void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence=0) const; bool info(unsigned inf) const; protected: - int compare_same_type(const basic & other) const; ex simplify_ncmul(const exvector & v) const; unsigned calchash(void) const; diff --git a/ginac/lorentzidx.cpp b/ginac/lorentzidx.cpp index 6a367be6..ca88d94a 100644 --- a/ginac/lorentzidx.cpp +++ b/ginac/lorentzidx.cpp @@ -171,12 +171,6 @@ void lorentzidx::archive(archive_node &n) const // public -basic * lorentzidx::duplicate() const -{ - debugmsg("lorentzidx duplicate",LOGLEVEL_DUPLICATE); - return new lorentzidx(*this); -} - void lorentzidx::printraw(std::ostream & os) const { debugmsg("lorentzidx printraw",LOGLEVEL_PRINT); @@ -260,6 +254,18 @@ bool lorentzidx::info(unsigned inf) const return inherited::info(inf); } +int lorentzidx::compare_same_type(const basic & other) const +{ + GINAC_ASSERT(is_of_type(other, lorentzidx)); + const lorentzidx &o = static_cast(other); + + if (orthogonal_only != o.orthogonal_only) + return orthogonal_only ? -1 : 1; + if (dim_parallel_space != o.dim_parallel_space) + return dim_parallel_space < o.dim_parallel_space ? -1 : 1; + return inherited::compare_same_type(other); +} + ////////// // non-virtual functions in this class ////////// diff --git a/ginac/lorentzidx.h b/ginac/lorentzidx.h index 099f36b5..20be2b50 100644 --- a/ginac/lorentzidx.h +++ b/ginac/lorentzidx.h @@ -59,7 +59,6 @@ public: // functions overriding virtual functions from bases classes public: - basic * duplicate() const; void printraw(std::ostream & os) const; void printtree(std::ostream & os, unsigned indent) const; void print(std::ostream & os, unsigned upper_precedence=0) const; diff --git a/ginac/lortensor.cpp b/ginac/lortensor.cpp index 7a97887a..6c326e2b 100644 --- a/ginac/lortensor.cpp +++ b/ginac/lortensor.cpp @@ -238,12 +238,6 @@ void lortensor::archive(archive_node &n) const //public -basic * lortensor::duplicate() const -{ - debugmsg("lortensor duplicate",LOGLEVEL_DUPLICATE); - return new lortensor(*this); -} - void lortensor::printraw(std::ostream & os) const { debugmsg("lortensor printraw",LOGLEVEL_PRINT); diff --git a/ginac/lortensor.h b/ginac/lortensor.h index d25211fe..8da739d8 100644 --- a/ginac/lortensor.h +++ b/ginac/lortensor.h @@ -80,14 +80,12 @@ protected: //functions overriding virtual functions from base classes public: - basic * duplicate() const; void printraw(std::ostream & os) const; void printtree(std::ostream & os, unsigned indent) const; void print(std::ostream & os, unsigned upper_precedence=0) const; bool info(unsigned inf) const; ex eval(int level=0) const; protected: - int compare_same_type(const basic & other) const; bool is_equal_same_type(const basic & other) const; unsigned return_type(void) const; unsigned return_type_tinfo(void) const; diff --git a/ginac/matrix.cpp b/ginac/matrix.cpp index 0b87ed5d..81d31bdb 100644 --- a/ginac/matrix.cpp +++ b/ginac/matrix.cpp @@ -140,12 +140,6 @@ void matrix::archive(archive_node &n) const // public -basic * matrix::duplicate() const -{ - debugmsg("matrix duplicate",LOGLEVEL_DUPLICATE); - return new matrix(*this); -} - void matrix::print(std::ostream & os, unsigned upper_precedence) const { debugmsg("matrix print",LOGLEVEL_PRINT); diff --git a/ginac/matrix.h b/ginac/matrix.h index 7c2b9c01..c04a592e 100644 --- a/ginac/matrix.h +++ b/ginac/matrix.h @@ -43,7 +43,6 @@ public: // functions overriding virtual functions from bases classes public: - basic * duplicate() const; void print(std::ostream & os, unsigned upper_precedence=0) const; void printraw(std::ostream & os) const; unsigned nops() const; @@ -55,7 +54,6 @@ public: ex evalf(int level=0) const; // ex subs(const lst & ls, const lst & lr) const; protected: - int compare_same_type(const basic & other) const; unsigned return_type(void) const { return return_types::noncommutative; }; // new virtual functions which can be overridden by derived classes // (none) diff --git a/ginac/mul.cpp b/ginac/mul.cpp index 80901d77..02029c54 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -155,12 +155,6 @@ void mul::archive(archive_node &n) const // public -basic * mul::duplicate() const -{ - debugmsg("mul duplicate",LOGLEVEL_ASSIGNMENT); - return new mul(*this); -} - void mul::print(std::ostream & os, unsigned upper_precedence) const { debugmsg("mul print",LOGLEVEL_PRINT); diff --git a/ginac/mul.h b/ginac/mul.h index c6d607db..cad3b9b3 100644 --- a/ginac/mul.h +++ b/ginac/mul.h @@ -49,7 +49,6 @@ public: // functions overriding virtual functions from bases classes public: - basic * duplicate() const; void print(std::ostream & os, unsigned upper_precedence) const; void printraw(std::ostream & os) const; void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const; @@ -68,7 +67,6 @@ public: ex simplify_ncmul(const exvector & v) const; protected: ex derivative(const symbol & s) const; - int compare_same_type(const basic & other) const; bool is_equal_same_type(const basic & other) const; unsigned return_type(void) const; unsigned return_type_tinfo(void) const; diff --git a/ginac/ncmul.cpp b/ginac/ncmul.cpp index 86b76e71..86501111 100644 --- a/ginac/ncmul.cpp +++ b/ginac/ncmul.cpp @@ -142,12 +142,6 @@ void ncmul::archive(archive_node &n) const // public -basic * ncmul::duplicate() const -{ - debugmsg("ncmul duplicate",LOGLEVEL_ASSIGNMENT); - return new ncmul(*this); -} - void ncmul::print(std::ostream & os, unsigned upper_precedence) const { debugmsg("ncmul print",LOGLEVEL_PRINT); diff --git a/ginac/ncmul.h b/ginac/ncmul.h index a4a77eb0..5373a75b 100644 --- a/ginac/ncmul.h +++ b/ginac/ncmul.h @@ -55,7 +55,6 @@ public: // functions overriding virtual functions from bases classes public: - basic * duplicate() const; void print(std::ostream & os, unsigned upper_precedence) const; void printraw(std::ostream & os) const; void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence = 0) const; @@ -71,7 +70,6 @@ public: ex thisexprseq(exvector * vp) const; protected: ex derivative(const symbol & s) const; - int compare_same_type(const basic & other) const; unsigned return_type(void) const; unsigned return_type_tinfo(void) const; diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp index 3398f60d..358ad45d 100644 --- a/ginac/numeric.cpp +++ b/ginac/numeric.cpp @@ -381,15 +381,6 @@ void numeric::archive(archive_node &n) const // functions overriding virtual functions from bases classes ////////// -// public - -basic * numeric::duplicate() const -{ - debugmsg("numeric duplicate", LOGLEVEL_DUPLICATE); - return new numeric(*this); -} - - /** Helper function to print a real number in a nicer way than is CLN's * default. Instead of printing 42.0L0 this just prints 42.0 to ostream os * and instead of 3.99168L7 it prints 3.99168E7. This is fine in GiNaC as diff --git a/ginac/numeric.h b/ginac/numeric.h index 1eda94d4..3a972bc9 100644 --- a/ginac/numeric.h +++ b/ginac/numeric.h @@ -87,7 +87,6 @@ public: // functions overriding virtual functions from bases classes public: - basic * duplicate() const; void print(std::ostream & os, unsigned precedence=0) const; void printraw(std::ostream & os) const; void printtree(std::ostream & os, unsigned indent) const; @@ -103,7 +102,6 @@ public: numeric max_coefficient(void) const; protected: ex derivative(const symbol & s) const; - int compare_same_type(const basic & other) const; bool is_equal_same_type(const basic & other) const; unsigned calchash(void) const; diff --git a/ginac/power.cpp b/ginac/power.cpp index 30697335..7324ca97 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -119,12 +119,6 @@ void power::archive(archive_node &n) const // public -basic * power::duplicate() const -{ - debugmsg("power duplicate",LOGLEVEL_DUPLICATE); - return new power(*this); -} - void power::print(std::ostream & os, unsigned upper_precedence) const { debugmsg("power print",LOGLEVEL_PRINT); diff --git a/ginac/power.h b/ginac/power.h index 65c86b7e..24e46f88 100644 --- a/ginac/power.h +++ b/ginac/power.h @@ -50,7 +50,6 @@ public: // functions overriding virtual functions from bases classes public: - basic * duplicate() const; void print(std::ostream & os, unsigned upper_precedence = 0) const; void printraw(std::ostream & os) const; void printtree(std::ostream & os, unsigned indent) const; @@ -70,7 +69,6 @@ public: ex simplify_ncmul(const exvector & v) const; protected: ex derivative(const symbol & s) const; - int compare_same_type(const basic & other) const; unsigned return_type(void) const; unsigned return_type_tinfo(void) const; ex expand(unsigned options = 0) const; diff --git a/ginac/pseries.cpp b/ginac/pseries.cpp index d447aaa6..2d873a26 100644 --- a/ginac/pseries.cpp +++ b/ginac/pseries.cpp @@ -132,12 +132,6 @@ void pseries::archive(archive_node &n) const // functions overriding virtual functions from bases classes ////////// -basic *pseries::duplicate() const -{ - debugmsg("pseries duplicate", LOGLEVEL_DUPLICATE); - return new pseries(*this); -} - void pseries::print(std::ostream &os, unsigned upper_precedence) const { debugmsg("pseries print", LOGLEVEL_PRINT); @@ -207,6 +201,31 @@ void pseries::printtree(std::ostream & os, unsigned indent) const point.printtree(os, indent+delta_indent); } +int pseries::compare_same_type(const basic & other) const +{ + GINAC_ASSERT(is_of_type(other, pseries)); + const pseries &o = static_cast(other); + + int cmpval = var.compare(o.var); + if (cmpval) + return cmpval; + cmpval = point.compare(o.point); + if (cmpval) + return cmpval; + + epvector::const_iterator it1 = seq.begin(), it2 = o.seq.begin(), it1end = seq.end(), it2end = o.seq.end(); + while ((it1 != it1end) && (it2 != it2end)) { + cmpval = it1->compare(*it2); + if (cmpval) + return cmpval; + it1++; it2++; + } + if (it1 == it1end) + return it2 == it2end ? 0 : -1; + + return 0; +} + /** Return the number of operands including a possible order term. */ unsigned pseries::nops(void) const { diff --git a/ginac/pseries.h b/ginac/pseries.h index 14b011af..95d85b28 100644 --- a/ginac/pseries.h +++ b/ginac/pseries.h @@ -44,7 +44,6 @@ public: // functions overriding virtual functions from base classes public: - basic *duplicate() const; void print(std::ostream &os, unsigned upper_precedence = 0) const; void printraw(std::ostream &os) const; void printtree(std::ostream & os, unsigned indent) const; @@ -85,6 +84,7 @@ protected: /** Expansion point */ ex point; + static unsigned precedence; }; diff --git a/ginac/registrar.h b/ginac/registrar.h index f665ccd8..2737325b 100644 --- a/ginac/registrar.h +++ b/ginac/registrar.h @@ -70,7 +70,10 @@ public: \ virtual void archive(archive_node &n) const; \ static ex unarchive(const archive_node &n, const lst &sym_lst); -/** Macro for inclusion in the declaration of each registered class. */ +/** Macro for inclusion in the declaration of each registered class. + * It declares some functions that are common to all classes derived + * from 'basic' as well as all required stuff for the GiNaC class + * registry (mainly needed for archiving). */ #define GINAC_DECLARE_REGISTERED_CLASS(classname, supername) \ GINAC_DECLARE_REGISTERED_CLASS_NO_CTORS(classname, supername) \ public: \ @@ -78,16 +81,21 @@ public: \ ~classname(); \ classname(const classname & other); \ const classname & operator=(const classname & other); \ + basic * duplicate() const; \ protected: \ void copy(const classname & other); \ void destroy(bool call_parent); \ + int compare_same_type(const basic & other) const; \ private: #define GINAC_IMPLEMENT_REGISTERED_CLASS_NO_CTORS(classname, supername) \ registered_class_info classname::reg_info(#classname, #supername, TINFO_##classname, &classname::unarchive); \ const char *classname::class_name(void) const {return reg_info.name;} -/** Macro for inclusion in the implementation of each registered class. */ +/** Macro for inclusion in the implementation of each registered class. + * It implements some functions that are the same in all classes derived + * from 'basic' (such as the destructor, the copy constructor and the + * assignment operator). */ #define GINAC_IMPLEMENT_REGISTERED_CLASS(classname, supername) \ GINAC_IMPLEMENT_REGISTERED_CLASS_NO_CTORS(classname, supername) \ classname::~classname() \ @@ -108,8 +116,14 @@ const classname & classname::operator=(const classname & other) \ copy(other); \ } \ return *this; \ +} \ +basic * classname::duplicate() const \ +{ \ + debugmsg(#classname " duplicate", LOGLEVEL_DUPLICATE); \ + return new classname(*this); \ } + /** Find TINFO_* key by class name. */ extern unsigned int find_tinfo_key(const std::string &class_name); diff --git a/ginac/relational.cpp b/ginac/relational.cpp index c8b50431..8f7b4b65 100644 --- a/ginac/relational.cpp +++ b/ginac/relational.cpp @@ -111,12 +111,6 @@ void relational::archive(archive_node &n) const // public -basic * relational::duplicate() const -{ - debugmsg("relational duplicate",LOGLEVEL_DUPLICATE); - return new relational(*this); -} - void relational::print(std::ostream & os, unsigned upper_precedence) const { debugmsg("relational print",LOGLEVEL_PRINT); diff --git a/ginac/relational.h b/ginac/relational.h index 5a9fe443..c988a631 100644 --- a/ginac/relational.h +++ b/ginac/relational.h @@ -53,7 +53,6 @@ public: // functions overriding virtual functions from bases classes public: - basic * duplicate() const; void print(std::ostream & os, unsigned upper_precedence=0) const; void printraw(std::ostream & os) const; void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence=0) const; @@ -65,7 +64,6 @@ public: ex normal(lst &sym_lst, lst &repl_lst, int level=0) const; ex simplify_ncmul(const exvector & v) const; protected: - int compare_same_type(const basic & other) const; unsigned return_type(void) const; unsigned return_type_tinfo(void) const; diff --git a/ginac/simp_lor.cpp b/ginac/simp_lor.cpp index 23bd24a3..3454b5a0 100644 --- a/ginac/simp_lor.cpp +++ b/ginac/simp_lor.cpp @@ -149,12 +149,6 @@ void simp_lor::archive(archive_node &n) const // public -basic * simp_lor::duplicate() const -{ - debugmsg("simp_lor duplicate",LOGLEVEL_DUPLICATE); - return new simp_lor(*this); -} - void simp_lor::printraw(std::ostream & os) const { debugmsg("simp_lor printraw",LOGLEVEL_PRINT); diff --git a/ginac/simp_lor.h b/ginac/simp_lor.h index d76f6c56..4b4e239c 100644 --- a/ginac/simp_lor.h +++ b/ginac/simp_lor.h @@ -99,7 +99,6 @@ protected: // functions overriding virtual functions from base classes public: - basic * duplicate() const; void printraw(std::ostream & os) const; void printtree(std::ostream & os, unsigned indent) const; void print(std::ostream & os, unsigned upper_precedence=0) const; @@ -107,7 +106,6 @@ public: bool info(unsigned inf) const; ex eval(int level=0) const; protected: - int compare_same_type(const basic & other) const; bool is_equal_same_type(const basic & other) const; unsigned return_type(void) const; unsigned return_type_tinfo(void) const; diff --git a/ginac/structure.cpp b/ginac/structure.cpp index 4aa4f10c..39c09bf1 100644 --- a/ginac/structure.cpp +++ b/ginac/structure.cpp @@ -90,12 +90,6 @@ void structure::archive(archive_node &n) const // public -basic * structure::duplicate() const -{ - debugmsg("structure duplicate",LOGLEVEL_DUPLICATE); - return new structure(*this); -} - void structure::printraw(std::ostream & os) const { debugmsg("structure printraw",LOGLEVEL_PRINT); diff --git a/ginac/structure.h b/ginac/structure.h index 6c540033..365f5691 100644 --- a/ginac/structure.h +++ b/ginac/structure.h @@ -48,13 +48,11 @@ class structure : public basic // functions overriding virtual functions from bases classes public: - basic * duplicate() const; void printraw(std::ostream & os) const; void print(std::ostream & os, unsigned upper_precedence=0) const; void printtree(std::ostream & os, unsigned indent) const; void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence=0) const; protected: - int compare_same_type(const basic & other) const; bool is_equal_same_type(const basic & other) const; // new virtual functions which can be overridden by derived classes