Typedefs |
typedef struct
coda_expression_struct | coda_expression |
typedef enum
coda_expression_type_enum | coda_expression_type |
Enumerations |
| enum | coda_expression_type_enum |
Functions |
| void | coda_expression_delete (coda_expression *expr) |
| int | coda_expression_is_constant (const coda_expression *expr) |
| int | coda_expression_get_type (const coda_expression *expr, coda_expression_type *type) |
| int | coda_expression_eval_bool (const coda_expression *expr, const coda_cursor *cursor, int *value) |
| int | coda_expression_eval_integer (const coda_expression *expr, const coda_cursor *cursor, int64_t *value) |
| int | coda_expression_eval_float (const coda_expression *expr, const coda_cursor *cursor, double *value) |
| int | coda_expression_eval_string (const coda_expression *expr, const coda_cursor *cursor, char **value, long *length) |
| int | coda_expression_eval_node (const coda_expression *expr, coda_cursor *cursor) |
| int | coda_expression_from_string (const char *exprstring, coda_expression **expr) |
| | Create a new CODA expression object by parsing a string containing a CODA expression. The string should contain a valid CODA expression. The returned expression object should be cleaned up using coda_expression_delete() after it has been used.
|
Detailed Description
CODA comes with a powerful expression language that can be used to perform calculations based on product data. This expression system is used internally with the product format definition (codadef) files that CODA uses to interpret products, but it can also be used by you as a user for your own purposes. More information on the CODA expression language and its ascii syntax can be found in the CODA documentation.
The example below shows how to evaluate a simple integer expression that does not make use of any product data:
However, in most cases you will want to run an expression on actual product data. In the example below the expression expects a cursor that points to a record which has two fields, 'numerator' and 'denominator', and it will return a floating point value with the division of those two field values.
Note that, unlike most other CODA functions, the coda_expression_from_string() and coda_expression_delete() functions do not require that CODA is initialised with coda_init(). This also holds for the coda_expression_eval functions if no cursor is provided as parameter (i.e. when a static evaluation of the expression is performed).
Typedef Documentation
Result types of CODA expressions.
Enumeration Type Documentation
Result types of CODA expressions.
Function Documentation
Delete the CODA expression object.
- Parameters:
-
| expr | A CODA expression object |
Evaluate a boolean expression. The expression object should be a coda_expression_bool expression. The function will evaluate the expression at the given cursor position and return the resulting boolean value (which will be 0 for False and 1 for True).
- Parameters:
-
| expr | A boolean expression object |
| cursor | Cursor pointing to a location in the product where the boolean expression should be evaluated (can be NULL for constant expressions). |
| value | Pointer to the variable where the resulting boolean value will be stored. |
- Returns:
0, Success.
-1, Error occurred (check coda_errno).
Evaluate a floating point expression. The function will evaluate the expression at the given cursor position and return the resulting floating point value. The expression object should be a coda_expression_float expression.
- Parameters:
-
| expr | A floating point expression object |
| cursor | Cursor pointing to a location in the product where the floating point expression should be evaluated (can be NULL for constant expressions). |
| value | Pointer to the variable where the resulting floating point value will be stored. |
- Returns:
0, Success.
-1, Error occurred (check coda_errno).
Evaluate an integer expression. The expression object should be a coda_expression_integer expression. The function will evaluate the expression at the given cursor position and return the resulting integer value.
- Parameters:
-
| expr | An integer expression object |
| cursor | Cursor pointing to a location in the product where the integer expression should be evaluated (can be NULL for constant expressions). |
| value | Pointer to the variable where the resulting integer value will be stored. |
- Returns:
0, Success.
-1, Error occurred (check coda_errno).
Evaluate a node expression. The function will moves the cursor to a different position in a product based on the node expression. The expression object should be a coda_expression_node expression.
- Parameters:
-
| expr | A node expression object |
| cursor | Cursor pointing to a location in the product where the node expression should be evaluated. |
- Returns:
0, Success.
-1, Error occurred (check coda_errno).
Evaluate a string expression. The function will evaluate the expression at the given cursor position (if provided) and return the resulting string and length. If length is 0 then no string will be returned and value will be set to NULL. If a string is returned then it will be zero terminated. However, in the case where the string itself also contains zero characters, strlen() can not be used and the length parameter will give the actual string length of value. The expression object should be a coda_expression_string expression.
- Note:
- The caller of this function is responsible for freeing the memory of the result that is stored in
value. It is recommended to do this with coda_free().
- Parameters:
-
| expr | A string expression object |
| cursor | Cursor pointing to a location in the product where the string expression should be evaluated (can be NULL for constant expressions). |
| value | Pointer to the variable where the result string will be stored (will be NULL if length == 0). |
| length | Pointer to the variable where the length of the result string will be stored. |
- Returns:
0, Success.
-1, Error occurred (check coda_errno).
| int coda_expression_from_string |
( |
const char * |
exprstring, |
|
|
coda_expression ** |
expr |
|
) |
| |
Create a new CODA expression object by parsing a string containing a CODA expression. The string should contain a valid CODA expression. The returned expression object should be cleaned up using coda_expression_delete() after it has been used.
- Parameters:
-
| exprstring | A string containing the string representation of the CODA expression |
| expr | Pointer to the variable where the expression object will be stored. |
- Returns:
0, Success.
-1, Error occurred (check coda_errno).
Retrieve the result type of a CODA expression.
- Parameters:
-
| expr | A CODA expression object |
| type | Pointer to the variable where the result type of the CODA expression will be stored. |
- Returns:
0, Success.
-1, Error occurred (check coda_errno).
Return whether an expression is constant or not. An expression is constant if it does not depend on the contents of a product and if the expression evaluation function can be called with cursor=NULL.
- Parameters:
-
| expr | A CODA expression object |
- Returns:
0, Expression will depend on the contents of a product.
1, Expression is constant.
-1, Error occurred (check coda_errno).