|
| FunctionDefinition (const QString &category, const QString &name, unsigned argc=0, bool variadic=false) |
| Construct a function definition. More...
|
|
| FunctionDefinition (const QString &category, const QString &name, const QString &description, unsigned argc=0, bool variadic=false) |
| Construct a function definition. More...
|
|
virtual | ~FunctionDefinition () |
| Virtual destructor.
|
|
const QString & | category () const |
| Access the function categorisation for UI grouping. More...
|
|
void | setCategory (const QString &category) |
| Set the category name for the function. More...
|
|
const QString & | name () const |
| Access the function name as used by the expression generator. More...
|
|
void | setName (const QString &name) |
| Set the function name as used by the generator. More...
|
|
const QString & | displayName () const |
| Return the function name as displayed with the user. More...
|
|
void | setDisplayName (const QString &name) |
| Set the function name as displayed to the user. More...
|
|
const QString & | description () const |
| Access the function description. More...
|
|
void | setDesciption (const QString &description) |
| Set the function description. More...
|
|
unsigned | argc () const |
| Access the minimum argument count. More...
|
|
void | setArgc (unsigned count) |
| Set the minimum required arguments. More...
|
|
bool | variadic () const |
| Is the function variadic beyond argc() ? More...
|
|
void | setVariadic (bool variadic) |
| Set the variadic flag. More...
|
|
virtual void | evaluate (PlotFunctionResult &result, double time, unsigned int argc, const double *argv, const PlotFunctionInfo &info, void *context) const =0 |
| Evaluate the function with the given context data. More...
|
|
virtual void * | createContext () const |
| Called to create an operating context for calculating function values. More...
|
|
virtual void | destroyContext (void *context) const |
| Destroys the context created by createContext() . More...
|
|
QString | deduceDisplayName () const |
| Deduces the display name of the function to show usage. More...
|
|
Defines a function which can be used with the FunctionRegister
.
The FunctionDefinition
defines the name, category and parameters as well as supporting execution of the function given a particular set of values.
During expression evaluation, a PlotFunction
manages binding the sub-expressions used to evaluate the arguments, evaluates those arguments and calls evaluate()
with the results.
Before calling evalulate()
the PlotFunction
creates a context via createContext()
. This represents context data used to track the valuation for a particular binding of the function. For example, this may contain a history of previous evaluations. The context is an arbitrary type and is released by calling destroyContext()
.
A function may also be variadic, requiring a minimum number of arguments, but supporting additional values. For example, the minof
function supports any number of values, returning the minimum value.
virtual void* FunctionDefinition::createContext |
( |
| ) |
const |
|
virtual |
Called to create an operating context for calculating function values.
The context may be any type and represents working data required for the function. For example, this may hold a window of previous values for calculating a running average. The returned context is passed to evaluate()
.
The context is destroyed by destroyContext()
.
The default implementation returns null.
- Returns
- Working context data.
Reimplemented in FunctionMAvg.
QString FunctionDefinition::deduceDisplayName |
( |
| ) |
const |
Deduces the display name of the function to show usage.
This takes the function name, adds brackets and a list of sequential parameter terms based on the number of expected parameters. Examples are below.
Name | argc() | variadic() | Result |
abs | 1 | false | abs(x) |
sqrt | 1 | false | abs(x) |
abserr | 2 | false | abserr(x,y) |
noargs | 0 | false | noargs() |
onearg | 1 | false | onearg(x) |
twoargs | 2 | false | twoargs(x,y) |
threeargs | 3 | false | threeargs(x,y,z) |
fourargs | 4 | false | fourargs(a,b,c,d) |
maxofFunc | 1 | true | maxof(x...) |
For three or less parameters, they are labelled x, y, z respectively. For more parameters, they are labelled a, b, c, ... to the required number of parameters. Finally, '...' is appended for variadic functions.