![]() |
![]() |
![]() |
cpg-network Reference Manual | ![]() |
---|---|---|---|---|
Top | Description | Object Hierarchy | Implemented Interfaces | Properties | Signals |
#define CPG_FUNCTION_CONST (obj) enum CpgFunctionError; struct CpgFunction; struct CpgFunctionClass; GQuark cpg_function_error_quark (void
); CpgFunction * cpg_function_new (const gchar *name
,const gchar *expression
); void cpg_function_add_argument (CpgFunction *function
,CpgFunctionArgument *argument
); gboolean cpg_function_remove_argument (CpgFunction *function
,CpgFunctionArgument *argument
,GError **error
); gboolean cpg_function_clear_arguments (CpgFunction *function
,GError **error
); const GList * cpg_function_get_arguments (CpgFunction *function
); guint cpg_function_get_n_optional (CpgFunction *function
); guint cpg_function_get_n_arguments (CpgFunction *function
); guint cpg_function_get_n_implicit (CpgFunction *function
); void cpg_function_execute (CpgFunction *function
,guint nargs
,CpgStack *stack
); void cpg_function_set_expression (CpgFunction *function
,CpgExpression *expression
); CpgExpression * cpg_function_get_expression (CpgFunction *function
); CpgFunctionPrivate;
GEnum +----CpgFunctionError
GObject +----CpgObject +----CpgFunction +----CpgFunctionPolynomial
CpgFunction implements CpgUsable, CpgAnnotatable, CpgLayoutable and CpgTaggable.
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.
#define CPG_FUNCTION_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CPG_TYPE_FUNCTION, CpgFunction const))
typedef enum { CPG_FUNCTION_ERROR_UNKNOWN, CPG_FUNCTION_ERROR_ARGUMENT_NOT_FOUND, CPG_FUNCTION_NUM_ERRORS } CpgFunctionError;
struct CpgFunctionClass { gdouble (*evaluate) (CpgFunction *function); void (*execute) (CpgFunction *function, guint nargs, CpgStack *stack); /* signals */ void (*argument_added) (CpgFunction *function, CpgFunctionArgument *argument); void (*argument_removed) (CpgFunction *function, CpgFunctionArgument *argument); void (*arguments_reordered) (CpgFunction *function); };
The CpgFunction class
CpgFunction * cpg_function_new (const gchar *name
,const gchar *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 |
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 |
gboolean cpg_function_remove_argument (CpgFunction *function
,CpgFunctionArgument *argument
,GError **error
);
Remove a function argument.
|
A CpgFunction |
|
A CpgFunctionArgument |
|
A GError |
Returns : |
TRUE if the argument could be removed, FALSE otherwise |
gboolean cpg_function_clear_arguments (CpgFunction *function
,GError **error
);
Remove all the function arguments.
|
A CpgFunction |
|
A GError |
Returns : |
TRUE if all arguments could be successfully removed, FALSE otherwise |
const 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. [element-type CpgFunctionArgument][transfer none] |
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 |
guint cpg_function_get_n_implicit (CpgFunction *function
);
Get the number of implicit arguments.
|
A CpgFunction |
Returns : |
the number of implicit arguments |
void cpg_function_execute (CpgFunction *function
,guint nargs
,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 |
CpgExpression * cpg_function_get_expression (CpgFunction *function
);
Get the function expression.
|
A CpgFunction |
Returns : |
A CpgExpression. [type CpgExpression][transfer none] |
"argument-added"
signalvoid user_function (CpgFunction *function,
CpgFunctionArgument *argument,
gpointer user_data) : Run Last
Emitted when an argument has been added to the function
|
a CpgFunction |
|
a CpgFunctionArgument |
|
user data set when the signal handler was connected. |
"argument-removed"
signalvoid user_function (CpgFunction *function,
CpgFunctionArgument *argument,
gpointer user_data) : Run Last
Emitted when an argument has been removed from the function
|
a CpgFunction |
|
a CpgFunctionArgument |
|
user data set when the signal handler was connected. |
"arguments-reordered"
signalvoid user_function (CpgFunction *cpgfunction,
gpointer user_data) : Run Last
|
the object which received the signal. |
|
user data set when the signal handler was connected. |