Symisc Vedis

An Embeddable Datastore Engine



Vedis C/C++ API Reference - Array Type Processing.

Syntax

int vedis_array_walk(

      vedis_value *pArray,

      int (*xWalk)(vedis_value *pEntry,void *pUserData),

      void *pUserData

);


Iterate over the elements of a given array and invoke the supplied callback for each entry.


Description


This routine iterate over the elements of a given array and invokes the supplied walker callback for each entry. The first argument (pArray) must be of type array obtained by a prior successful call to vedis_context_new_array() or passed as parameter to the foreign command. Otherwise, this routine return immediately and the walk process could not be done.


The most interesting parameter is the walker callback (xWalk()) which is a user defined function that is invoked for each array entry. The callback must accept two arguments. The first argument is the entry value which could be any type even others arrays and the last argument is a copy of the third argument to this function which is forwarded verbatim by engine.

The callback must return VEDIS_OK. Otherwise the walk process is aborted and this function return VEDIS_ABORT.


The entry value could be extracted inside the callback using these interfaces:


vedis_value_to_int()

vedis_value_to_bool()

vedis_value_to_int64()

vedis_value_to_double()

vedis_value_to_string()


Note: This routine is not thread-safe.


Parameters


pArray

vedis_value which must be of type array.

  xWalk

Walker callback which is invoked for each array entry. If the callback wishes to abort the walk process, it must return a value different from VEDIS_OK such as VEDIS_ABORT.

  pUserDara

Arbitrary user pointer which is forwarded verbatim by the engine to the walker callback as its third argument.


Return value


VEDIS_OK is returned on success. Any other return value typically (VEDIS_ABORT) indicates failure.


Example


Compile this C file for a smart introduction to the array handling interfaces.


See also


vedis_array_insert, vedis_array_next_elem, vedis_array_fetch.



Symisc Systems
Copyright © Symisc Systems