SCalc
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
SCalc::FuncDef Class Referenceabstract

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

#include <functions.hh>

Inheritance diagram for SCalc::FuncDef:
Inheritance graph
[legend]
Collaboration diagram for SCalc::FuncDef:
Collaboration graph
[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 FuncDefderivative (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:
 
Sessionsession ()
 The SCalc::Session object used. More...
 
virtual int is_expression ()
 Is it a SCalc::Expression ? More...
 
Expressionto_expression ()
 Converts to SCalc::Expression. More...
 
virtual int is_syntax_error ()
 Is it a SCalc::SyntaxError ? More...
 
SyntaxErrorto_syntax_error ()
 Converts to SCalc::SyntaxError. More...
 
FuncDefto_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::FuncDef * funcdef = sess.eval("f : x-> x** 2 + 1");

There are different kind of functions:

Member Function Documentation

◆ can_delete()

virtual int SCalc::FuncDef::can_delete ( )
inlinevirtual

We can delete this function freely unless it has a name – that is, unless it is registered.

Reimplemented from SCalc::ParserResult.

◆ 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.

Referenced by set_name().

◆ 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, derivative(), evaluate(), and register_common_functions().

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 set_name().


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