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

Modules

 Custom Type Integration
 

Macros

#define stDestroy(type, pobj, ...)    _stDestroy(stType(type), stArgPtr(type, pobj), opt_flags(__VA_ARGS__))
 
#define stCmp(type, obj1, obj2, ...)    _stCmp(stType(type), stArg(type, obj1), stArg(type, obj2), opt_flags(__VA_ARGS__))
 
#define stCopy(type, pdest, src, ...)    _stCopy(stType(type), stArgPtr(type, pdest), stArg(type, src), opt_flags(__VA_ARGS__))
 
#define stHash(type, obj, ...)   _stHash(stType(type), stArg(type, obj), opt_flags(__VA_ARGS__))
 
#define stConvert(desttype, pdest, srctype, src, ...)
 

Functions

stype stCanonical (stype st)
 
bool stEq (stype s1, stype s2)
 

Detailed Description

Type-safe wrappers for common operations on typed values. These macros expand to the appropriate function calls with compile-time type checking.

Macro Definition Documentation

◆ stCmp

#define stCmp (   type,
  obj1,
  obj2,
  ... 
)     _stCmp(stType(type), stArg(type, obj1), stArg(type, obj2), opt_flags(__VA_ARGS__))

intptr stCmp(type, obj1, obj2, [flags])

Compare two typed values for ordering.

Parameters
typeType name
obj1First value
obj2Second value
...(flags) Optional operation flags:
  • ST_CaseInsensitive: Case-insensitive comparison
  • ST_Equality: Only check equality, not ordering
Returns
Negative if obj1 < obj2, zero if equal, positive if obj1 > obj2

Example:

if (stCmp(string, s1, s2) == 0) {
// strings are equal
}
#define stCmp(type, obj1, obj2,...)
Definition stype.h:1662

Definition at line 1662 of file stype.h.

◆ stConvert

#define stConvert (   desttype,
  pdest,
  srctype,
  src,
  ... 
)
Value:
_stConvert(stType(desttype), \
stArgPtr(desttype, pdest), \
stType(srctype), \
stArg(srctype, src), \
opt_flags(__VA_ARGS__))
#define stType(name)
Definition stype.h:972
#define stArg(type, val)
Definition stype.h:1036
#define stArgPtr(type, val)
Definition stype.h:1091

bool stConvert(desttype, pdest, srctype, src, [flags])

Convert a value from one type to another.

WARNING: Overwrites destination without destroying existing value.

Parameters
desttypeDestination type name
pdestPointer to destination
srctypeSource type name
srcSource value
...(flags) Conversion flags:
  • ST_Overflow: Allow overflow without error
  • ST_Lossless: Fail if conversion loses precision
Returns
true if conversion succeeded

Example:

float32 f;
if (stConvert(float32, &f, int32, 42)) {
// f now contains 42.0
}
#define stConvert(desttype, pdest, srctype, src,...)
Definition stype.h:1812

Definition at line 1812 of file stype.h.

◆ stCopy

#define stCopy (   type,
  pdest,
  src,
  ... 
)     _stCopy(stType(type), stArgPtr(type, pdest), stArg(type, src), opt_flags(__VA_ARGS__))

void stCopy(type, pdest, src, [flags])

Copy a typed value from source to destination.

WARNING: Overwrites destination without destroying existing value. For managed types, the destination must be uninitialized or already destroyed.

Parameters
typeType name
pdestPointer to destination
srcSource value
...(flags) Optional operation flags

Example:

int32 dest; // uninitialized
stCopy(int32, &dest, 42);
#define stCopy(type, pdest, src,...)
Definition stype.h:1695

Definition at line 1695 of file stype.h.

◆ stDestroy

#define stDestroy (   type,
  pobj,
  ... 
)     _stDestroy(stType(type), stArgPtr(type, pobj), opt_flags(__VA_ARGS__))

void stDestroy(type, pobj, [flags])

Destroy a typed value, releasing any resources it owns.

Calls the appropriate destructor based on the type. For reference-counted types, decrements the reference count. For containers, recursively destroys elements. For primitives, this is typically a no-op.

Parameters
typeType name (e.g., string, int32, object)
pobjPointer to the value to destroy
...(flags) Optional operation flags

Example:

string s = _SL("hello");
stDestroy(string, &s); // s is now invalid
#define _SL(s)
Inline ASCII string literal with compile-time embedded length (STR_LEN8). Content must be < 200 bytes...
Definition strliteral.h:207
#define stDestroy(type, pobj,...)
Definition stype.h:1617

Definition at line 1617 of file stype.h.

◆ stHash

#define stHash (   type,
  obj,
  ... 
)    _stHash(stType(type), stArg(type, obj), opt_flags(__VA_ARGS__))

uint32 stHash(type, obj, [flags])

Compute a hash value for a typed value.

Parameters
typeType name
objValue to hash
...(flags) Optional operation flags:
  • ST_CaseInsensitive: Case-insensitive hash
Returns
32-bit hash value

Example:

uint32 h = stHash(string, s);
#define stHash(type, obj,...)
Definition stype.h:1731

Definition at line 1731 of file stype.h.

Function Documentation

◆ stCanonical()

stype stCanonical ( stype  st)
inline

stype stCanonical(stype st)

Return the canonical pointer for a type descriptor.

For static built-in types (STypeFlag_Temporary clear), returns st immediately - zero overhead. For dynamically constructed types (STypeFlag_Temporary set, e.g. opaque(MyStruct) compound literals or parameterized container types), looks up or inserts the descriptor in the global type registry and returns the stable canonical pointer. After the first call, all equivalent descriptors resolve to the same address.

Containers call stCanonical() automatically at init time. User code rarely needs to call this directly.

Parameters
stType descriptor (may be Temporary)
Returns
Canonical, non-Temporary type descriptor pointer

Definition at line 1763 of file stype.h.

References stHasFlag, and stType.

Referenced by stEq().

◆ stEq()

bool stEq ( stype  s1,
stype  s2 
)
inline

bool stEq(stype s1, stype s2)

Test whether two type descriptors refer to the same type.

Calls stCanonical() on both operands before comparing pointers. For static types this reduces to a single pointer comparison. Handles the case where one or both descriptors are Temporary compound literals that have not yet been registered.

Parameters
s1First type descriptor
s2Second type descriptor
Returns
true if both descriptors represent the same type

Definition at line 1785 of file stype.h.

References stCanonical().