OpenCurves  0.9
PlotFunctionRegister Class Reference

A PlotFunctionRegister stores function implementations to expose to the plot expression generator. More...

#include <plotfunctionregister.h>

Public Member Functions

 PlotFunctionRegister (bool registerDefaults=true)
 Constructor - optinally register default/built-in functions. More...
 
 ~PlotFunctionRegister ()
 Destructor. Destroys all functions which the register owns.
 
FunctionSimpleadd (FunctionSimple::ValueFunctionPtr function, const QString &category, const QString &name, const QString &description)
 Add a function to the register using a FunctionSimple object with a FunctionSimple::ValueFunction implementation. More...
 
FunctionSimpleadd (FunctionSimple::ExpandedFunctionPtr function, const QString &category, const QString &name, const QString &description, unsigned argc=0, bool variadic=false)
 Add a function to the register using a FunctionSimple object with a FunctionSimple::ExpandedFunction implementation. More...
 
FunctionDefinitionadd (FunctionDefinition *functionDef, bool takeOwnership=true)
 A a function by object. More...
 
const FunctionDefinitionfind (const QString &name) const
 Search for a function by name : exact match with FunctionDefinition::name(). More...
 
void registerDefaultFunctions ()
 Register built in functions. May have already been called from the constructor.
 
const QVector< FunctionDefinition * > & definitions () const
 Fetch all registered functions. More...
 
const QStringList categories () const
 Return the list of category names which covers all registered functions. More...
 
unsigned getDefinitionsInCategory (const QString &categoryName, QVector< const FunctionDefinition * > &definitions) const
 Request definitions in a particular category. More...
 

Protected Member Functions

void ensureCategoryIsPresent (const QString &categoryName)
 Ensure that categoryName is present in the list of categories. More...
 

Detailed Description

A PlotFunctionRegister stores function implementations to expose to the plot expression generator.

These functions represent arbitrary operations which can be performed in a plot expression. Function implementations are free to perform whatever calculations they wish (within reason) based on the given inputs. For example, the max() function tracks the running maximum of the input expression.

Function implementations are added by calling add().

Constructor & Destructor Documentation

PlotFunctionRegister::PlotFunctionRegister ( bool  registerDefaults = true)

Constructor - optinally register default/built-in functions.

Built-in functions can be registered later by calling registerDefaultFunctions().

Parameters
registerDefaultsTrue to register the default/build-in functions.

Member Function Documentation

FunctionSimple* PlotFunctionRegister::add ( FunctionSimple::ValueFunctionPtr  function,
const QString &  category,
const QString &  name,
const QString &  description 
)

Add a function to the register using a FunctionSimple object with a FunctionSimple::ValueFunction implementation.

Parameters
functionThe function pointer handling calculation of the results.
categoryThe category for the function, used for grouping in the UI.
nameThe function name. Used as the function identifier. Follows identifier rules for valid characters.
descriptionDescription shown to the user. Cannot be translated yet.
Returns
The FunctionSimple object instantiated to invoke function, or null on failure.
FunctionSimple* PlotFunctionRegister::add ( FunctionSimple::ExpandedFunctionPtr  function,
const QString &  category,
const QString &  name,
const QString &  description,
unsigned  argc = 0,
bool  variadic = false 
)

Add a function to the register using a FunctionSimple object with a FunctionSimple::ExpandedFunction implementation.

Parameters
functionThe function pointer handling calculation of the results.
categoryThe category for the function, used for grouping in the UI.
nameThe function name. Used as the function identifier. Follows identifier rules for valid characters.
argcThe minimum number of arguments the function requires.
descriptionDescription shown to the user. Cannot be translated yet.
variadicSet to true if the function is variadic and supports a variable number of parameters after argc.
Returns
The FunctionSimple object instantiated to invoke function, or null on failure.
FunctionDefinition* PlotFunctionRegister::add ( FunctionDefinition functionDef,
bool  takeOwnership = true 
)

A a function by object.

Parameters
functionDefThe function definition. This class takes ownership of the pointer if takeOwnership is true.
takeOwnershipTrue if this class will delete functionDef (call delete).
Returns
The FunctionDefinition object functionDef on success or null on failure.
const QStringList PlotFunctionRegister::categories ( ) const
inline

Return the list of category names which covers all registered functions.

Returns
The category list.
const QVector<FunctionDefinition *>& PlotFunctionRegister::definitions ( ) const
inline

Fetch all registered functions.

Returns
A list of registered function definitions.
void PlotFunctionRegister::ensureCategoryIsPresent ( const QString &  categoryName)
protected

Ensure that categoryName is present in the list of categories.

Parameters
categoryNameThe category name to ensure is present.
const FunctionDefinition* PlotFunctionRegister::find ( const QString &  name) const

Search for a function by name : exact match with FunctionDefinition::name().

Parameters
nameThe name to match.
Returns
The matched function, or null on failure.
unsigned PlotFunctionRegister::getDefinitionsInCategory ( const QString &  categoryName,
QVector< const FunctionDefinition * > &  definitions 
) const

Request definitions in a particular category.

Parameters
categoryNameThe category to match (exact match).
definitionsMatching definitions are added to this container.
Returns
The number of items added to definitions.

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