Previous: String Values, Up: Values [Contents][Index]
When a value’s type is only known at runtime, it is often represented
as a union value
, defined in data/value.h. A union value
does not identify the type or width of the data it contains. Code
that works with union values
s must therefore have external knowledge
of its content, often through the type and width of a
struct variable
(see Variables).
union value
has one member that clients are permitted to access
directly, a double
named ‘f’ that stores the content of a
numeric union value
. It has other members that store the content of
string union value
, but client code should use accessor functions
instead of referring to these directly.
PSPP provides some functions for working with union value
s. The
most useful are described below. To use these functions, recall that
a numeric value has a width of 0.
Initializes value as a value of the given width. After initialization, the data in value are indeterminate; the caller is responsible for storing initial data in it.
Frees auxiliary storage associated with value, which must have the given width.
For some widths, value_init
and value_destroy
do not
actually do anything, because no additional storage is needed beyond
the size of union value
. This function returns true if width
is such a width, which case there is no actual need to call those
functions. This can be a useful optimization if a large number of
union value
s of such a width are to be initialized or destroyed.
This function returns false if value_init
and
value_destroy
are actually required for the given width.
Copies the contents of union value
src to dst. Both
dst and src must have been initialized with the specified
width.
Sets value to SYSMIS
if it is numeric or to all spaces if
it is alphanumeric, according to width. value must have
been initialized with the specified width.
Determines whether value, which must have been initialized with the specified old_width, may be resized to new_width. Resizing is possible if the following criteria are met. First, old_width and new_width must be both numeric or both string widths. Second, if new_width is a short string width and less than old_width, resizing is allowed only if bytes new_width through old_width in value contain only spaces.
These rules are part of those used by mv_is_resizable
and
val_labs_can_set_width
.
Resizes value from old_width to new_width, which must be allowed by the rules stated above. value must have been initialized with the specified old_width before calling this function. After resizing, value has width new_width.
If new_width is greater than old_width, value will be padded on the right with spaces to the new width. If new_width is less than old_width, the rightmost bytes of value are truncated.
Compares of a and b, which must both have width width. Returns true if their contents are the same, false if they differ.
Compares of a and b, which must both have width width. Returns -1 if a is less than b, 0 if they are equal, or 1 if a is greater than b.
Numeric values are compared numerically, with SYSMIS
comparing
less than any real number. String values are compared
lexicographically byte-by-byte.
Computes and returns a hash of value, which must have the specified width. The value in basis is folded into the hash.
Previous: String Values, Up: Values [Contents][Index]