]> www.ginac.de Git - ginac.git/blobdiff - ginac/function.pl
- do something about the mad cast disease.
[ginac.git] / ginac / function.pl
index 7d45d6d449dec417dd3d96d5c2f0b32de5075edd..c3dbcd6f3bb3db8d74806eef325fe8a5ecd54438 100755 (executable)
@@ -212,19 +212,11 @@ $declare_function_macro
 const unsigned function_index_##NAME= \\
        GiNaC::function::register_new(GiNaC::function_options(#NAME).OPT);
 
-#define REGISTER_FUNCTION_OLD(NAME,E,EF,D,S) \\
-const unsigned function_index_##NAME= \\
-       GiNaC::function::register_new(GiNaC::function_options(#NAME). \\
-                                     eval_func(E). \\
-                                     evalf_func(EF). \\
-                                     derivative_func(D). \\
-                                     series_func(S));
-
 #define BEGIN_TYPECHECK \\
 bool automatic_typecheck=true;
 
 #define TYPECHECK(VAR,TYPE) \\
-if (!is_ex_exactly_of_type(VAR,TYPE)) { \\
+if (!is_exactly_a<TYPE>(VAR)) { \\
        automatic_typecheck=false; \\
 } else
 
@@ -379,11 +371,19 @@ protected:
 };
 
 // utility functions/macros
+/** Return the object of type function handled by an ex.
+ *  This is unsafe: you need to check the type first. */
 inline const function &ex_to_function(const ex &e)
 {
        return static_cast<const function &>(*e.bp);
 }
 
+/** Specialization of is_exactly_a<function>(obj) for objects of type function. */
+template<> inline bool is_exactly_a<function>(const basic & obj)
+{
+       return obj.tinfo()==TINFO_function;
+}
+
 #define is_ex_the_function(OBJ, FUNCNAME) \\
        (is_ex_exactly_of_type(OBJ, function) && static_cast<GiNaC::function *>(OBJ.bp)->get_serial() == function_index_##FUNCNAME)
 
@@ -737,7 +737,7 @@ ex function::eval(int level) const
        if (seq.size() > 1 && !(opt.symtree.is_zero())) {
                exvector v = seq;
                GINAC_ASSERT(is_ex_exactly_of_type(opt.symtree, symmetry));
-               int sig = canonicalize(v.begin(), ex_to_symmetry(opt.symtree));
+               int sig = canonicalize(v.begin(), ex_to<symmetry>(opt.symtree));
                if (sig != INT_MAX) {
                        // Something has changed while sorting arguments, more evaluations later
                        if (sig == 0)
@@ -832,7 +832,7 @@ ${series_switch_statement}
 bool function::match(const ex & pattern, lst & repl_lst) const
 {
        // Serial number must match
-       if (is_ex_of_type(pattern, function) && serial != ex_to_function(pattern).serial)
+       if (is_ex_of_type(pattern, function) && serial != ex_to<function>(pattern).serial)
                return false;
        return inherited::match(pattern, repl_lst);
 }
@@ -860,7 +860,7 @@ ex function::derivative(const symbol & s) const
                for (unsigned i=0; i!=fcn.nops(); i++) {
                        arg_diff = fcn.op(i).diff(s);
                        if (!arg_diff.is_zero()) {
-                               lst new_lst = ex_to_lst(seq[1]);
+                               lst new_lst = ex_to<lst>(seq[1]);
                                new_lst.append(i);
                                result += arg_diff * Derivative(fcn, new_lst);
                        }
@@ -885,7 +885,7 @@ ex function::derivative(const symbol & s) const
 int function::compare_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_of_type(other, function));
-       const function & o=static_cast<function &>(const_cast<basic &>(other));
+       const function & o = static_cast<const function &>(other);
 
        if (serial!=o.serial) {
                return serial < o.serial ? -1 : 1;
@@ -896,7 +896,7 @@ int function::compare_same_type(const basic & other) const
 bool function::is_equal_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_of_type(other, function));
-       const function & o=static_cast<function &>(const_cast<basic &>(other));
+       const function & o = static_cast<const function &>(other);
 
        if (serial!=o.serial) return false;
        return exprseq::is_equal_same_type(o);