A function definition with any number of parameters. More...
#include <functions.hh>
Public Member Functions | |
FuncDef (Session *s, int nb) | |
virtual int | is_func_def () |
Yes, this is a function definition. | |
virtual std::string | pretty_print () |
Pretty printing of the result ? | |
int | register_self () |
Register the function to the session if it has a name. | |
int | nb_params () |
The number of params the function takes. | |
void | set_name (const char *name) |
std::string | name () |
virtual double | evaluate (const double *vars, const double *args)=0 |
virtual FuncDef * | derivative (int nb)=0 |
The derivative with regards to the argument nb. | |
virtual void | destroy_anonymous_derivatives () |
Delete the derivative if anonymous. | |
virtual int | can_delete () |
Static Public Member Functions | |
static void | register_common_functions (Session *sess) |
This function registers common functions to the given session. | |
Protected Attributes | |
int | _nb_params |
std::string | _name |
A function definition with any number of parameters.
The FuncDef class represents a function definition. A function can have any number of parameters. A typical way to create a function definition is the following:
SCalc::Session sess; SCalc::FuncDef * funcdef = sess.eval("f : x-> x** 2 + 1");
There are different kind of functions:
virtual int SCalc::FuncDef::can_delete | ( | ) | [inline, virtual] |
We can delete this function freely unless it has a name -- that is, unless it is registered.
Reimplemented from SCalc::ParserResult.
References _name.
virtual double SCalc::FuncDef::evaluate | ( | const double * | vars, | |
const double * | args | |||
) | [pure virtual] |
Evaluate the function; first argument is the undefined variables second is the actual function arguments.
Implemented in SCalc::CFunc, SCalc::CFuncParam, and SCalc::ExprFunc.
void SCalc::FuncDef::set_name | ( | const char * | name | ) | [inline] |
Set the name of the function. (does not register it). Be careful, as setting the name to a function and not registering it soon will cause memory leaks.
References _name.
std::string SCalc::FuncDef::_name [protected] |
The name is something particularly important. FuncDefs split themselves into two categories: anonymous functions, that probably should be disposed of after use; (when to determine this is something tricky...). named functions, which *should* be registered to the session.
Referenced by can_delete(), and set_name().