@c -*-texinfo-*-
@c This is part of the GNU G-Golf Reference Manual.
@c Copyright (C) 2016 - 2025 Free Software Foundation, Inc.
@c See the file g-golf.texi for copying conditions.


@node Union
@subsection Union

G-Golf class, accessors, methods and procedures to deal with C union
types.

@subheading Classes

@indentedblock
@table @code
@item @ref{<gi-union>}
@end table
@end indentedblock

@subheading Procedures, Accessors and Methods

@indentedblock
@table @code
@item @ref{make-c-union}
@item @ref{c-union-ref}
@item @ref{c-union-set!}
@item @ref{!g-type__}
@item @ref{!g-name__}
@item @ref{!name___}
@item @ref{!size_}
@item @ref{!alignment_}
@item @ref{!fields}
@item @ref{!is-discriminated?}
@item @ref{!discriminator-offset}
@item @ref{!discriminator}
@end table
@end indentedblock


@c @subheading Types and Values


@subheading Description

G-Golf class, accessors, methods and procedures to deal with C union
types.


@subheading Classes



@anchor{<gi-union>}
@deftp Class <gi-union>

The @code{<gi-union>} class. Its @code{class-direct-slots} are:

@indentedblock
@table @code
@item @emph{g-type}
#:accessor !g-type @*
#:init-keyword #:g-type

@item @emph{g-name}
#:accessor !g-name @*
#:init-keyword #:g-name

@item @emph{name}
#:accessor !name

@item @emph{size}
#:accessor !size @*
#:init-keyword #:size

@item @emph{alignment}
#:accessor !alignment @*
#:init-keyword #:alignment

@item @emph{fields}
#:accessor !fields @*
#:init-keyword #:fields

@item @emph{is-discrimanted?}
#:accessor !is-discriminated? @*
#:init-keyword #:is-discriminated?

@item @emph{discriminator-offset}
#:accessor !discriminator-offset @*
#:init-keyword #:discriminator-offset

@item @emph{discriminator}
#:accessor !discriminator
#:init-keyword #:discriminator
#:init-value #f
@end table
@end indentedblock

The @code{name} slot is automatically initialized.

Instances of the @code{<gi-union>} are immutable (to be precise, there
are not meant to be mutated, see @ref{GOOPS Notes - Conventions - Recommendations},
'Slots are not Immutable').
@end deftp



@subheading Procedures, Accessors and Methods


@anchor{make-c-union}
@deffn Procedure make-c-union types [type #f] [val #f]

Returns a pointer.

Create a foreign pointer to a C union for the list of @var{types} (see
@uref{@value{UGUILE-FOREIGN-TYPES}, Foreign Types} in the Guile
Reference Manual for a list of supported types).
@end deffn


@anchor{c-union-ref}
@deffn Procedure c-union-ref foreign size type

Returns the content of the C union pointed by @var{foreign}, for the
given @var{size} and @var{type}.
@end deffn


@anchor{c-union-set!}
@deffn Procedure c-union-set! foreign size type val

Returns nothing.

Sets the content of the C union pointed by @var{foreign} to @var{val},
given its @var{size} and @var{type}.
@end deffn


@anchor{!g-type__}
@anchor{!g-name__}
@anchor{!name___}
@anchor{!size_}
@anchor{!alignment_}
@anchor{!fields}
@anchor{!is-discriminated?}
@anchor{!discriminator-offset}
@anchor{!discriminator}
@deffn Accessor !g-type (inst <gi-union>)
@deffnx Accessor !g-name (inst <gi-union>)
@deffnx Accessor !name (inst <gi-union>)
@deffnx Accessor !size (inst <gi-union>)
@deffnx Accessor !alignment (inst <gi-union>)
@deffnx Accessor !fields (inst <gi-union>)
@deffnx Accessor !is-discriminated? (inst <gi-union>)
@deffnx Accessor !discriminator-offset (inst <gi-union>)
@deffnx Accessor !discriminator (inst <gi-union>)

Returns the content of their respective slot for @var{inst}.
@end deffn



@c @subheading Types and Values
