.TH "corm_record" 3 "corm" \" -*- nroff -*- .ad l .nh .SH NAME corm_record \- Record-Aware Maps .PP \- Functions for record-aware (struct-aware) maps\&. .SH SYNOPSIS .br .PP .SS "Data Structures" .in +1c .ti -1c .RI "struct \fBcorm_record_field_t\fP" .br .RI "Describes a single field in a record layout\&. " .in -1c .SS "Typedefs" .in +1c .ti -1c .RI "typedef \fBcorm_record_field_t\fP \fBcorm_field_t\fP" .br .RI "Concise aliases for record schema operations\&. " .in -1c .SS "Functions" .in +1c .ti -1c .RI "uint32_t \fBcorm_record_register\fP (const char *name, size_t struct_size, const \fBcorm_record_field_t\fP *fields, size_t field_count)" .br .RI "Register a record layout describing a C struct\&. " .ti -1c .RI "uint32_t \fBcorm_record_type_id\fP (uint32_t record_id)" .br .RI "Get the struct type ID registered for a record\&. " .ti -1c .RI "const char * \fBcorm_get_key\fP (uint32_t hd, uint32_t pos)" .br .RI "Get the string key at a given position number\&. " .ti -1c .RI "uint32_t \fBcorm_pos\fP (uint32_t hd, const char *key)" .br .RI "Get the position number for a given key string\&. " .ti -1c .RI "size_t \fBcorm_inv_get\fP (uint32_t hd, const char *field_name, uint32_t target_pos, uint32_t *out, size_t max)" .br .RI "Query the inverse index for a reference field\&. " .ti -1c .RI "void \fBcorm_record_field_set_target_hd\fP (uint32_t record_id, const char *field_name, uint32_t target_hd)" .br .RI "Set the target head handle for reference resolution\&. " .ti -1c .RI "uint32_t \fBcorm_field_put\fP (uint32_t hd, const char *item_id, const char *field_name, const char *value)" .br .RI "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\&. " .ti -1c .RI "const char * \fBcorm_field_get\fP (uint32_t hd, const char *item_id, const char *field_name)" .br .RI "Get a field value from a record-aware map, auto-resolving references when the field is CM_REFERENCE\&. " .in -1c .SH "Detailed Description" .PP 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\&. .PP Usage: .PP .nf 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 .fi .PP .SH "Function Documentation" .PP .SS "const char * corm_field_get (uint32_t hd, const char * item_id, const char * field_name)" .PP Get a field value from a record-aware map, auto-resolving references when the field is CM_REFERENCE\&. Inverse of \fBcorm_field_put()\fP\&. .PP 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)\&. .PP \fBParameters\fP .RS 4 \fIhd\fP Record-aware map handle\&. .br \fIitem_id\fP Record key (entry ID)\&. .br \fIfield_name\fP Field name\&. .RE .PP \fBReturns\fP .RS 4 String value (corm-managed, do not free), or NULL\&. .RE .PP .SS "uint32_t corm_field_put (uint32_t hd, const char * item_id, const char * field_name, const char * value)" .PP 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 \fRvalue\fP (a string ID) to a position via corm_pos(target_hd, value) before calling corm_put\&. For CM_MULTI_REFERENCE: splits \fRvalue\fP on newlines, resolves each ID, and joins the positions with newlines\&. For CM_STR: passes \fRvalue\fP through unchanged\&. .PP \fBReturns\fP .RS 4 corm_put result (position number, or 0 on error)\&. .RE .PP .SS "const char * corm_get_key (uint32_t hd, uint32_t pos)" .PP Get the string key at a given position number\&. For record-aware maps this is the item ID (e\&.g\&. "choir1")\&. .PP \fBParameters\fP .RS 4 \fIhd\fP Map handle\&. .br \fIpos\fP Position number\&. .RE .PP \fBReturns\fP .RS 4 Key string, or NULL if pos is out of range\&. .RE .PP .SS "size_t corm_inv_get (uint32_t hd, const char * field_name, uint32_t target_pos, uint32_t * out, size_t max)" .PP Query the inverse index for a reference field\&. Returns all source positions that reference \fRtarget_pos\fP via the named reference field\&. .PP \fBParameters\fP .RS 4 \fIhd\fP Map handle\&. .br \fIfield_name\fP Reference field name\&. .br \fItarget_pos\fP Position in the target record-aware map\&. .br \fIout\fP Array to fill with source positions\&. .br \fImax\fP Capacity of out[]\&. .RE .PP \fBReturns\fP .RS 4 Number of positions written to out[]\&. .RE .PP .SS "uint32_t corm_pos (uint32_t hd, const char * key)" .PP 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\&. .PP \fBParameters\fP .RS 4 \fIhd\fP Map handle (must be record-aware, CM_STR keys)\&. .br \fIkey\fP Key string to look up\&. .RE .PP \fBReturns\fP .RS 4 Position number, or UINT32_MAX if not found\&. .RE .PP .SS "void corm_record_field_set_target_hd (uint32_t record_id, const char * field_name, uint32_t target_hd)" .PP Set the target head handle for reference resolution\&. After both source and target maps exist, configure a reference field so that \fBcorm_field_put()\fP can auto-resolve string IDs to positions via corm_pos(target_hd, id)\&. .PP \fBParameters\fP .RS 4 \fIrecord_id\fP Record ID from \fBcorm_record_register()\fP\&. .br \fIfield_name\fP Field name\&. .br \fItarget_hd\fP Head handle of the target map (e\&.g\&. song\&.items)\&. .RE .PP .SS "uint32_t corm_record_register (const char * name, size_t struct_size, const \fBcorm_record_field_t\fP * fields, size_t field_count)" .PP 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 \fBcorm_open()\fP\&. .PP \fBParameters\fP .RS 4 \fIname\fP Record name (for debugging, copied internally)\&. .br \fIstruct_size\fP sizeof(struct)\&. .br \fIfields\fP Array of field descriptors\&. .br \fIfield_count\fP Number of fields\&. .RE .PP \fBReturns\fP .RS 4 Record ID for use with CM_RECORD(), or CM_MISS on failure\&. .RE .PP .SS "uint32_t corm_record_type_id (uint32_t record_id)" .PP Get the struct type ID registered for a record\&. .PP \fBParameters\fP .RS 4 \fIrecord_id\fP Record ID from \fBcorm_record_register()\fP\&. .RE .PP \fBReturns\fP .RS 4 Type ID for use as vtype in \fBcorm_open()\fP, or CM_MISS\&. .RE .PP .SH "Author" .PP Generated automatically by Doxygen for corm from the source code\&.