|
CX Framework
Cross-platform C utility framework
|
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) |
Type-safe wrappers for common operations on typed values. These macros expand to the appropriate function calls with compile-time type checking.
| #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.
| type | Type name |
| obj1 | First value |
| obj2 | Second value |
| ... | (flags) Optional operation flags:
|
Example:
| #define stConvert | ( | desttype, | |
| pdest, | |||
| srctype, | |||
| src, | |||
| ... | |||
| ) |
bool stConvert(desttype, pdest, srctype, src, [flags])
Convert a value from one type to another.
WARNING: Overwrites destination without destroying existing value.
| desttype | Destination type name |
| pdest | Pointer to destination |
| srctype | Source type name |
| src | Source value |
| ... | (flags) Conversion flags:
|
Example:
| #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.
| type | Type name |
| pdest | Pointer to destination |
| src | Source value |
| ... | (flags) Optional operation flags |
Example:
| #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.
| type | Type name (e.g., string, int32, object) |
| pobj | Pointer to the value to destroy |
| ... | (flags) Optional operation flags |
Example:
uint32 stHash(type, obj, [flags])
Compute a hash value for a typed value.
| type | Type name |
| obj | Value to hash |
| ... | (flags) Optional operation flags:
|
Example:
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.
| st | Type descriptor (may be Temporary) |
Definition at line 1763 of file stype.h.
References stHasFlag, and stType.
Referenced by stEq().
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.
| s1 | First type descriptor |
| s2 | Second type descriptor |
Definition at line 1785 of file stype.h.
References stCanonical().