Harlequin RIP SDK

A structure containing callback functions for structured data access. More...

#include "swdataapi.h"

Data Fields

sw_api_info info
 
sw_data_result(* get_indexed )(const sw_datum *array, size_t index, sw_datum *value)
 Get an indexed value from an array or stack datum. More...
 
sw_data_result(* set_indexed )(sw_datum *array, size_t index, const sw_datum *value)
 Store an indexed value in an array or stack datum. More...
 
sw_data_result(* get_keyed )(const sw_datum *dict, const sw_datum *key, sw_datum *value)
 Get a keyed value from a dictionary datum. More...
 
sw_data_result(* set_keyed )(sw_datum *dict, const sw_datum *key, const sw_datum *value)
 Store a keyed value in a dictionary datum. More...
 
sw_data_result(* match )(const sw_datum *composite, sw_data_match *match, size_t match_length)
 Match multiple data entries in a dictionary or array datum. More...
 
sw_data_result(* iterate_begin )(const sw_datum *composite, sw_data_iterator **iterator)
 Start a new iteration over a dictionary or array datum. More...
 
sw_data_result(* iterate_next )(const sw_datum *composite, sw_data_iterator *iterator, sw_datum *key, sw_datum *value)
 Get a key-value pair from a dictionary or array datum iteration. More...
 
void(* iterate_end )(const sw_datum *composite, sw_data_iterator **iterator)
 Discard resources associated with a data structure iterator state. More...
 
HqBool(* equal )(const sw_datum *one, const sw_datum *two)
 Compare two datums for equality. More...
 
sw_data_result(* open_blob )(const sw_datum *datum, int32 mode, sw_blob_instance **blob)
 Open a SW_DATUM_TYPE_BLOB datum for access via the sw_blob_api interface. More...
 
sw_data_result(* pop )(sw_datum *stack)
 Pop the top element from the stack. A stack is an array datum of subtype SW_DATUM_SUBTYPE_STACK_ARRAY. More...
 
sw_data_result(* push )(sw_datum *stack, const sw_datum *value)
 Push an entry onto a stack. A stack is an array datum of subtype SW_DATUM_SUBTYPE_STACK_ARRAY. More...
 
sw_data_result(* retain )(const sw_datum *datum, sw_datum **retained)
 Retain a datum until released. More...
 
sw_data_result(* release )(sw_datum **retained)
 Release a composite datum that was previously retained. More...
 

Detailed Description

A structure containing callback functions for structured data access.

Data references provided from the RIP are automatically invalidated at the end of the callback that passed them to a module. All data that is to be stored between calls to the module must be copied from the RIP.

Note that in the case of complex types such as strings, arrays and dictionaries, it is not enough to copy the sw_datum - its contents must be copied. This includes the bytes of a strings, and all the elements of an array or dictionary. It is not usually necessary to copy datums in this way.

Creators of sw_datum complex types can implement this API, pointing the datum's owner field at their sw_data_api structure, to enable on-demand creation or delivery of array, stack and dictionary contents. In such a case, the implementor uses the datum's value.opaque field for its own purposes. A sw_data_api created for this purpose need only implement those methods that are relevant - NULL methods return SW_DATA_ERROR_INVALIDACCESS if used.

Field Documentation

◆ equal

HqBool( * sw_data_api::equal) ( const sw_datum *one, const sw_datum *two)

Compare two datums for equality.

Parameters
[in]oneThe first sw_datum.
[in]twoThe second sw_datum.
Return values
FALSEthe values were of incomparable types, or were not equal.
TRUEthe values were of comparable types of the same value.

This is a strict equality test for composites, but is otherwise an equivalence test, so the numeric value of a float can be equal to the value of an integer, for example. For composites such as arrays this does not compare the contents, but tests whether they are the same array.

◆ get_indexed

sw_data_result( * sw_data_api::get_indexed) ( const sw_datum *array, size_t index, sw_datum *value)

Get an indexed value from an array or stack datum.

Parameters
[in]arrayAn array or stack datum from which an indexed value will be extracted.
[in]indexThe index of the value to extract. Zero means the first element of the array, or the topmost element of the stack.
[out]valueThe location to be filled in with the returned value.
Return values
SW_DATA_OKSuccess. The value entry is filled with the indexed array or stack entry.
SW_DATA_ERROR_RANGECHECKReturned if the index is out of range.
SW_DATA_ERROR_TYPECHECKReturned if the indexed value is an unsupported type or the first parameter isn't an array.
SW_DATA_ERROR_INVALIDACCESSReturned if the array was not readable.

◆ get_keyed

sw_data_result( * sw_data_api::get_keyed) ( const sw_datum *dict, const sw_datum *key, sw_datum *value)

Get a keyed value from a dictionary datum.

Parameters
[in]dictA dictionary datum from which a keyed value will be extracted.
[in]keyA key for the value to extract. The type of the key may be restricted to transparent type (strings, integer, boolean, real, null), depending on the owner of the dictionary.
[out]valueThe location to be filled in with the returned value.
Return values
SW_DATA_OKSuccess. The value entry is filled with the keyed array entry.
SW_DATA_ERROR_UNDEFINEDReturned if the key does not exist in the dictionary.
SW_DATA_ERROR_TYPECHECKReturned if the keyed value is an unsupported type or the first parameter is not a dictionary.
SW_DATA_ERROR_INVALIDACCESSReturned if the dictionary was not readable.

◆ info

sw_api_info sw_data_api::info

Version number, name, display name, size. This is REQUIRED to be the first field.

◆ iterate_begin

sw_data_result( * sw_data_api::iterate_begin) ( const sw_datum *composite, sw_data_iterator **iterator)

Start a new iteration over a dictionary or array datum.

Parameters
[in]compositeThe datum to iterate over.
[out]iteratorA pointer to an opaque iteration state.
Return values
SW_DATA_OKReturned if the iterator was started. sw_data_api::iterate_end() must be called when complete to dispose of the iterator state.
SW_DATA_ERROR_TYPECHECKReturned if the composite datum is not of a suitable type to iterate.
SW_DATA_ERROR_MEMORYReturned if the iteration state could not be created because of a memory allocation failure.
SW_DATA_ERROR_INVALIDACCESSReturned if the composite datum was not readable.

◆ iterate_end

void( * sw_data_api::iterate_end) ( const sw_datum *composite, sw_data_iterator **iterator)

Discard resources associated with a data structure iterator state.

If sw_data_api::iterate_begin() succeeded, this function must be called to dispose of the iterator state.

Parameters
[in]compositeThe data structure being iterated.
[in,out]iteratorThe location where the iterator state is stored. The iterator state pointer will be invalidated on exit.

◆ iterate_next

sw_data_result( * sw_data_api::iterate_next) ( const sw_datum *composite, sw_data_iterator *iterator, sw_datum *key, sw_datum *value)

Get a key-value pair from a dictionary or array datum iteration.

Parameters
[in]compositeThe datum being iterated.
[in]iteratorAn iterator state previously created by iterate_begin().
[out]keyA unique key identifying the datum in the composite structure. When iterating over arrays, this will be set to an integer datum with the index of the associated value.
[out]valueThe value associated with key in the composite structure.
Return values
SW_DATA_OKSuccess. The key and value parameters are filled in.
SW_DATA_FINISHEDReturned when there are no more keys to iterate over.
SW_DATA_ERROR_MEMORYReturned if the iteration state could not be updated because of a memory allocation failure.

◆ match

sw_data_result( * sw_data_api::match) ( const sw_datum *composite, sw_data_match *match, size_t match_length)

Match multiple data entries in a dictionary or array datum.

Parameters
[in]compositeAn array or dictionary datum from which values will be extracted.
[in,out]matchAn array of match structures, determining the key to match, what types are acceptable for the match, how to treat type mismatches or missing values, and where to store the value.
[in]match_lengthThe number of entries to match.
Return values
SW_DATA_OKSuccess. The match result data are updated with the value of the extracted entries, or set to SW_DATUM_TYPE_NOTHING if the key was not matched but was optional.
SW_DATA_ERROR_UNDEFINEDReturned if a required entry was not present. The match data should not be examined if this error occurs.
SW_DATA_ERROR_TYPECHECKReturned if a matched value has the wrong type, and the SW_DATUM_TYPE_INVALID bit was not set in the allowed type mask of the match. The match data should not be examined if this error occurs. This error is also returned if the first parameter is not an array or dictionary.
SW_DATA_ERROR_INVALIDACCESSReturned if the data structure to match was not readable. The match data should not be examined if this error occurs.

◆ open_blob

sw_data_result( * sw_data_api::open_blob) ( const sw_datum *datum, int32 mode, sw_blob_instance **blob)

Open a SW_DATUM_TYPE_BLOB datum for access via the sw_blob_api interface.

Parameters
[in]datumA datum of type SW_DATUM_TYPE_BLOB.
[in]modeAn access mode of SW_RDONLY, SW_WRONLY, or SW_RDWR, possibly combined with the flags SW_FONT and SW_EXCL, as defined in swdevice.h. If none of the access mode flags are set, the RIP will derive the access mode from the datum itself.
[in]blobA pointer to a handle for a sw_blob_instance.
Returns
SW_DATA_OK if a blob was opened. In this case a valid blob handle will be stored in blob. The caller must release the blob reference when it has finished accessing it using the sw_blob_api::close() method. If the blob could not be opened, then one of the sw_data_result error codes will be returned.

◆ pop

sw_data_result( * sw_data_api::pop) ( sw_datum *stack)

Pop the top element from the stack. A stack is an array datum of subtype SW_DATUM_SUBTYPE_STACK_ARRAY.

Parameters
[in]stackA stack datum from which the datum will be removed.
Return values
SW_DATA_OKSuccess. The top entry was popped from the stack.
SW_DATA_ERROR_RANGECHECKReturned if the stack is empty.
SW_DATA_ERROR_TYPECHECKReturned if stack is not an array datum of subtype SW_DATUM_SUBTYPE_STACK_ARRAY.
SW_DATA_ERROR_INVALIDACCESSReturned if the stack was not readable or mutable.

Note that like set_indexed, pop implicitly invalidates any opaque datum representing the value that has been popped from the stack. e.g.:

sw_datum top, temp ;
(void)get_indexed(stack, 0, &top) ; // get topmost element
(void)pop(stack) ; // implicitly invalidates 'top'
if (top.type == SW_DATUM_TYPE_ARRAY) { // ERROR! Invalid opaque type
(void)get_indexed(stack, 0, &temp) ; // CRASH!
@ SW_DATUM_TYPE_ARRAY
Definition: swdataapi.h:204
sw_data_result(* pop)(sw_datum *stack)
Pop the top element from the stack. A stack is an array datum of subtype SW_DATUM_SUBTYPE_STACK_ARRAY...
Definition: swdataapi.h:785
sw_data_result(* get_indexed)(const sw_datum *array, size_t index, sw_datum *value)
Get an indexed value from an array or stack datum.
Definition: swdataapi.h:511
Structured data instance type.
Definition: swdataapi.h:283
unsigned char type
Definition: swdataapi.h:287

Do not change or pop an opaque datum until you have finished with it. See set_indexed for more details.

◆ push

sw_data_result( * sw_data_api::push) ( sw_datum *stack, const sw_datum *value)

Push an entry onto a stack. A stack is an array datum of subtype SW_DATUM_SUBTYPE_STACK_ARRAY.

Parameters
[in]stackA stack datum onto which the datum will be added.
[in]valueThe datum to be pushed onto the top of the stack.
Return values
SW_DATA_OKSuccess. The value entry has been pushed onto the top of the stack.
SW_DATA_ERROR_RANGECHECKReturned if the stack is full.
SW_DATA_ERROR_TYPECHECKReturned if stack is not an array datum of subtype SW_DATUM_SUBTYPE_STACK_ARRAY or the value is not of a suitable type.
SW_DATA_ERROR_MEMORYReturned if a memory allocation failed while trying to push the value.
SW_DATA_ERROR_INVALIDACCESSReturned if the stack was not writeable.

◆ release

sw_data_result( * sw_data_api::release) ( sw_datum **retained)

Release a composite datum that was previously retained.

Parameters
[in,out]retainedThe location of a retained datum pointer that was previously retained using sw_data_api::retain(). If the datum pointer was valid, this is set to NULL on exit.
Return values
SW_DATA_OKif the datum was released. Datum objects that were retained successfully will always be able to be released.
SW_DATA_ERROR_SYNTAXif the location of the datum or the datum is invalid.
SW_DATA_ERROR_INVALIDACCESSif the datum could not be released for any other reason.

◆ retain

sw_data_result( * sw_data_api::retain) ( const sw_datum *datum, sw_datum **retained)

Retain a datum until released.

Parameters
[in]datumA pointer to the datum to retain.
[out]retainedA pointer to a location in which a new datum pointer will be stored. Access to the retained datum should always be through this pointer.

Not all datum objects may be retained (generally simple datum objects, and composite objects that do not contain unsupported datum types). Datum that are successfully retained must be released before the RIP shuts down.

In some cases, the retained datum pointer may be the same as the original datum pointer, but this is not guaranteed. The sw_data_api::release() call must always be called using the new retained datum pointer. The datum object will become invalid and should not be dereferenced after the matching release call.

Data returned by the sw_data_api::get_indexed(), sw_data_api::get_keyed(), and iteration methods are temporary copies of the retained data. If the retained data are released, the temporary copies may cease to be valid. Retaining the temporary copy may create a new retained copy of the data, distinct from the original, or may share the original retained data. The exact behaviour of retaining the temporary copies is not guaranteed.

Return values
SW_DATA_OKif the datum could be retained. The datum pointer will remain valid until after a matching sw_data_api::release() call.
SW_DATA_ERROR_SYNTAXif the datum is invalid.
SW_DATA_ERROR_MEMORYif the datum could not be retained because of memory exhaustion.
SW_DATA_ERROR_RANGECHECKif the datum is retained too many times.
SW_DATA_ERROR_INVALIDACCESSif the datum could not be retained for any other reason.

◆ set_indexed

sw_data_result( * sw_data_api::set_indexed) ( sw_datum *array, size_t index, const sw_datum *value)

Store an indexed value in an array or stack datum.

Parameters
[in]arrayAn array or stack datum into which an indexed value will be stored.
[in]indexThe index at which to store the value. Zero means the first element of the array, or the topmost element of the stack.
[in]valueThe datum to store into the array. Values in local module memory will be deep-copied when storing into RIP owned arrays or stacks.
Return values
SW_DATA_OKReturned if successful.
SW_DATA_ERROR_TYPECHECKReturned if the first parameter isn't an array.
SW_DATA_ERROR_RANGECHECKReturned if the index is out of range.
SW_DATA_ERROR_INVALIDACCESSReturned if the value cannot be stored into the array or stack.
SW_DATA_ERROR_MEMORYReturned if a memory allocation failed while trying to store the value.

Note that using set_indexed to change an element of an array or stack will invalidate any opaque datum already fetched from that index - datums represent data, they are not necessarily an independent copy of that data. e.g.:

sw_datum got, temp, change = SW_DATUM_INTEGER(0) ;
(void)get_indexed(arr, 0, &got) ; // ignore errors for this example
(void)set_indexed(arr, 0, &change) ; // implicitly invalidates 'got'
if (got.type == SW_DATUM_TYPE_ARRAY) { // ERROR! got is no longer valid
(void)get_indexed(&got, 0 &temp) ; // CRASH!
#define SW_DATUM_INTEGER(_int)
Auto/static initializer for sw_datum integer values.
Definition: swdataapi.h:341
sw_data_result(* set_indexed)(sw_datum *array, size_t index, const sw_datum *value)
Store an indexed value in an array or stack datum.
Definition: swdataapi.h:557

In the above example, array index 0 is changed after having been fetched, so the fetched opaque datum no longer represents the actual data. Any attempt to use that outdated representation can fail in unpredictable and serious ways.

◆ set_keyed

sw_data_result( * sw_data_api::set_keyed) ( sw_datum *dict, const sw_datum *key, const sw_datum *value)

Store a keyed value in a dictionary datum.

Parameters
[in]dictA dictionary datum into which a keyed value will be stored.
[in]keyA key for the value to store. The type of the key may be restricted to transparent type (strings, integer, boolean, real, null), depending on the owner of the dictionary.
[in]valueThe datum to store into the dictionary. Values in local module memory will be deep-copied when stored in RIP owned dictionaries.
Return values
SW_DATA_OKReturned if successful.
SW_DATA_ERROR_TYPECHECKReturned if the first parameter is not a dictionary or the value is not of an appropriate type.
SW_DATA_ERROR_INVALIDACCESSReturned if the value cannot be stored into the dictionary.
SW_DATA_ERROR_MEMORYReturned if a memory allocation failed while trying to store the value.

Note that like set_indexed, changing a dictionary value with set_keyed will invalidate any opaque datum fetched for that key. See set_indexed for details.


The documentation for this struct was generated from the following file: