|
CX Framework
Cross-platform C utility framework
|
Macros | |
| #define | stTypeCast(name, v) ((SType_##name)(v)) |
| #define | stPtrCast(name, v) ((SType_##name*)(v)) |
| #define | stTypeId(name) STypeId_##name |
| #define | stTypeSize(name) STypeSize_##name |
| #define | stHasFlag(st, fname) ((st >> 8) & stFlag(fname)) |
| #define | stGetId(st) (st & 0xff) |
| #define | stGetFlags(st) ((st >> 8) & 0xff) |
| #define | stGetSize(st) (st >> 16) |
| #define | stTypeFlags(name) STypeFlags_##name |
| #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 | |
| bool | stEq (stype sta, stype stb) |
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 stGetFlags | ( | st | ) | ((st >> 8) & 0xff) |
uint8 stGetFlags(stype st)
Extract the flags byte from a type descriptor.
| st | Type descriptor |
| #define stGetId | ( | st | ) | (st & 0xff) |
uint8 stGetId(stype st)
Extract the type ID from a type descriptor.
| st | Type descriptor |
| #define stGetSize | ( | st | ) | (st >> 16) |
uint16 stGetSize(stype st)
Extract the size from a type descriptor.
| st | Type descriptor |
| #define stHasFlag | ( | st, | |
| fname | |||
| ) | ((st >> 8) & stFlag(fname)) |
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)) |
SType_<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)) |
SType_<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 stTypeFlags | ( | name | ) | STypeFlags_##name |
uint8 stTypeFlags(type)
Get the compile-time default flags for a type name.
| name | Type name |
| #define stTypeId | ( | name | ) | STypeId_##name |
uint8 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:
|
inline |
bool stEq(stype sta, stype stb)
Compare two type descriptors for equivalence.
Ignores the Custom flag, so custom(int32) compares equal to int32.
| sta | First type descriptor |
| stb | Second type descriptor |