OpenCurves  0.9
plotfunctionregister.h
1 //
2 // author Kazys Stepanas
3 //
4 // Copyright (c) CSIRO 2013
5 //
6 #ifndef __PLOTFUNCTIONREGISTER_H_
7 #define __PLOTFUNCTIONREGISTER_H_
8 
9 #include "plotsconfig.h"
10 
11 #include "plotfunction.h"
12 
13 #include "functionsimple.h"
14 
15 #include <QStringList>
16 
27 {
28 public:
33  PlotFunctionRegister(bool registerDefaults = true);
34 
37 
44  FunctionSimple *add(FunctionSimple::ValueFunctionPtr function, const QString &category, const QString &name, const QString &description);
45 
55  FunctionSimple *add(FunctionSimple::ExpandedFunctionPtr function, const QString &category, const QString &name, const QString &description, unsigned argc = 0, bool variadic = false);
56 
61  FunctionDefinition *add(FunctionDefinition *functionDef, bool takeOwnership = true);
62 
66  const FunctionDefinition *find(const QString &name) const;
67 
70 
73  inline const QVector<FunctionDefinition *> &definitions() const { return _definitions; }
74 
77  inline const QStringList categories() const { return _categories; }
78 
83  unsigned getDefinitionsInCategory(const QString &categoryName, QVector<const FunctionDefinition *> &definitions) const;
84 
85 protected:
88  void ensureCategoryIsPresent(const QString &categoryName);
89 
90 private:
91  QVector<FunctionDefinition *> _definitions;
92  QStringList _categories;
93  QVector<bool> _ownership;
94 };
95 
96 #endif // __PLOTFUNCTIONREGISTER_H_
void(* ExpandedFunctionPtr)(PlotFunctionResult &result, double time, unsigned int argc, const double *argv, const PlotFunctionInfo &info)
ExpandedFunction typedef to a C function.
Definition: functionsimple.h:36
double(* ValueFunctionPtr)(double)
ValueFunction typedef to a C function.
Definition: functionsimple.h:31
const QStringList categories() const
Return the list of category names which covers all registered functions.
Definition: plotfunctionregister.h:77
void ensureCategoryIsPresent(const QString &categoryName)
Ensure that categoryName is present in the list of categories.
FunctionSimple * 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 imp...
A PlotFunctionRegister stores function implementations to expose to the plot expression generator...
Definition: plotfunctionregister.h:26
const FunctionDefinition * find(const QString &name) const
Search for a function by name : exact match with FunctionDefinition::name().
void registerDefaultFunctions()
Register built in functions. May have already been called from the constructor.
unsigned getDefinitionsInCategory(const QString &categoryName, QVector< const FunctionDefinition * > &definitions) const
Request definitions in a particular category.
~PlotFunctionRegister()
Destructor. Destroys all functions which the register owns.
Defines a function which can be used with the FunctionRegister.
Definition: functiondefinition.h:34
Defines a function which is implemented by a given function object.
Definition: functionsimple.h:25
const QVector< FunctionDefinition * > & definitions() const
Fetch all registered functions.
Definition: plotfunctionregister.h:73
PlotFunctionRegister(bool registerDefaults=true)
Constructor - optinally register default/built-in functions.