|
CX Framework
Cross-platform C utility framework
|
Macros | |
| #define | stTypeCast(name, v) ((SType_##name)(v)) |
| #define | stPtrCast(name, v) ((SType_##name*)(v)) |
| #define | stvarTypeId(v) (stvarType(v)->id) |
| #define | stTypeId(name) STypeId_##name |
| #define | stTypeSize(name) STypeSize_##name |
| #define | stHasFlag(st, fname) (((st)->flags & stFlag(fname)) != 0) |
| #define | stGetSize(st) ((st)->size) |
| #define | stCheck(type, val) STypeCheck_##type(type, val) |
| #define | stCheckPtr(type, ptr) STypeCheckPtr_##type(type, ptr) |
| #define | stRvalAddr(type, rval) ((stStorageType(type)[1]) { rval }) |
Functions | |
| stype | stvarType (const stvar *v) |
| const char * | stvarKey (const stvar *v) |
Utility macros for type casting, checking, and manipulation.
| #define stCheck | ( | type, | |
| val | |||
| ) | STypeCheck_##type(type, val) |
value stCheck(type, value)
Perform compile-time type checking on a value.
For primitive types, this is a no-op that returns the value unchanged. For object types (strings, objects, containers), verifies the value has the expected structure marker, providing compile-time type safety.
This is used internally by the argument passing macros but can also be used directly for type validation.
| type | Type name |
| val | Value to check |
Example:
| #define stCheckPtr | ( | type, | |
| ptr | |||
| ) | STypeCheckPtr_##type(type, ptr) |
pointer stCheckPtr(type, pointer)
Perform compile-time type checking on a pointer to a value.
Similar to stCheck() but for pointers. Validates that the pointer points to the expected type.
| type | Type name |
| ptr | Pointer to check |
| #define stGetSize | ( | st | ) | ((st)->size) |
uint16 stGetSize(stype st)
Extract the storage size from a type descriptor. Equivalent to st->size.
| st | Type descriptor |
| #define stHasFlag | ( | st, | |
| fname | |||
| ) | (((st)->flags & stFlag(fname)) != 0) |
bool stHasFlag(stype st, flagname)
Check if a type descriptor has a specific flag set.
| st | Type descriptor |
| fname | Flag name (Object, Custom, or PassPtr) |
Example:
| #define stPtrCast | ( | name, | |
| v | |||
| ) | ((SType_##name*)(v)) |
<type>* stPtrCast(type, value)
Cast a pointer to a pointer-to-type for the given stype name.
| name | Type name |
| v | Pointer to cast |
Example:
| #define stRvalAddr | ( | type, | |
| rval | |||
| ) | ((stStorageType(type)[1]) { rval }) |
stStorageType(type)* stRvalAddr(type, rvalue)
Create an lvalue from an rvalue expression.
Uses C99 compound literals to create a temporary on the stack, allowing pointers to be taken of arbitrary expressions. This is primarily used internally for pass-by-pointer types (SUID, stvar, opaque) that need to pass rvalues where a pointer is required.
| type | Type name |
| rval | Rvalue expression |
Example (internal use):
| #define stTypeCast | ( | name, | |
| v | |||
| ) | ((SType_##name)(v)) |
<type> stTypeCast(type, value)
Cast a value to the appropriate C type for the given stype name.
| name | Type name (e.g., int32, string, object) |
| v | Value to cast |
Example:
| #define stTypeId | ( | name | ) | STypeId_##name |
uint32 stTypeId(type)
Get the compile-time type ID constant for a type name.
| name | Type name |
Example:
| #define stTypeSize | ( | name | ) | STypeSize_##name |
size_t stTypeSize(type)
Get the compile-time storage size for a type name.
| name | Type name |
Example:
| #define stvarTypeId | ( | v | ) | (stvarType(v)->id) |
uint32 stvarTypeId(const stvar *v)
Returns the type ID of the value contained in a variant.
Convenience shorthand for stvarType(v)->id. Handy for switch statements over a variant's runtime type using the stTypeId() constants.
| v | Pointer to variant |
Example:
|
inline |
const char* stvarKey(const stvar *v)
Returns the key attached to a variant, or NULL if it has none.
Keyed variants are created with stvark() (or stvarkn()), which attaches a name so the variant can be located by key instead of by type and position. The name is a plain C string rather than a cx string – there is no portable way to embed a length inside an expression macro, and keys are short enough that a plain compare costs nothing.
The name is metadata: it is preserved by copy, but deliberately ignored by compare and hash, so attaching a key never changes a variant's value semantics in a container.
| v | Pointer to variant |
Example:
stype stvarType(const stvar *v)
Returns the canonical type descriptor for a variant.
| v | Pointer to variant |
Definition at line 457 of file stype.h.
Referenced by stvarCopy().