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

Macros

#define ssdExportArray(root, path, out)    _ssdExportArray(root, path, out, (SSDLockState*)_ssdCurrentLockState)
 
#define ssdImportArray(root, path, arr)    _ssdImportArray(root, path, arr, (SSDLockState*)_ssdCurrentLockState)
 
#define ssdExportTypedArray(root, path, type, out, strict)
 
#define ssdImportTypedArray(root, path, type, arr)    _ssdImportTypedArray(root, path, stType(type), SAREF(arr), (SSDLockState*)_ssdCurrentLockState)
 
#define ssdCount(root, path, arrayonly)    _ssdCount(root, path, arrayonly, (SSDLockState*)_ssdCurrentLockState)
 
#define ssdIndex(root, path, idx)    _ssdIndex(root, path, idx, (SSDLockState*)&_ssdCurrentLockState->_is_SSDLockState)
 
#define ssdAppend(root, path, createpath, val)    _ssdAppend(root, path, createpath, val, (SSDLockState*)_ssdCurrentLockState)
 

Detailed Description

Functions for importing/exporting arrays and working with array nodes.

Macro Definition Documentation

◆ ssdAppend

#define ssdAppend (   root,
  path,
  createpath,
  val 
)     _ssdAppend(root, path, createpath, val, (SSDLockState*)_ssdCurrentLockState)

bool ssdAppend(SSDNode *root, strref path, bool createpath, stvar val)

Appends a value to an array at the given path.

If the array doesn't exist and createpath is true, it will be created automatically.

Parameters
rootThe root node
pathPath to the array node (NULL to append to root if it's an array)
createpathIf true, create the array if it doesn't exist
valValue to append (copied)
Returns
true on success, false if the node exists but isn't an array

Example:

ssdAppend(root, _S"items", true, stvar(string, _S"apple"));
ssdAppend(root, _S"items", true, stvar(string, _S"banana"));
#define ssdAppend(root, path, createpath, val)
Definition ssdtree.h:675
#define _S
Creates a static ASCII string from a string literal.
Definition strbase.h:392
#define stvar(typen, val)
Definition stvar.h:153

Definition at line 675 of file ssdtree.h.

◆ ssdCount

#define ssdCount (   root,
  path,
  arrayonly 
)     _ssdCount(root, path, arrayonly, (SSDLockState*)_ssdCurrentLockState)

int32 ssdCount(SSDNode *root, strref path, bool arrayonly)

Returns the number of children/elements at the given path.

Parameters
rootThe root node
pathPath to the node to count
arrayonlyIf true, returns 0 for hashtable nodes
Returns
Number of elements, or 0 if not found or empty

Definition at line 635 of file ssdtree.h.

◆ ssdExportArray

#define ssdExportArray (   root,
  path,
  out 
)     _ssdExportArray(root, path, out, (SSDLockState*)_ssdCurrentLockState)

bool ssdExportArray(SSDNode *root, strref path, sa_stvar *out)

Exports an array node to a dynamic array of stvars.

The output array must be either initialized or point to NULL. The function will populate it with copies of all values in the SSD array node.

Parameters
rootThe root node
pathPath to the array node
outPointer to sa_stvar (initialized or NULL)
Returns
true on success, false if path doesn't point to an array

Definition at line 557 of file ssdtree.h.

◆ ssdExportTypedArray

#define ssdExportTypedArray (   root,
  path,
  type,
  out,
  strict 
)
Value:
_ssdExportTypedArray(root, \
path, \
stType(type), \
SAHANDLE(out), \
strict, \
(SSDLockState*)_ssdCurrentLockState)
#define stType(name)
Definition stype.h:822

bool ssdExportTypedArray(SSDNode *root, strref path, type, sahandle out, bool strict)

Exports an array node to a typed dynamic array.

The output array must be either initialized or point to NULL. Values are converted to the specified element type during export.

Parameters
rootThe root node
pathPath to the array node
typeThe desired element type
outPointer to typed sarray (initialized or NULL)
strictIf true, fails on type mismatch; if false, skips incompatible items
Returns
true on success, false on failure

Example:

sa_int32 values;
saInit(&values, int32, 0);
if (ssdExportTypedArray(root, _S"scores", int32, &values, false)) {
// use values.a[]
}
saDestroy(&values);
#define saDestroy(handle)
Definition sarray.h:348
#define saInit(out, type, capacity,...)
Definition sarray.h:318
#define ssdExportTypedArray(root, path, type, out, strict)
Definition ssdtree.h:604

Definition at line 604 of file ssdtree.h.

◆ ssdImportArray

#define ssdImportArray (   root,
  path,
  arr 
)     _ssdImportArray(root, path, arr, (SSDLockState*)_ssdCurrentLockState)

bool ssdImportArray(SSDNode *root, strref path, sa_stvar arr)

Imports a dynamic array of stvars into an array node.

Creates an array node at the specified path and populates it with the values.

Parameters
rootThe root node
pathPath where to create/replace the array
arrThe source array of stvars
Returns
true on success, false on failure

Definition at line 573 of file ssdtree.h.

◆ ssdImportTypedArray

#define ssdImportTypedArray (   root,
  path,
  type,
  arr 
)     _ssdImportTypedArray(root, path, stType(type), SAREF(arr), (SSDLockState*)_ssdCurrentLockState)

bool ssdImportTypedArray(SSDNode *root, strref path, type, sa_ref arr)

Imports a typed dynamic array into an array node.

Parameters
rootThe root node
pathPath where to create/replace the array
typeThe element type of the source array
arrReference to the source array
Returns
true on success, false on failure

Definition at line 621 of file ssdtree.h.

◆ ssdIndex

#define ssdIndex (   root,
  path,
  idx 
)     _ssdIndex(root, path, idx, (SSDLockState*)&_ssdCurrentLockState->_is_SSDLockState)

stvar *ssdIndex(SSDNode *root, strref path, int32 idx)

Gets a pointer to a specific array element by index.

CRITICAL: Like ssdPtr(), this requires a lock via ssdLockedTransaction(). The pointer is only valid while the lock is held.

Parameters
rootThe root node
pathPath to the array node
idxArray index to access
Returns
Pointer to the element's stvar, or NULL if not found

Definition at line 652 of file ssdtree.h.