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

Functions

bool setsBind (SSDNode *sets, SetsBindSpec *bindings, void *base)
 
void setsUnbindAll (SSDNode *sets)
 
void setsCheckBound (SSDNode *sets)
 
bool setsImport (SSDNode *sets, SetsBindSpec *bindings, void *base)
 
bool setsExport (SSDNode *sets, SetsBindSpec *bindings, void *base)
 

Detailed Description

Functions for binding settings paths to program variables for automatic synchronization.

Function Documentation

◆ setsBind()

bool setsBind ( SSDNode *  sets,
SetsBindSpec bindings,
void *  base 
)

Binds settings paths to program variables for automatic two-way synchronization.

Establishes connections between settings paths and program variables. When a setting is accessed, the bound variable is automatically updated. When the bound variable changes, the setting is updated at the next flush interval.

Important Notes:

  • bindings must be a static array terminated with a {0} entry (NULL name field)
  • Multiple calls will stack bindings, replacing only those with the same name
  • Variables are initialized from settings if they exist, otherwise from the default values
  • For strings, the module manages memory and will destroy old values when updating
Parameters
setsThe settings tree root
bindingsArray of binding specifications (must be NULL-terminated)
baseBase pointer to the structure containing the variables
Returns
true if all bindings were successfully established

Example:

static struct {
int32 width;
string name;
} config;
SetsBindSpec bindings[] = {
{ _S"width", offsetof(typeof(config), width), stvar(int32, 800) },
{ _S"name", offsetof(typeof(config), name), stvar(string, _S"default") },
{ 0 }
};
setsBind(settings, bindings, &config);
bool setsBind(SSDNode *sets, SetsBindSpec *bindings, void *base)
#define _S
Creates a static ASCII string from a string literal.
Definition strbase.h:392
#define stvar(typen, val)
Definition stvar.h:153

◆ setsCheckBound()

void setsCheckBound ( SSDNode *  sets)

Forces a full rescan of all bound variables at the next flush interval.

Normally bound variables are checked for changes only during flush operations. This function requests an immediate check of all bound variables at the next flush to detect any modifications and update the settings tree accordingly.

Parameters
setsThe settings tree root

◆ setsExport()

bool setsExport ( SSDNode *  sets,
SetsBindSpec bindings,
void *  base 
)

Saves variable values into settings without establishing bindings.

Copies values from the specified variables into the settings tree, but does not create ongoing synchronization. This is a one-time export operation.

Note: Currently not implemented.

Parameters
setsThe settings tree root
bindingsArray of binding specifications
baseBase pointer to the structure containing the variables
Returns
false (not yet implemented)

◆ setsImport()

bool setsImport ( SSDNode *  sets,
SetsBindSpec bindings,
void *  base 
)

Loads settings values into variables without establishing bindings.

Copies values from the settings tree into the specified variables, but does not create ongoing synchronization. This is a one-time import operation.

Note: Currently not implemented.

Parameters
setsThe settings tree root
bindingsArray of binding specifications
baseBase pointer to the structure containing the variables
Returns
false (not yet implemented)

◆ setsUnbindAll()

void setsUnbindAll ( SSDNode *  sets)

Removes all variable bindings from the settings tree.

Unbinds all variables that were previously bound with setsBind(). After calling this, variables will no longer be synchronized with settings.

Parameters
setsThe settings tree root