![]() |
![]() |
![]() |
cpg-network Reference Manual | ![]() |
---|---|---|---|---|
Top | Description | Object Hierarchy | Implemented Interfaces | Properties |
#define CPG_EXPRESSION_CONST (obj) struct CpgExpression; struct CpgExpressionClass; typedef CpgPropertyForward; CpgExpression * cpg_expression_new (const gchar *expression
); CpgExpression * cpg_expression_copy (CpgExpression *expression
); const GSList * cpg_expression_get_dependencies (CpgExpression *expression
); const gchar * cpg_expression_get_as_string (CpgExpression *expression
); gboolean cpg_expression_compile (CpgExpression *expression
,CpgCompileContext *context
,GError **error
); gdouble cpg_expression_evaluate (CpgExpression *expression
); void cpg_expression_set_value (CpgExpression *expression
,gdouble value
); void cpg_expression_reset (CpgExpression *expression
); void cpg_expression_reset_variadic (CpgExpression *expression
); gboolean cpg_expression_equal (CpgExpression *expression
,CpgExpression *other
); void cpg_expression_set_from_string (CpgExpression *expression
,const gchar *value
); void cpg_expression_reset_cache (CpgExpression *expression
); gboolean cpg_expression_get_has_cache (CpgExpression *expression
); void cpg_expression_set_has_cache (CpgExpression *expression
,gboolean cache
); const GSList * cpg_expression_get_instructions (CpgExpression *expression
); void cpg_expression_set_instructions (CpgExpression *expression
,const GSList *instructions
); const GSList * cpg_expression_get_operators (CpgExpression *expression
); gboolean cpg_expression_get_once (CpgExpression *expression
); void cpg_expression_set_once (CpgExpression *expression
,gboolean instant
); gint cpg_expression_get_error_at (CpgExpression *expression
); CpgExpressionPrivate;
"expression" gchar* : Read / Write / Construct "has-cache" gboolean : Read / Write / Construct "value" gdouble : Read / Write
A CpgExpression contains a mathematical expression. The expression in string format can be compiled and evaluated. At the compilation phase, a list of CpgObject is provided as a context in which variables are mapped to CpgProperty in this context.
#define CPG_EXPRESSION_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CPG_TYPE_EXPRESSION, CpgExpression const))
CpgExpression * cpg_expression_new (const gchar *expression
);
Create a new CpgExpression containing the expression expression
|
an expression |
Returns : |
a new CpgExpression |
CpgExpression * cpg_expression_copy (CpgExpression *expression
);
Create a copy of a CpgExpression.
|
A CpgExpression |
Returns : |
A CpgExpression. [transfer full] |
const GSList * cpg_expression_get_dependencies (CpgExpression *expression
);
Get a list of CpgProperty on which the expression depends. The list is owned
by expression
and should not be freed or modified
|
a CpgExpression |
Returns : |
a list of CpgProperty. [element-type CpgProperty][transfer container] |
const gchar * cpg_expression_get_as_string (CpgExpression *expression
);
Get the string representation of the expression
|
a CpgExpression |
Returns : |
the string representation of the expression |
gboolean cpg_expression_compile (CpgExpression *expression
,CpgCompileContext *context
,GError **error
);
Compile the expression. The context is a list of CpgObject from which
properties can be looked up (such as global constants, or from/to objects).
If there were any errors during compilation, error
will be set accordingly
|
a CpgExpression |
|
the evaluation context |
|
a GError |
Returns : |
TRUE if the expression compiled successfully, FALSE otherwise |
gdouble cpg_expression_evaluate (CpgExpression *expression
);
Get the result of evaluating the expression. If the expression is not yet compiled, 0.0 is returned. The result of the evaluation is cached in the expression. Make sure to call cpg_expression_reset_cache to clear the cache if needed
|
a CpgExpression |
Returns : |
the result of evaluating the expression |
void cpg_expression_set_value (CpgExpression *expression
,gdouble value
);
Sets the cached/instant value of an expression. If the expression is reset, this value will no longer be used and the expression will be evaluated as normal
|
a CpgExpression |
|
a value |
void cpg_expression_reset (CpgExpression *expression
);
Resets all the expression flags (cache, instant)
|
a CpgExpression |
void cpg_expression_reset_variadic (CpgExpression *expression
);
Reset the cache of the variadic functions (such as rand()
). You normally
do not need to call this function directly.
|
A CpgExpression |
gboolean cpg_expression_equal (CpgExpression *expression
,CpgExpression *other
);
Get whether two expressions are equal. If the expressions are compiled, they are evaluated for equality by means of their instructions. Otherwise the comparison is done on their string representations
|
a CpgExpression |
|
a CpgExpression |
Returns : |
TRUE if the expressions are equal, FALSE otherwise |
void cpg_expression_set_from_string (CpgExpression *expression
,const gchar *value
);
Set a new expression for expression
|
a CpgExpression |
|
the value |
void cpg_expression_reset_cache (CpgExpression *expression
);
Resets the possibly cached result of the value
|
a CpgExpression |
void cpg_expression_set_has_cache (CpgExpression *expression
,gboolean cache
);
const GSList * cpg_expression_get_instructions (CpgExpression *expression
);
Get list of CpgInstruction. The list is owned by expression
and should
not be freed or modified
|
a CpgExpression |
Returns : |
list of CpgInstruction. [element-type CpgInstruction][transfer none] |
void cpg_expression_set_instructions (CpgExpression *expression
,const GSList *instructions
);
Set the instructions used to evaluate the expression. You should never have to use this function. It's main purpose is for optimization of expressions in cpgrawc.
|
A CpgExpression |
|
A GSList of CpgInstruction. [element-type CpgInstruction][transfer full] |
const GSList * cpg_expression_get_operators (CpgExpression *expression
);
gboolean cpg_expression_get_once (CpgExpression *expression
);
Get whether the expression is only evaluated once.
|
A CpgExpression |
Returns : |
TRUE if the expression is only evaluated once, FALSE otherwise. |
void cpg_expression_set_once (CpgExpression *expression
,gboolean instant
);
When an expression is "once", its value will not change.
|
A CpgExpression |
|
Whether the expression should be constant |
gint cpg_expression_get_error_at (CpgExpression *expression
);
Get the character position in the expression at which an error occurred while compiling the expression
|
A CpgExpression |
Returns : |
the character position at which an error occurred |