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

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)
 

Detailed Description

Utility macros for type casting, checking, and manipulation.

Macro Definition Documentation

◆ stCheck

#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.

Parameters
typeType name
valValue to check
Returns
The value, unchanged (with compile-time validation)

Example:

string s = ...;
string checked = stCheck(string, s); // Validates s is a string
#define stCheck(type, val)
Definition stype.h:669

Definition at line 669 of file stype.h.

◆ stCheckPtr

#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.

Parameters
typeType name
ptrPointer to check
Returns
The pointer, unchanged (with compile-time validation)

Definition at line 710 of file stype.h.

◆ stGetFlags

#define stGetFlags (   st)    ((st >> 8) & 0xff)

uint8 stGetFlags(stype st)

Extract the flags byte from a type descriptor.

Parameters
stType descriptor
Returns
Flags byte (bits 8-15)

Definition at line 515 of file stype.h.

◆ stGetId

#define stGetId (   st)    (st & 0xff)

uint8 stGetId(stype st)

Extract the type ID from a type descriptor.

Parameters
stType descriptor
Returns
Type ID (bits 0-7)

Definition at line 507 of file stype.h.

◆ stGetSize

#define stGetSize (   st)    (st >> 16)

uint16 stGetSize(stype st)

Extract the size from a type descriptor.

Parameters
stType descriptor
Returns
Size in bytes (bits 16-31)

Definition at line 523 of file stype.h.

◆ stHasFlag

#define stHasFlag (   st,
  fname 
)    ((st >> 8) & stFlag(fname))

bool stHasFlag(stype st, flagname)

Check if a type descriptor has a specific flag set.

Parameters
stType descriptor
fnameFlag name (Object, Custom, or PassPtr)
Returns
true if flag is set

Example:

if (stHasFlag(st, Object)) {
// This is an object-like type
}
#define stHasFlag(st, fname)
Definition stype.h:490

Definition at line 490 of file stype.h.

◆ stPtrCast

#define stPtrCast (   name,
 
)    ((SType_##name*)(v))

SType_<type>* stPtrCast(type, value)

Cast a pointer to a pointer-to-type for the given stype name.

Parameters
nameType name
vPointer to cast
Returns
Pointer cast to pointer-to-type

Example:

void* ptr = ...;
int32* iptr = stPtrCast(int32, ptr);
#define stPtrCast(name, v)
Definition stype.h:283

Definition at line 283 of file stype.h.

◆ stRvalAddr

#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.

Parameters
typeType name
rvalRvalue expression
Returns
Pointer to a stack-allocated temporary containing the value

Example (internal use):

// Allows passing SUID literals where SUID* is expected
stRvalAddr(suid, suidMake())
#define stRvalAddr(type, rval)
Definition stype.h:732

Definition at line 732 of file stype.h.

◆ stTypeCast

#define stTypeCast (   name,
 
)    ((SType_##name)(v))

SType_<type> stTypeCast(type, value)

Cast a value to the appropriate C type for the given stype name.

Parameters
nameType name (e.g., int32, string, object)
vValue to cast
Returns
Value cast to the appropriate type

Example:

void* ptr = ...;
string s = stTypeCast(string, ptr);
#define stTypeCast(name, v)
Definition stype.h:268

Definition at line 268 of file stype.h.

◆ stTypeFlags

#define stTypeFlags (   name)    STypeFlags_##name

uint8 stTypeFlags(type)

Get the compile-time default flags for a type name.

Parameters
nameType name
Returns
Default flags for the type

Definition at line 580 of file stype.h.

◆ stTypeId

#define stTypeId (   name)    STypeId_##name

uint8 stTypeId(type)

Get the compile-time type ID constant for a type name.

Parameters
nameType name
Returns
Type ID enum value (STypeId_xxx)

Example:

stype st = ...;
if (stGetId(st) == stTypeId(int32)) { ... }
#define stGetId(st)
Definition stype.h:507
#define stTypeId(name)
Definition stype.h:419

Definition at line 419 of file stype.h.

◆ stTypeSize

#define stTypeSize (   name)    STypeSize_##name

size_t stTypeSize(type)

Get the compile-time storage size for a type name.

Parameters
nameType name
Returns
Size in bytes

Example:

void* buffer = xaAlloc(stTypeSize(MyStruct) * count);
#define stTypeSize(name)
Definition stype.h:466
#define xaAlloc(size,...)
Definition xalloc.h:199

Definition at line 466 of file stype.h.

Function Documentation

◆ stEq()

bool stEq ( stype  sta,
stype  stb 
)
inline

bool stEq(stype sta, stype stb)

Compare two type descriptors for equivalence.

Ignores the Custom flag, so custom(int32) compares equal to int32.

Parameters
staFirst type descriptor
stbSecond type descriptor
Returns
true if types are equivalent

Definition at line 537 of file stype.h.