Skip to content

ReadStat api updates #65

Closed
Closed

Description

Variable handlers now take 4 arguments instead of 7, using the readstat_variable_t to wrap the values that were previously passed separately. New callback signature:

typedef int (*readstat_variable_handler)(int index, readstat_variable_t *variable,
const char *val_labels, void *ctx);

You can access the previous values with new accessor functions:

const char *readstat_variable_get_name(readstat_variable_t *variable);
const char *readstat_variable_get_label(readstat_variable_t *variable);
const char *readstat_variable_get_format(readstat_variable_t *variable);
readstat_types_t readstat_variable_get_type(readstat_variable_t *variable);

In the future I'd like to stuff the value labels into the variable argument, and eliminate the value labels handler altogether, but this is not implemented.


The motivation here was adding support for missing value definitions. To access the definitions with SPSS files inside the variable handler, you can use:

int readstat_variable_get_missing_ranges_count(readstat_variable_t *variable);
readstat_value_t readstat_variable_get_missing_range_lo(readstat_variable_t *variable, int i);
readstat_value_t readstat_variable_get_missing_range_hi(readstat_variable_t *variable, int i);

"lo" and "hi" represent the lower and upper bounds of the missing range -- if lo == hi, then it's a single missing value rather than a contiguous range.


readstat_value_is_missing is now supplemented with two more functions to distinguish system-missing (e.g. NaN values) from values that are considered missing on account of the missing value definitions:

int readstat_value_is_system_missing(readstat_value_t value);
int readstat_value_is_considered_missing(readstat_value_t value);

But you can continue to use readstat_value_is_missing, which is just an OR of those two functions.


The underlying representation of readstat_value_t is no longer a pointer to a primitive value; instead, it's a struct + union that includes missingness information as well as the value type. As an added convenience, readstat_double_value etc. will do appropriate casting from other numeric types. Your existing accessor code should continue to work, but you might be able to simplify it with the new automatic casting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions