OpenCurves  0.9
FunctionSimple Class Reference

Defines a function which is implemented by a given function object. More...

#include <functionsimple.h>

Inheritance diagram for FunctionSimple:
FunctionDefinition

Public Types

typedef std::function< double(double)> ValueFunction
 Simple implementation parameterisation.
 
typedef double(* ValueFunctionPtr) (double)
 ValueFunction typedef to a C function.
 
typedef std::function< void(PlotFunctionResult &result, double time, unsigned int argc, const double *argv, const PlotFunctionInfo &info)> ExpandedFunction
 Expanded function parameterisation.
 
typedef void(* ExpandedFunctionPtr) (PlotFunctionResult &result, double time, unsigned int argc, const double *argv, const PlotFunctionInfo &info)
 ExpandedFunction typedef to a C function.
 

Public Member Functions

 FunctionSimple (const ValueFunction &func, const QString &category, const QString &name, const QString &description=QString())
 Constructor routing the function implementation through a ValueFunction. More...
 
 FunctionSimple (const ExpandedFunction &func, const QString &category, const QString &name, unsigned argc=0, bool variadic=false)
 Constructor routing the function implementation through a ExpandedFunction. More...
 
 FunctionSimple (const ExpandedFunction &func, const QString &category, const QString &name, const QString &description, unsigned argc=0, bool variadic=false)
 Constructor routing the function implementation through a ExpandedFunction. More...
 
ExpandedFunction function () const
 Returns the function object invoked from evaluate(). More...
 
void evaluate (PlotFunctionResult &result, double time, unsigned int argc, const double *argv, const PlotFunctionInfo &info, void *context) const override
 Evaluates the function results. More...
 
- Public Member Functions inherited from FunctionDefinition
 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 * 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...
 

Protected Attributes

ExpandedFunction _function
 The function object.
 

Detailed Description

Defines a function which is implemented by a given function object.

Supports two kinds of function objects:

  • ValueFunction accepting and returning a single double precision value.
  • ExpandedFunction which allows greater control over the inputs and results.

Note that a ValueFunction is always wrapped up in a function call which accepts all the arguments of ExpandedFunction, but only passes through argv[0].

Constructor & Destructor Documentation

FunctionSimple::FunctionSimple ( const ValueFunction func,
const QString &  category,
const QString &  name,
const QString &  description = QString() 
)

Constructor routing the function implementation through a ValueFunction.

Expects exactly one argument.

Parameters
funcThe function object to call through to from evaluate().
categoryThe sorting category for this function.
nameThe name of the function. Used to match expressions.
descriptionThe readable description of the function. Displayed to the user.
FunctionSimple::FunctionSimple ( const ExpandedFunction func,
const QString &  category,
const QString &  name,
unsigned  argc = 0,
bool  variadic = false 
)

Constructor routing the function implementation through a ExpandedFunction.

Parameters
funcThe function object to call through to from evaluate().
categoryThe sorting category for this function.
nameThe name of the function. Used to match expressions.
argcThe exact number of arguments the function expects, or the minimum number if variadic is true.
variadicIs the function variadic, accepting more arguments than just argc?
FunctionSimple::FunctionSimple ( const ExpandedFunction func,
const QString &  category,
const QString &  name,
const QString &  description,
unsigned  argc = 0,
bool  variadic = false 
)

Constructor routing the function implementation through a ExpandedFunction.

Parameters
funcThe function object to call through to from evaluate().
categoryThe sorting category for this function.
nameThe name of the function. Used to match expressions.
descriptionThe readable description of the function. Displayed to the user.
argcThe exact number of arguments the function expects, or the minimum number if variadic is true.
variadicIs the function variadic, accepting more arguments than just argc?

Member Function Documentation

void FunctionSimple::evaluate ( PlotFunctionResult result,
double  time,
unsigned int  argc,
const double *  argv,
const PlotFunctionInfo info,
void *  context 
) const
overridevirtual

Evaluates the function results.

For a ExpandedFunction, this simply invokes that function. For a ValueFunction, this will invoke that function in a more round about way, passing through only argv[0].

Parameters
[out]resultThe evaluation result is written here.
timeThe sample time being evaluated for.
argcThe number of arguments actually given.
argvThe list of calculated arguments, length argc. These are always logical values.
infoAdditional information about the current sampling.
contextAdditional context of the operation. May hold working data. This is optained via createContext().

Implements FunctionDefinition.

ExpandedFunction FunctionSimple::function ( ) const
inline

Returns the function object invoked from evaluate().

This will wrap a ValueFunction when constructed from such.

Returns
The function implementation.

References _function.


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