![]() |
![]() |
![]() |
cpg-network Reference Manual | ![]() |
---|---|---|---|---|
Top | Description | Object Hierarchy | Properties |
#include <cpg-network/cpg-function.h> CpgFunctionArgument; CpgFunctionClass; CpgFunction; CpgFunction * cpg_function_new (gchar const *name, gchar const *expression); CpgFunctionArgument * cpg_function_argument_new (gchar const *name, gboolean optional, gdouble def); void cpg_function_add_argument (CpgFunction *function, CpgFunctionArgument *argument); void cpg_function_remove_argument (CpgFunction *function, CpgFunctionArgument *argument); void cpg_function_clear_arguments (CpgFunction *function); GList * cpg_function_get_arguments (CpgFunction *function); guint cpg_function_get_n_optional (CpgFunction *function); guint cpg_function_get_n_arguments (CpgFunction *function); void cpg_function_execute (CpgFunction *function, CpgStack *stack); void cpg_function_set_expression (CpgFunction *function, CpgExpression *expression); gchar const * cpg_function_argument_get_name (CpgFunctionArgument *argument); gboolean cpg_function_argument_get_optional (CpgFunctionArgument *argument); gdouble cpg_function_argument_get_default_value (CpgFunctionArgument *argument); CpgProperty * cpg_function_argument_get_property (CpgFunctionArgument *argument);
It is possible to define custom user functions in the network which can then be used from any expression. This class provides the basic user function functionality. User defined functions can have optional arguments with default values and can reference global constants as well as use other user defined functions in their expressions.
The CpgFunction class can be subclassed to provide more specific types of functions. One such example is the CpgFunctionPolynomial class which can be used to define and evaluate piecewise polynomials.
typedef struct { CpgObjectClass parent_class; gdouble (*evaluate) (CpgFunction *function); void (*execute) (CpgFunction *function, CpgStack *stack); } CpgFunctionClass;
CpgFunction * cpg_function_new (gchar const *name, gchar const *expression);
Create a new custom user function. After creation, function arguments can be added to the function using cpg_function_add_argument.
|
The function name |
|
The function expression |
Returns : |
A CpgFunction |
CpgFunctionArgument * cpg_function_argument_new (gchar const *name, gboolean optional, gdouble def);
Create a new function argument.
|
The argument name |
|
Whether the argument is optional |
|
The default value of an optional argument |
Returns : |
A CpgFunctionArgument |
void cpg_function_add_argument (CpgFunction *function, CpgFunctionArgument *argument);
Add a function argument. A proxy property for the argument will be automatically created if it does not exist yet. If the argument already exists it will not be added.
|
A CpgFunction |
|
A CpgFunctionArgument |
void cpg_function_remove_argument (CpgFunction *function, CpgFunctionArgument *argument);
Remove a function argument.
|
A CpgFunction |
|
A CpgFunctionArgument |
void cpg_function_clear_arguments (CpgFunction *function);
Remove all the function arguments.
|
A CpgFunction |
GList * cpg_function_get_arguments (CpgFunction *function);
Get the list of function arguments. The returned list is used internally and should not be modified or freed.
|
A CpgFunction |
Returns : |
A GList |
guint cpg_function_get_n_optional (CpgFunction *function);
Get the number of optional arguments. The optional arguments are always at the end of the list of arguments of the function.
|
A CpgFunction |
Returns : |
the number of optional arguments |
guint cpg_function_get_n_arguments (CpgFunction *function);
Get the number of arguments. This value is cached and is thus faster than using cpg_function_get_arguments and g_list_length.
|
A CpgFunction |
Returns : |
the number of arguments |
void cpg_function_execute (CpgFunction *function, CpgStack *stack);
Execute the function. This is used internally when the function needs to be evaluated.
|
A CpgFunction |
|
A CpgStack |
void cpg_function_set_expression (CpgFunction *function, CpgExpression *expression);
Set the function expression.
|
A CpgFunction |
|
A CpgExpression |
gchar const * cpg_function_argument_get_name (CpgFunctionArgument *argument);
Get the function name.
|
A CpgFunctionArgument |
Returns : |
the function name |
gboolean cpg_function_argument_get_optional (CpgFunctionArgument *argument);
Get whether the function argument is optional. If the argument is optional its default value can be obtained with cpg_function_argument_get_default_value
|
A CpgFunctionArgument |
Returns : |
whether the argument is optional |
gdouble cpg_function_argument_get_default_value (CpgFunctionArgument *argument);
Get the function argument default value.
|
A CpgFunctionArgument |
Returns : |
the default value |
CpgProperty * cpg_function_argument_get_property (CpgFunctionArgument *argument);
Get the underlying property that is the proxy for the function argument. You should generally not need this. It is mainly used in cpgrawc.
|
A CpgFunctionArgument |
Returns : |
the underlying argument property |