CpgFunction

CpgFunction — Custom user defined function

Synopsis

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

Object Hierarchy

  GEnum
   +----CpgFunctionError
  GObject
   +----CpgObject
         +----CpgFunction
               +----CpgFunctionPolynomial

Implemented Interfaces

CpgFunction implements CpgUsable, CpgAnnotatable, CpgLayoutable and CpgTaggable.

Properties

  "expression"               CpgExpression*        : Read / Write / Construct

Signals

  "argument-added"                                 : Run Last
  "argument-removed"                               : Run Last
  "arguments-reordered"                            : Run Last

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.

CpgFunction Copy Semantics

When a function is copied with cpg_object_copy, the function expression and all the arguments are copied as well.

Details

CPG_FUNCTION_CONST()

#define CPG_FUNCTION_CONST(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), CPG_TYPE_FUNCTION, CpgFunction const))


enum CpgFunctionError

typedef enum
{
	CPG_FUNCTION_ERROR_UNKNOWN,
	CPG_FUNCTION_ERROR_ARGUMENT_NOT_FOUND,
	CPG_FUNCTION_NUM_ERRORS
} CpgFunctionError;

CPG_FUNCTION_ERROR_UNKNOWN

unknown

CPG_FUNCTION_ERROR_ARGUMENT_NOT_FOUND

property not found

CPG_FUNCTION_NUM_ERRORS

num errors

struct CpgFunction

struct CpgFunction;


struct CpgFunctionClass

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

evaluate ()

evaluate virtual function

execute ()

execute virtual function

argument_added ()

argument_removed ()

arguments_reordered ()


cpg_function_error_quark ()

GQuark              cpg_function_error_quark            (void);


cpg_function_new ()

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.

name :

The function name

expression :

The function expression

Returns :

A CpgFunction

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 ()

gboolean            cpg_function_remove_argument        (CpgFunction *function,
                                                         CpgFunctionArgument *argument,
                                                         GError **error);

Remove a function argument.

function :

A CpgFunction

argument :

A CpgFunctionArgument

error :

A GError

Returns :

TRUE if the argument could be removed, FALSE otherwise

cpg_function_clear_arguments ()

gboolean            cpg_function_clear_arguments        (CpgFunction *function,
                                                         GError **error);

Remove all the function arguments.

function :

A CpgFunction

error :

A GError

Returns :

TRUE if all arguments could be successfully removed, FALSE otherwise

cpg_function_get_arguments ()

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.

function :

A CpgFunction

Returns :

A GList. [element-type CpgFunctionArgument][transfer none]

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_get_n_implicit ()

guint               cpg_function_get_n_implicit         (CpgFunction *function);

Get the number of implicit arguments.

function :

A CpgFunction

Returns :

the number of implicit arguments

cpg_function_execute ()

void                cpg_function_execute                (CpgFunction *function,
                                                         guint nargs,
                                                         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_get_expression ()

CpgExpression *     cpg_function_get_expression         (CpgFunction *function);

Get the function expression.

function :

A CpgFunction

Returns :

A CpgExpression. [type CpgExpression][transfer none]

CpgFunctionPrivate

typedef struct _CpgFunctionPrivate CpgFunctionPrivate;

Property Details

The "expression" property

  "expression"               CpgExpression*        : Read / Write / Construct

Expression.

Signal Details

The "argument-added" signal

void                user_function                      (CpgFunction         *function,
                                                        CpgFunctionArgument *argument,
                                                        gpointer             user_data)      : Run Last

Emitted when an argument has been added to the function

function :

a CpgFunction

argument :

a CpgFunctionArgument

user_data :

user data set when the signal handler was connected.

The "argument-removed" signal

void                user_function                      (CpgFunction         *function,
                                                        CpgFunctionArgument *argument,
                                                        gpointer             user_data)      : Run Last

Emitted when an argument has been removed from the function

function :

a CpgFunction

argument :

a CpgFunctionArgument

user_data :

user data set when the signal handler was connected.

The "arguments-reordered" signal

void                user_function                      (CpgFunction *cpgfunction,
                                                        gpointer     user_data)        : Run Last

cpgfunction :

the object which received the signal.

user_data :

user data set when the signal handler was connected.