CpgFunction

CpgFunction — Custom user defined function

Synopsis


#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);

Object Hierarchy

  GObject
   +----CpgObject
         +----CpgFunction
               +----CpgFunctionPolynomial

Properties

  "expression"               CpgExpression*        : Read / Write / Construct

Description

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.

Details

CpgFunctionArgument

typedef struct _CpgFunctionArgument CpgFunctionArgument;


CpgFunctionClass

typedef struct {
	CpgObjectClass parent_class;

	gdouble (*evaluate) (CpgFunction *function);
	void (*execute) (CpgFunction *function, CpgStack *stack);
} CpgFunctionClass;


CpgFunction

typedef struct _CpgFunction CpgFunction;


cpg_function_new ()

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.

name :

The function name

expression :

The function expression

Returns :

A CpgFunction

cpg_function_argument_new ()

CpgFunctionArgument * cpg_function_argument_new         (gchar const *name,
                                                         gboolean optional,
                                                         gdouble def);

Create a new function argument.

name :

The argument name

optional :

Whether the argument is optional

def :

The default value of an optional argument

Returns :

A CpgFunctionArgument

cpg_function_add_argument ()

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.

function :

A CpgFunction

argument :

A CpgFunctionArgument

cpg_function_remove_argument ()

void                cpg_function_remove_argument        (CpgFunction *function,
                                                         CpgFunctionArgument *argument);

Remove a function argument.

function :

A CpgFunction

argument :

A CpgFunctionArgument

cpg_function_clear_arguments ()

void                cpg_function_clear_arguments        (CpgFunction *function);

Remove all the function arguments.

function :

A CpgFunction

cpg_function_get_arguments ()

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.

function :

A CpgFunction

Returns :

A GList

cpg_function_get_n_optional ()

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.

function :

A CpgFunction

Returns :

the number of optional arguments

cpg_function_get_n_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.

function :

A CpgFunction

Returns :

the number of arguments

cpg_function_execute ()

void                cpg_function_execute                (CpgFunction *function,
                                                         CpgStack *stack);

Execute the function. This is used internally when the function needs to be evaluated.

function :

A CpgFunction

stack :

A CpgStack

cpg_function_set_expression ()

void                cpg_function_set_expression         (CpgFunction *function,
                                                         CpgExpression *expression);

Set the function expression.

function :

A CpgFunction

expression :

A CpgExpression

cpg_function_argument_get_name ()

gchar const *       cpg_function_argument_get_name      (CpgFunctionArgument *argument);

Get the function name.

argument :

A CpgFunctionArgument

Returns :

the function name

cpg_function_argument_get_optional ()

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

argument :

A CpgFunctionArgument

Returns :

whether the argument is optional

cpg_function_argument_get_default_value ()

gdouble             cpg_function_argument_get_default_value
                                                        (CpgFunctionArgument *argument);

Get the function argument default value.

argument :

A CpgFunctionArgument

Returns :

the default value

cpg_function_argument_get_property ()

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.

argument :

A CpgFunctionArgument

Returns :

the underlying argument property

Property Details

The "expression" property

  "expression"               CpgExpression*        : Read / Write / Construct

Expression.