From 1b0eb6f8881286b996d8ac906df5dbb4e10215b6 Mon Sep 17 00:00:00 2001 From: Christian Bauer Date: Wed, 16 Oct 2002 20:44:08 +0000 Subject: [PATCH] Redone the way in which function serial numbers are stored. This allows for using namespace qualifiers in the is_ex_the_function() macro like this is_ex_the_function(e, GiNaC::sin); and it also works with the (overloaded) zeta() and psi() functions. Unfortunately, it's not possible to using GiNaC::sin; is_ex_the_function(e, sin); and the is_the_function<> template is not useful outside the is_ex_the_function() macro. Even renaming the 'sin_SERIAL' class to 'sin' (which doesn't seem to work with gcc3) you would still have to write 'is_the_function(e)' instead of 'is_the_function(e)'. I currently see no better solution, though... --- ginac/function.pl | 22 ++++++++++++++-------- ginac/inifcns.cpp | 4 ++-- ginac/inifcns.h | 26 ++++++++++++++++++-------- ginac/inifcns_gamma.cpp | 4 ++-- ginac/inifcns_zeta.cpp | 4 ++-- 5 files changed, 38 insertions(+), 22 deletions(-) diff --git a/ginac/function.pl b/ginac/function.pl index 394f2234..76af1dc9 100755 --- a/ginac/function.pl +++ b/ginac/function.pl @@ -39,10 +39,9 @@ sub generate { $declare_function_macro = generate( <<'END_OF_DECLARE_FUNCTION_MACRO','typename T${N}','const T${N} & p${N}','GiNaC::ex(p${N})'); #define DECLARE_FUNCTION_${N}P(NAME) \\ -extern const unsigned function_index_##NAME; \\ -template<${SEQ1}> \\ -inline const GiNaC::function NAME(${SEQ2}) { \\ - return GiNaC::function(function_index_##NAME, ${SEQ3}); \\ +class NAME##_SERIAL { public: static unsigned serial; }; \\ +template<${SEQ1}> const GiNaC::function NAME(${SEQ2}) { \\ + return GiNaC::function(NAME##_SERIAL::serial, ${SEQ3}); \\ } END_OF_DECLARE_FUNCTION_MACRO @@ -197,7 +196,7 @@ $declare_function_macro // end of generated lines #define REGISTER_FUNCTION(NAME,OPT) \\ -const unsigned function_index_##NAME= \\ +unsigned NAME##_SERIAL::serial = \\ GiNaC::function::register_new(GiNaC::function_options(#NAME).OPT); namespace GiNaC { @@ -364,8 +363,15 @@ template<> inline bool is_exactly_a(const basic & obj) return obj.tinfo()==TINFO_function; } -#define is_ex_the_function(OBJ, FUNCNAME) \\ - (GiNaC::is_exactly_a(OBJ) && GiNaC::ex_to(OBJ).get_serial() == GiNaC::function_index_##FUNCNAME) +template +inline bool is_the_function(const ex & x) +{ + return is_exactly_a(x) + && ex_to(x).get_serial() == T::serial; +} + +// Check whether OBJ is the specified symbolic function. +#define is_ex_the_function(OBJ, FUNCNAME) (GiNaC::is_the_function(OBJ)) } // namespace GiNaC @@ -861,7 +867,7 @@ ex function::derivative(const symbol & s) const { ex result; - if (serial == function_index_Order) { + if (serial == Order_SERIAL::serial) { // Order Term function only differentiates the argument return Order(seq[0].diff(s)); } else { diff --git a/ginac/inifcns.cpp b/ginac/inifcns.cpp index 761a9eac..9739b286 100644 --- a/ginac/inifcns.cpp +++ b/ginac/inifcns.cpp @@ -515,7 +515,7 @@ ex lsolve(const ex &eqns, const ex &symbols, unsigned options) /* Force inclusion of functions from inifcns_gamma and inifcns_zeta * for static lib (so ginsh will see them). */ -unsigned force_include_tgamma = function_index_tgamma; -unsigned force_include_zeta1 = function_index_zeta1; +unsigned force_include_tgamma = tgamma_SERIAL::serial; +unsigned force_include_zeta1 = zeta1_SERIAL::serial; } // namespace GiNaC diff --git a/ginac/inifcns.h b/ginac/inifcns.h index 58b5fa9f..accc7c70 100644 --- a/ginac/inifcns.h +++ b/ginac/inifcns.h @@ -90,16 +90,21 @@ DECLARE_FUNCTION_1P(Li3) // overloading at work: we cannot use the macros here /** Riemann's Zeta-function. */ -extern const unsigned function_index_zeta1; +class zeta1_SERIAL { public: static unsigned serial; }; template inline function zeta(const T1 & p1) { - return function(function_index_zeta1, ex(p1)); + return function(zeta1_SERIAL::serial, ex(p1)); } /** Derivatives of Riemann's Zeta-function. */ -extern const unsigned function_index_zeta2; +class zeta2_SERIAL { public: static unsigned serial; }; template inline function zeta(const T1 & p1, const T2 & p2) { - return function(function_index_zeta2, ex(p1), ex(p2)); + return function(zeta2_SERIAL::serial, ex(p1), ex(p2)); +} +class zeta_SERIAL; +template<> inline bool is_the_function(const ex & x) +{ + return is_the_function(x) || is_the_function(x); } /** Gamma-function. */ @@ -111,16 +116,21 @@ DECLARE_FUNCTION_2P(beta) // overloading at work: we cannot use the macros here /** Psi-function (aka digamma-function). */ -extern const unsigned function_index_psi1; +class psi1_SERIAL { public: static unsigned serial; }; template inline function psi(const T1 & p1) { - return function(function_index_psi1, ex(p1)); + return function(psi1_SERIAL::serial, ex(p1)); } /** Derivatives of Psi-function (aka polygamma-functions). */ -extern const unsigned function_index_psi2; +class psi2_SERIAL { public: static unsigned serial; }; template inline function psi(const T1 & p1, const T2 & p2) { - return function(function_index_psi2, ex(p1), ex(p2)); + return function(psi2_SERIAL::serial, ex(p1), ex(p2)); +} +class psi_SERIAL; +template<> inline bool is_the_function(const ex & x) +{ + return is_the_function(x) || is_the_function(x); } /** Factorial function. */ diff --git a/ginac/inifcns_gamma.cpp b/ginac/inifcns_gamma.cpp index d2e9a6b7..14b9ae87 100644 --- a/ginac/inifcns_gamma.cpp +++ b/ginac/inifcns_gamma.cpp @@ -422,7 +422,7 @@ static ex psi1_series(const ex & arg, return (psi(arg+m+_ex1)-recur).series(rel, order, options); } -const unsigned function_index_psi1 = +unsigned psi1_SERIAL::serial = function::register_new(function_options("psi"). eval_func(psi1_eval). evalf_func(psi1_evalf). @@ -550,7 +550,7 @@ static ex psi2_series(const ex & n, return (psi(n, arg+m+_ex1)-recur).series(rel, order, options); } -const unsigned function_index_psi2 = +unsigned psi2_SERIAL::serial = function::register_new(function_options("psi"). eval_func(psi2_eval). evalf_func(psi2_evalf). diff --git a/ginac/inifcns_zeta.cpp b/ginac/inifcns_zeta.cpp index 45ab0c95..57b94127 100644 --- a/ginac/inifcns_zeta.cpp +++ b/ginac/inifcns_zeta.cpp @@ -84,7 +84,7 @@ static ex zeta1_deriv(const ex & x, unsigned deriv_param) return zeta(_ex1, x); } -const unsigned function_index_zeta1 = +unsigned zeta1_SERIAL::serial = function::register_new(function_options("zeta"). eval_func(zeta1_eval). evalf_func(zeta1_evalf). @@ -119,7 +119,7 @@ static ex zeta2_deriv(const ex & n, const ex & x, unsigned deriv_param) return zeta(n+1,x); } -const unsigned function_index_zeta2 = +unsigned zeta2_SERIAL::serial = function::register_new(function_options("zeta"). eval_func(zeta2_eval). derivative_func(zeta2_deriv). -- 2.49.0