Main Page   Modules   File List   Globals  

Typedefs | Enumerations | Functions
CODA Expression

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:

 const char *equation = "1+2";
 coda_expression *expr;
 long result;

 coda_expression_from_string(equation, &expr);
 coda_expression_eval_integer(expr, NULL, &result);
 coda_expression_delete(expr);
 printf("%d\n", result);

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.

 const char *equation = "float(./numerator)/float(./denominator)";
 coda_cursor cursor;
 coda_expression *expr;
 double result;

 coda_expression_from_string(equation, &expr);

 ... loop over all cursors for which you want to calculate the division ....
 coda_expression_eval_integer(expr, &cursor, &result);
 printf("%f\n", result);
 ... end of loop ...

 coda_expression_delete(expr);

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

CODA Expression

Result types of CODA expressions.


Enumeration Type Documentation

Result types of CODA expressions.


Function Documentation

void coda_expression_delete ( coda_expression expr)

Delete the CODA expression object.

Parameters:
exprA CODA expression object
int coda_expression_eval_bool ( const coda_expression expr,
const coda_cursor cursor,
int *  value 
)

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:
exprA boolean expression object
cursorCursor pointing to a location in the product where the boolean expression should be evaluated (can be NULL for constant expressions).
valuePointer to the variable where the resulting boolean value will be stored.
Returns:
  • 0, Success.
  • -1, Error occurred (check coda_errno).
int coda_expression_eval_float ( const coda_expression expr,
const coda_cursor cursor,
double *  value 
)

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:
exprA floating point expression object
cursorCursor pointing to a location in the product where the floating point expression should be evaluated (can be NULL for constant expressions).
valuePointer to the variable where the resulting floating point value will be stored.
Returns:
  • 0, Success.
  • -1, Error occurred (check coda_errno).
int coda_expression_eval_integer ( const coda_expression expr,
const coda_cursor cursor,
int64_t *  value 
)

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:
exprAn integer expression object
cursorCursor pointing to a location in the product where the integer expression should be evaluated (can be NULL for constant expressions).
valuePointer to the variable where the resulting integer value will be stored.
Returns:
  • 0, Success.
  • -1, Error occurred (check coda_errno).
int coda_expression_eval_node ( const coda_expression expr,
coda_cursor cursor 
)

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:
exprA node expression object
cursorCursor pointing to a location in the product where the node expression should be evaluated.
Returns:
  • 0, Success.
  • -1, Error occurred (check coda_errno).
int coda_expression_eval_string ( const coda_expression expr,
const coda_cursor cursor,
char **  value,
long *  length 
)

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:
exprA string expression object
cursorCursor pointing to a location in the product where the string expression should be evaluated (can be NULL for constant expressions).
valuePointer to the variable where the result string will be stored (will be NULL if length == 0).
lengthPointer 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:
exprstringA string containing the string representation of the CODA expression
exprPointer to the variable where the expression object will be stored.
Returns:
  • 0, Success.
  • -1, Error occurred (check coda_errno).
int coda_expression_get_type ( const coda_expression expr,
coda_expression_type type 
)

Retrieve the result type of a CODA expression.

Parameters:
exprA CODA expression object
typePointer to the variable where the result type of the CODA expression will be stored.
Returns:
  • 0, Success.
  • -1, Error occurred (check coda_errno).
int coda_expression_is_constant ( const coda_expression expr)

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:
exprA CODA expression object
Returns:
  • 0, Expression will depend on the contents of a product.
  • 1, Expression is constant.
  • -1, Error occurred (check coda_errno).