CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches

Functions

void stvarDestroy (stvar *stv)
 
void stvarCopy (stvar *dvar, stvar svar)
 

Detailed Description

Functions for managing variant lifetime and copying.

Function Documentation

◆ stvarCopy()

void stvarCopy ( stvar dvar,
stvar  svar 
)
inline

void stvarCopy(stvar *dest, stvar source)

Deep copy a variant to another variant.

Copies both the type descriptor and value, performing appropriate operations for the contained type (incrementing reference counts for objects, duplicating strings, etc.). The destination variant should be uninitialized or previously destroyed to avoid leaking resources.

Parameters
dvarPointer to destination variant (overwritten)
svarSource variant to copy (passed by value)

Example:

stvar original = stvar(string, _S"text");
stvar copy;
stvarCopy(&copy, original);
// Both variants now reference the string (refcount incremented)
stvarDestroy(&copy);
#define _S
Creates a static ASCII string from a string literal.
Definition strbase.h:392
#define stvar(typen, val)
Definition stvar.h:153
void stvarDestroy(stvar *stv)
Definition stvar.h:209
void stvarCopy(stvar *dvar, stvar svar)
Definition stvar.h:235

Definition at line 235 of file stvar.h.

◆ stvarDestroy()

void stvarDestroy ( stvar stv)
inline

void stvarDestroy(stvar *stv)

Destroy a variant and release its resources.

Invokes the type-appropriate destructor on the contained value (e.g., decrements reference counts for objects, frees strings) and resets the type to none. After destruction, the variant is in a valid but empty state and can be safely destroyed again or reassigned.

Parameters
stvPointer to variant to destroy

Example:

stvarCopy(&v, stvar(string, _S"hello"));
// ... use v ...
stvarDestroy(&v); // Releases string reference

Definition at line 209 of file stvar.h.