SCalc::FuncDef Class Referenceabstract

A function definition with any number of parameters. More...

`#include <functions.hh>`

Inheritance diagram for SCalc::FuncDef:
[legend]
Collaboration diagram for SCalc::FuncDef:
[legend]

## 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 ()
Public Member Functions inherited from SCalc::ParserResult
| ParserResult (Session *s)
| Constructors/desctructors:
Session * | session ()
| The SCalc::Session object used. More...
virtual int | is_expression ()
| Is it a SCalc::Expression ? More...
Expression * | to_expression ()
| Converts to SCalc::Expression. More...
virtual int | is_syntax_error ()
| Is it a SCalc::SyntaxError ? More...
SyntaxError * | to_syntax_error ()
| Converts to SCalc::SyntaxError. More...
FuncDef * | to_func_def ()
| Converts to SCalc::FuncDef. More...

## 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

## Detailed Description

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:

- SCalc::ExprFunc is an expression-based function definition, such as the one in the above example;
- SCalc::CFunc points to a function written in C. They have to be created manually. Unless you provide a derivative using SCalc::CFunc::set_derivative(), it will not be possible to derive them (returns systematically 0).

## Member Function Documentation

## can_delete()

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.

## evaluate()

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::ExprFunc, SCalc::CFuncParam, and SCalc::CFunc.

## set_name()

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.

## Member Data Documentation

## _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().

The documentation for this class was generated from the following file:

- lib/functions.hh

SCalc::FuncDef
A function definition with any number of parameters.
Definition: functions.hh:39
SCalc::Session
A class representing a whole session.
Definition: session.hh:75
SCalc::Session::eval
ParserResult * eval(const char *)
Evaluates a string.