NAME
corm_record - Record-Aware Maps
- Functions for record-aware (struct-aware) maps.
SYNOPSIS
Data Structures
Describes a single field in a record layout.
Typedefs
Concise aliases for record schema operations.
Functions
Register a record layout describing a C struct.
Get the struct type ID registered for a record.
Get the string key at a given position number.
Get the position number for a given key string.
Query the inverse index for a reference field.
Set the target head handle for reference resolution.
Put a field value into a record-aware map, auto-resolving references when the field is CM_REFERENCE / CM_MULTI_REFERENCE and target_hd is set.
Get a field value from a record-aware map, auto-resolving references when the field is CM_REFERENCE.
Detailed Description
Functions for record-aware (struct-aware) maps.
Record-aware maps store C struct values by-key and automatically resolve composite keys (e.g. "id:fieldname") to field offsets within the stored struct. No per-field entries are stored โ the struct is the single source of truth.
Usage:
typedef struct { char title[256]; uint32_t age; } item_t;
uint32_t rec = corm_record_register("item",
sizeof(item_t),
(corm_record_field_t[]){
{ "title", CM_STR, offsetof(item_t, title),
sizeof(((item_t*)0)->title) },
{ "age", CM_U32, offsetof(item_t, age),
sizeof(uint32_t) },
}, 2);
uint32_t hd = corm_open(NULL, NULL, CM_STR,
corm_record_type_id(rec),
0xFF, CM_RECORD(rec));
item_t row = { .title = "Hello", .age = 42 };
corm_put(hd, "item1", &row); // store whole struct
const char *t = corm_get(hd, "item1:title"); // โ &row.title
const uint32_t *a = corm_get(hd, "item1:age"); // โ &row.age
Function Documentation
const char * corm_field_get (uint32_t hd, const char * item_id, const char * field_name)
Get a field value from a record-aware map, auto-resolving references when the field is CM_REFERENCE. Inverse of corm_field_put().
For CM_STR: returns the string value directly (points into struct memory). For CM_REFERENCE: resolves the stored position back to the target ID string via corm_get_key(target_hd, pos). For CM_MULTI_REFERENCE and other types: returns the raw value pointer (caller must know the type).
Parameters
hd Record-aware map handle.
item_id Record key (entry ID).
field_name Field name.
Returns
String value (corm-managed, do not free), or NULL.
uint32_t corm_field_put (uint32_t hd, const char * item_id, const char * field_name, const char * value)
Put a field value into a record-aware map, auto-resolving references when the field is CM_REFERENCE / CM_MULTI_REFERENCE and target_hd is set. For CM_REFERENCE: resolves value (a string ID) to a position via corm_pos(target_hd, value) before calling corm_put. For CM_MULTI_REFERENCE: splits value on newlines, resolves each ID, and joins the positions with newlines. For CM_STR: passes value through unchanged.
Returns
corm_put result (position number, or 0 on error).
const char * corm_get_key (uint32_t hd, uint32_t pos)
Get the string key at a given position number. For record-aware maps this is the item ID (e.g. "choir1").
Parameters
hd Map handle.
pos Position number.
Returns
Key string, or NULL if pos is out of range.
size_t corm_inv_get (uint32_t hd, const char * field_name, uint32_t target_pos, uint32_t * out, size_t max)
Query the inverse index for a reference field. Returns all source positions that reference target_pos via the named reference field.
Parameters
hd Map handle.
field_name Reference field name.
target_pos Position in the target record-aware map.
out Array to fill with source positions.
max Capacity of out[].
Returns
Number of positions written to out[].
uint32_t corm_pos (uint32_t hd, const char * key)
Get the position number for a given key string. Performs an O(n) linear scan of the map entries. Used when converting filesystem string IDs to position numbers for reference fields.
Parameters
hd Map handle (must be record-aware, CM_STR keys).
key Key string to look up.
Returns
Position number, or UINT32_MAX if not found.
void corm_record_field_set_target_hd (uint32_t record_id, const char * field_name, uint32_t target_hd)
Set the target head handle for reference resolution. After both source and target maps exist, configure a reference field so that corm_field_put() can auto-resolve string IDs to positions via corm_pos(target_hd, id).
Parameters
record_id Record ID from corm_record_register().
field_name Field name.
target_hd Head handle of the target map (e.g. song.items).
uint32_t corm_record_register (const char * name, size_t struct_size, const corm_record_field_t * fields, size_t field_count)
Register a record layout describing a C struct. Internally calls corm_reg(struct_size) to create a fixed-length type for the struct. The returned record_id is used with CM_RECORD(record_id) in corm_open().
Parameters
name Record name (for debugging, copied internally).
struct_size sizeof(struct).
fields Array of field descriptors.
field_count Number of fields.
Returns
Record ID for use with CM_RECORD(), or CM_MISS on failure.
uint32_t corm_record_type_id (uint32_t record_id)
Get the struct type ID registered for a record.
Parameters
record_id Record ID from corm_record_register().
Returns
Type ID for use as vtype in corm_open(), or CM_MISS.
Author
Generated automatically by Doxygen for corm from the source code.