Logo Search packages:      
Sourcecode: dballe version File versions

dba_err dba_record_var_set ( dba_record  rec,
dba_varcode  code,
dba_var  var 
)

Set the value of a parameter, from a dba_var. If dba_var has a value for a different parameter, it will be converted.

Parameters:
rec The record where the value is to be set.
code The variable to set the value for.
var A the dba_var with the parameter which will be copied inside the record. The record will copy the variable and will not take ownership of it: memory management will remain in charge of the caller.
Returns:
The error indicator for the function (
See also:
dba_err).

Definition at line 566 of file dba_record.c.

References DBA_RUN_OR_GOTO.

{
      assert_is_dba_record(rec);

      dba_err err = DBA_OK;
      dba_item i = NULL;

      /* If var is undef, remove this variable from the record */
      if (dba_var_value(var) == NULL)
            dba_record_remove_item(rec, code);
      else
      {
            /* Lookup the variable in the hash table */
            DBA_RUN_OR_GOTO(fail1, dba_record_obtain_item(rec, code, &i));

            /* Set the value of the variable */
            if (i->var != NULL)
            {
                  dba_var_delete(i->var);
                  i->var = NULL;
            }
            if (dba_var_code(var) == code)
                  DBA_RUN_OR_GOTO(fail1, dba_var_copy(var, &(i->var)));
            else
            {
                  dba_varinfo info;
                  DBA_RUN_OR_GOTO(fail1, dba_varinfo_query_local(code, &info));
                  DBA_RUN_OR_GOTO(fail1, dba_var_convert(var, info, &(i->var)));
            }
      }
      return dba_error_ok();
fail1:
      if (i != NULL)
            dba_record_remove_dba_item(rec, i);
      return err;
}


Generated by  Doxygen 1.6.0   Back to index