var.h File Reference


Detailed Description

Implement dba_var, an encapsulation of a measured variable.

#include <dballe/core/error.h>
#include <dballe/core/vartable.h>
#include <stdio.h>

Go to the source code of this file.

Typedefs

typedef struct _dba_var * dba_var
 Holds a DBALLE variable.
typedef struct _dba_var_attr * dba_var_attr_iterator
 Cursor for iterating through the attributes of a dba_var.

Functions

dba_err dba_var_create (dba_varinfo info, dba_var *var)
 Create a new dba_var.
dba_err dba_var_createi (dba_varinfo info, int val, dba_var *var)
 Create a new dba_var, setting it to an integer value.
dba_err dba_var_created (dba_varinfo info, double val, dba_var *var)
 Create a new dba_var, setting it to a double value.
dba_err dba_var_createc (dba_varinfo info, const char *val, dba_var *var)
 Create a new dba_var, setting it to a character value.
dba_err dba_var_create_local (dba_varcode code, dba_var *var)
 Create a variable with informations from the local table.
dba_err dba_var_copy (dba_var source, dba_var *dest)
 Make an exact copy of a dba_var.
void dba_var_delete (dba_var var)
 Delete a dba_var.
int dba_var_equals (const dba_var var1, const dba_var var2)
 Check if two variables contains the same data.
dba_err dba_var_enqi (dba_var var, int *val)
 Get the value of a dba_var, as an integer.
dba_err dba_var_enqd (dba_var var, double *val)
 Get the value of a dba_var, as a double.
dba_err dba_var_enqc (dba_var var, const char **val)
 Get the value of a dba_var, as a string.
dba_err dba_var_seti (dba_var var, int val)
 Set the value of a dba_var, from an integer value.
dba_err dba_var_setd (dba_var var, double val)
 Set the value of a dba_var, from a double value.
dba_err dba_var_setc (dba_var var, const char *val)
 Set the value of a dba_var, from a string value.
dba_err dba_var_unset (dba_var var)
 Unset the value of a dba_var.
dba_err dba_var_enqa (dba_var var, dba_varcode code, dba_var *attr)
 Query variable attributes.
dba_err dba_var_seta (dba_var var, dba_var attr)
 Set an attribute of the variable.
dba_err dba_var_seta_nocopy (dba_var var, dba_var attr)
 Set an attribute of the variable.
dba_err dba_var_unseta (dba_var var, dba_varcode code)
 Remove the attribute with the given code.
void dba_var_clear_attrs (dba_var var)
 Remove all attributes from the variable.
dba_varcode dba_var_code (dba_var var)
 Retrieve the dba_varcode for a variable.
dba_varinfo dba_var_info (dba_var var)
 Get informations about the variable.
const char * dba_var_value (dba_var var)
 Retrieve the internal string representation of the value for a variable.
dba_var_attr_iterator dba_var_attr_iterate (dba_var var)
 Start iterating through all the attributes of a variable.
dba_var_attr_iterator dba_var_attr_iterator_next (dba_var_attr_iterator iter)
 Advance a dba_var_attr_iterator to point to the next attribute.
dba_var dba_var_attr_iterator_attr (dba_var_attr_iterator iter)
 Get the attribute pointed by a dba_var_attr_iterator.
dba_err dba_var_copy_val (dba_var dest, dba_var orig)
 Copy a value from a variable to another, performing conversions if needed.
dba_err dba_var_copy_attrs (dba_var dest, dba_var src)
 Copy all the attributes from one variable to another.
dba_err dba_var_convert (dba_var orig, dba_varinfo info, dba_var *conv)
 Convert a variable to an equivalent variable using different informations.
int dba_var_encode_int (double fval, dba_varinfo info)
 Encode a double value into an integer value using varinfo encoding informations.
double dba_var_decode_int (int val, dba_varinfo info)
 Decode a double value from integer value using varinfo encoding informations.
void dba_var_print (dba_var var, FILE *out)
 Print the variable to an output stream.
void dba_var_diff (dba_var var1, dba_var var2, int *diffs, FILE *out)
 Print the difference between two variables to an output stream.


Typedef Documentation

typedef struct _dba_var* dba_var

Holds a DBALLE variable.

A dba_var contains:

  • a dba_varcode identifying what is measured. See vartable.h
  • a measured value, that can be an integer, double or string depending on the dba_varcode
  • zero or more attributes, in turn represented by dba_var structures


Function Documentation

dba_var_attr_iterator dba_var_attr_iterate ( dba_var  var  ) 

Start iterating through all the attributes of a variable.

Parameters:
var The variable to work on
Returns:
The dba_var_attr_iterator to use to iterate the attributes

dba_var dba_var_attr_iterator_attr ( dba_var_attr_iterator  iter  ) 

Get the attribute pointed by a dba_var_attr_iterator.

Parameters:
iter The iterator to work on
Returns:
The attribute currently pointed by the iterator

dba_var_attr_iterator dba_var_attr_iterator_next ( dba_var_attr_iterator  iter  ) 

Advance a dba_var_attr_iterator to point to the next attribute.

Parameters:
iter The iterator to work on
Returns:
The iterator to the next attribute, or NULL if there are no more attributes

void dba_var_clear_attrs ( dba_var  var  ) 

Remove all attributes from the variable.

Parameters:
var The variable to work on
Returns:
The error indicator for the function (See error.h)

dba_varcode dba_var_code ( dba_var  var  ) 

Retrieve the dba_varcode for a variable.

This function cannot fail, as dba_var always have a varcode value.

Parameters:
var Variable to query
Returns:
The dba_varcode for the variable. See vartable.h

dba_err dba_var_convert ( dba_var  orig,
dba_varinfo  info,
dba_var conv 
)

Convert a variable to an equivalent variable using different informations.

Parameters:
orig The variable to convert
info The dba_varinfo describing the target of the conversion
Return values:
conv The converted variable. It needs to be deallocated using dba_var_delete().
Returns:
The error indicator for the function (See error.h)

References DBA_RUN_OR_GOTO, and DBA_RUN_OR_RETURN.

dba_err dba_var_copy ( dba_var  source,
dba_var dest 
)

Make an exact copy of a dba_var.

Parameters:
source The variable to copy
Return values:
dest The new copy of source. It will need to be deallocated using dba_var_delete().
Returns:
The error indicator for the function (See error.h)

References DBA_RUN_OR_GOTO, and DBA_RUN_OR_RETURN.

dba_err dba_var_copy_attrs ( dba_var  dest,
dba_var  src 
)

Copy all the attributes from one variable to another.

Parameters:
dest The variable that will hold the attributes.
src The variable with the attributes to copy.
Returns:
The error indicator for the function (See error.h)

References DBA_RUN_OR_RETURN.

dba_err dba_var_copy_val ( dba_var  dest,
dba_var  orig 
)

Copy a value from a variable to another, performing conversions if needed.

Parameters:
dest The variable to write the value to
orig The variable to read the value from
Returns:
The error indicator for the function (See error.h)

References dba_convert_units(), DBA_RUN_OR_GOTO, _dba_varinfo::is_string, and _dba_varinfo::unit.

dba_err dba_var_create ( dba_varinfo  info,
dba_var var 
)

Create a new dba_var.

Parameters:
info The dba_varinfo that describes the variable
Return values:
var The variable created. It will need to be deallocated using dba_var_delete().
Returns:
The error indicator for the function (See error.h)

dba_err dba_var_create_local ( dba_varcode  code,
dba_var var 
)

Create a variable with informations from the local table.

Parameters:
code The dba_varcode that identifies the variable in the local B table. See vartable.h
Return values:
var The variable created. It will need to be deallocated using dba_var_delete().
Returns:
The error indicator for the function (See error.h)

References DBA_RUN_OR_RETURN.

dba_err dba_var_createc ( dba_varinfo  info,
const char *  val,
dba_var var 
)

Create a new dba_var, setting it to a character value.

Parameters:
info The dba_varinfo that describes the variable
val The initial value for the variable
Return values:
var The variable created. It will need to be deallocated using dba_var_delete().
Returns:
The error indicator for the function (See error.h)

References DBA_RUN_OR_GOTO, and DBA_RUN_OR_RETURN.

dba_err dba_var_created ( dba_varinfo  info,
double  val,
dba_var var 
)

Create a new dba_var, setting it to a double value.

Parameters:
info The dba_varinfo that describes the variable
val The initial value for the variable
Return values:
var The variable created. It will need to be deallocated using dba_var_delete().
Returns:
The error indicator for the function (See error.h)

References DBA_RUN_OR_GOTO, and DBA_RUN_OR_RETURN.

dba_err dba_var_createi ( dba_varinfo  info,
int  val,
dba_var var 
)

Create a new dba_var, setting it to an integer value.

Parameters:
info The dba_varinfo that describes the variable
val The initial value for the variable
Return values:
var The variable created. It will need to be deallocated using dba_var_delete().
Returns:
The error indicator for the function (See error.h)

References DBA_RUN_OR_GOTO, and DBA_RUN_OR_RETURN.

double dba_var_decode_int ( int  val,
dba_varinfo  info 
)

Decode a double value from integer value using varinfo encoding informations.

Parameters:
val Value to decode
info dba_varinfo structure to use for the encoding informations
Returns:
The decoded double value

References _dba_varinfo::ref, and _dba_varinfo::scale.

void dba_var_delete ( dba_var  var  ) 

Delete a dba_var.

Parameters:
var The variable to delete

void dba_var_diff ( dba_var  var1,
dba_var  var2,
int *  diffs,
FILE *  out 
)

Print the difference between two variables to an output stream.

If there is no difference, it does not print anything.

Parameters:
var1 The first variable to compare
var2 The second variable to compare
Return values:
diffs Incremented by 1 if the variables differ
Parameters:
out The output stream to use for printing

References DBA_VAR_F, DBA_VAR_X, and DBA_VAR_Y.

int dba_var_encode_int ( double  fval,
dba_varinfo  info 
)

Encode a double value into an integer value using varinfo encoding informations.

Parameters:
fval Value to encode
info dba_varinfo structure to use for the encoding informations
Returns:
The double value encoded as an integer

References _dba_varinfo::ref, and _dba_varinfo::scale.

dba_err dba_var_enqa ( dba_var  var,
dba_varcode  code,
dba_var attr 
)

Query variable attributes.

Parameters:
var The variable to query
code The dba_varcode of the attribute requested. See vartable.h
Return values:
attr A pointer to the attribute if it exists, else NULL. The pointer points to the internal representation and must not be deallocated by the caller.
Returns:
The error indicator for the function (See error.h)

dba_err dba_var_enqc ( dba_var  var,
const char **  val 
)

Get the value of a dba_var, as a string.

Parameters:
var The variable to query
Return values:
val The resulting value
Returns:
The error indicator for the function (See error.h)

References dba_error_notfound, DBA_VAR_X, and DBA_VAR_Y.

dba_err dba_var_enqd ( dba_var  var,
double *  val 
)

Get the value of a dba_var, as a double.

Parameters:
var The variable to query
Return values:
val The resulting value
Returns:
The error indicator for the function (See error.h)

References dba_error_notfound, dba_error_type, DBA_VAR_X, and DBA_VAR_Y.

dba_err dba_var_enqi ( dba_var  var,
int *  val 
)

Get the value of a dba_var, as an integer.

Parameters:
var The variable to query
Return values:
val The resulting value
Returns:
The error indicator for the function (See error.h)

References dba_error_notfound, dba_error_type, DBA_VAR_X, and DBA_VAR_Y.

int dba_var_equals ( const dba_var  var1,
const dba_var  var2 
)

Check if two variables contains the same data.

Parameters:
var1 First variable to compare
var2 Second variable to compare
Returns:
1 if the two variables have the same data, 0 otherwise

dba_varinfo dba_var_info ( dba_var  var  ) 

Get informations about the variable.

Parameters:
var The variable to query informations for
Returns:
info The dba_varinfo for the variable

void dba_var_print ( dba_var  var,
FILE *  out 
)

Print the variable to an output stream.

Parameters:
var The variable to print
out The output stream to use for printing

References DBA_VAR_F, DBA_VAR_X, and DBA_VAR_Y.

dba_err dba_var_seta ( dba_var  var,
dba_var  attr 
)

Set an attribute of the variable.

An existing attribute with the same dba_varcode will be replaced.

Parameters:
var The variable to work on
attr The attribute to add. It will be copied inside var, and memory management will still be in charge of the caller.
Returns:
The error indicator for the function (See error.h)

References DBA_RUN_OR_GOTO, and DBA_RUN_OR_RETURN.

dba_err dba_var_seta_nocopy ( dba_var  var,
dba_var  attr 
)

Set an attribute of the variable.

An existing attribute with the same dba_varcode will be replaced.

Parameters:
var The variable to work on
attr The attribute to add. It will be used directly, and var will take care of its memory management.
Returns:
The error indicator for the function (See error.h)

dba_err dba_var_setc ( dba_var  var,
const char *  val 
)

Set the value of a dba_var, from a string value.

Parameters:
var The variable to set
val The value to set
Returns:
The error indicator for the function (See error.h)

References dba_error_toolong, DBA_RUN_OR_RETURN, DBA_VAR_X, and DBA_VAR_Y.

dba_err dba_var_setd ( dba_var  var,
double  val 
)

Set the value of a dba_var, from a double value.

Parameters:
var The variable to set
val The value to set
Returns:
The error indicator for the function (See error.h)

References dba_error_toolong, dba_error_type, DBA_RUN_OR_RETURN, DBA_VAR_X, and DBA_VAR_Y.

dba_err dba_var_seti ( dba_var  var,
int  val 
)

Set the value of a dba_var, from an integer value.

Parameters:
var The variable to set
val The value to set
Returns:
The error indicator for the function (See error.h)

References dba_error_toolong, dba_error_type, DBA_RUN_OR_RETURN, DBA_VAR_X, and DBA_VAR_Y.

dba_err dba_var_unset ( dba_var  var  ) 

Unset the value of a dba_var.

Parameters:
var The variable to unset
Returns:
The error indicator for the function (See error.h)

dba_err dba_var_unseta ( dba_var  var,
dba_varcode  code 
)

Remove the attribute with the given code.

Parameters:
var The variable to work on
code The dba_varcode of the attribute to remove. See vartable.h
Returns:
The error indicator for the function (See error.h)

const char* dba_var_value ( dba_var  var  ) 

Retrieve the internal string representation of the value for a variable.

Parameters:
var Variable to query
Returns:
A const pointer to the internal string representation, or NULL if the variable is not defined.


Generated on Fri Aug 1 15:18:42 2008 for libdballe by  doxygen 1.5.6