The structured data interface is a callback-based interface used to access parameters passed to a module. More...
Files | |
file | swdataapi.h |
Header file defining the Structured data callback API. | |
file | swdevdata.h |
Header file defining the Structured data callback API. | |
Data Structures | |
struct | sw_datum |
Structured data instance type. More... | |
struct | sw_data_api |
A structure containing callback functions for structured data access. More... | |
struct | sw_data_match |
A structure used for extracting multiple values from an array or dictionary in one go. More... | |
Macros | |
#define | SW_DATUM_INVALID {SW_DATUM_TYPE_INVALID} |
Auto/static initializer for sw_datum invalid values. More... | |
#define | SW_DATUM_NOTHING {SW_DATUM_TYPE_NOTHING} |
Auto/static initializer for sw_datum nothing values. More... | |
#define | SW_DATUM_NULL {SW_DATUM_TYPE_NULL} |
Auto/static initializer for sw_datum null values. More... | |
#define | SW_DATUM_INTEGER(_int) {SW_DATUM_TYPE_INTEGER, 0,0,0, NULL, 0, { (void *)((intptr_t)(_int)) }} |
Auto/static initializer for sw_datum integer values. More... | |
#define | SW_DATUM_BOOLEAN(_bool) {SW_DATUM_TYPE_BOOLEAN, 0,0,0, NULL, 0, { (void *)((intptr_t)(_bool)) }} |
Auto/static initializer for sw_datum boolean values. More... | |
#define | SW_DATUM_STRING(_str) {SW_DATUM_TYPE_STRING, 0,0,0, NULL, sizeof("" _str "") - 1, {(const void *)("" _str "")}} |
Auto/static initializer for sw_datum string values. More... | |
#define | SW_DATUM_NAME(_str) {SW_DATUM_TYPE_STRING, SW_DATUM_SUBTYPE_NAME_STRING,0,0, NULL, sizeof("" _str "") - 1, {(const void *)("" _str "")}} |
Auto/static initializer for sw_datum name values. More... | |
#define | SW_DATUM_ARRAY(_array, _len) {SW_DATUM_TYPE_ARRAY, 0,0,0, NULL, (_len), { (void *)(_array) }} |
Auto/static initializer for sw_datum array values. More... | |
#define | SW_DATUM_STACK(_stack, _len) {SW_DATUM_TYPE_ARRAY, SW_DATUM_SUBTYPE_STACK_ARRAY,0,0, NULL, (_len), { (void *)(_stack) }} |
Auto/static initializer for sw_datum stack values. More... | |
#define | SW_DATUM_DICT(_dict, _len) {SW_DATUM_TYPE_DICT, 0,0,0, NULL, (_len), { (void *)(_dict) }} |
Auto/static initializer for sw_datum dictionary values. More... | |
#define | SW_DATA_ARRAY_LENGTH(_array) (sizeof(_array) / sizeof((_array)[0])) |
Count the members of a local data array. Useful for statically initialising arrays. | |
#define | SW_DATA_DICT_LENGTH(_dict) (SW_DATA_ARRAY_LENGTH(_dict) >> 1) |
Count the members of a local data dictionary. Useful for statically initialising dictionaries. | |
#define | SW_DATUM_0_0F 0 |
A constant of real value 0.0 for use with the SW_DATUM_FLOAT() static initializer. | |
#define | SW_DATUM_1_0F 1065353216 |
A constant of real value 1.0 for use with the SW_DATUM_FLOAT() static initializer. | |
#define | SW_DATUM_0_5F 1056964608 |
A constant of real value 0.5 for use with the SW_DATUM_FLOAT() static initializer. | |
#define | SW_DATUM_FLOAT(_real) {SW_DATUM_TYPE_FLOAT, 0,0,0, NULL, 0, { (void *)((intptr_t)(_real)) }} |
Auto/static initializer for sw_datum float values, for use with the defined constants that can be used with this initializer. More... | |
#define | SW_DATUM_REQUIREDKEY(type, name) {SW_DATUM_BIT_##type,SW_DATUM_STRING(""name""),SW_DATUM_NOTHING} |
A key initializer macro to help build the sw_data_match structure. More... | |
#define | SW_DATUM_OPTIONALKEY(type, name) {SW_DATUM_BIT_##type|SW_DATUM_BIT_NOTHING,SW_DATUM_STRING(""name""),SW_DATUM_NOTHING} |
A key initializer macro to help build the sw_data_match structure. More... | |
Typedefs | |
typedef HqnResult | sw_data_result |
Type of return values from sw_data_api functions. More... | |
typedef struct sw_data_api | sw_data_api |
Type definition for the structured data interface implementation. | |
typedef struct sw_datum | sw_datum |
Structured data instance type. More... | |
typedef struct sw_data_match | sw_data_match |
A structure used for matching multiple datum entries in one go. | |
typedef struct sw_data_iterator | sw_data_iterator |
An opaque type used by the data provider to iterate data structures. | |
Functions | |
HqnResult | swdata_result_translate (sw_data_result result) |
Translate a data API-specific error code to a generic HqnResult error code. More... | |
void | sw_datum_get_integer (const sw_datum *datum, int value, sw_data_result result) |
A utility macro to extract an integer value from a sw_datum object of integer or float type. More... | |
void | sw_datum_get_real (const sw_datum *datum, float_or_double_specifier type, float_or_double value, sw_data_result result) |
A utility macro to extract a real value from a sw_datum object of integer or float type. More... | |
The structured data interface is a callback-based interface used to access parameters passed to a module.
Some APIs and callback functions are provided with a sw_datum or sw_datum pointer represent structured data, usually for parameters that the function or API may read. A sw_datum can represent a boolean, integer, float, string, name, array, stack, dictionary, BLOB (i.e., a file), a null object or nothing at all. It can represent a PostScript object and act as a proxy for it to allow manipulation of PostScript state; it can represent and act as a proxy for a DEVICEPARAM or a JSON object or another structured data object; or it can be an independent module-created 'raw' value. A uniform set of functions allow navigation, matching, comparison, manipulation and retention of structured data objects, regardless of the object source that they proxy or represent.
Structured object sw_datum values are examined, matched and manipulated through the sw_data_api interface. When a sw_datum is presented to a callback or API, it should be accompanied by a sw_data_api pointer, which is the API that should be used to access this structured data object. Do not mix and match sw_datum objects from one source with sw_data_api pointers from another source: they may not work, and may crash the application. Always use the sw_data_api pointer supplied with a sw_datum object to manipulate and examine it. You may use 'raw' sw_datum objects with any sw_data_api pointer, however.
A sw_datum object contains a type, a sub-type, flags, an owner (the data proxy that created it), a length (used for strings, arrays, and dictionaries), and a variant member with the value of the data object. The type, sub-type, flags, length, and variant member may be read directly by the client. For composite objects (arrays, dictionaries, BLOBs and their sub-types), the variant member is opaque, and must be accessed through data API functions.
The data API provides functions to:
A number of auto and static initializer macros exist to construct raw datum objects from scratch. These are useful as values to set in datum parameters, and as values for matches.
A utility function, swdata_result_translate(), is provided to translate data API-specific result values to generic HqnResult result codes that can be passed to the RIP or as return values for other APIs.
A data API pointer must be discovered using RDR using class RDR_CLASS_API and type RDR_API_DATA before the API methods are used. The data API is automatically registered when the Harlequin RIP is started. It is deregistered when the Harlequin RIP is shutdown.
#define SW_DATUM_ARRAY | ( | _array, | |
_len | |||
) | {SW_DATUM_TYPE_ARRAY, 0,0,0, NULL, (_len), { (void *)(_array) }} |
Auto/static initializer for sw_datum array values.
For example:
It is also possible to initialise the array and contents simultaneously, if you are careful about the array length:
Dynamically allocated datums are most easily initialised using a static datum as a template, e.g.:
#define SW_DATUM_BOOLEAN | ( | _bool | ) | {SW_DATUM_TYPE_BOOLEAN, 0,0,0, NULL, 0, { (void *)((intptr_t)(_bool)) }} |
Auto/static initializer for sw_datum boolean values.
For example:
#define SW_DATUM_DICT | ( | _dict, | |
_len | |||
) | {SW_DATUM_TYPE_DICT, 0,0,0, NULL, (_len), { (void *)(_dict) }} |
Auto/static initializer for sw_datum dictionary values.
For example:
#define SW_DATUM_FLOAT | ( | _real | ) | {SW_DATUM_TYPE_FLOAT, 0,0,0, NULL, 0, { (void *)((intptr_t)(_real)) }} |
Auto/static initializer for sw_datum float values, for use with the defined constants that can be used with this initializer.
For example:
#define SW_DATUM_INTEGER | ( | _int | ) | {SW_DATUM_TYPE_INTEGER, 0,0,0, NULL, 0, { (void *)((intptr_t)(_int)) }} |
Auto/static initializer for sw_datum integer values.
For example:
#define SW_DATUM_INVALID {SW_DATUM_TYPE_INVALID} |
Auto/static initializer for sw_datum invalid values.
For example:
This type is more likely to be returned by a match call than created by module code.
#define SW_DATUM_NAME | ( | _str | ) | {SW_DATUM_TYPE_STRING, SW_DATUM_SUBTYPE_NAME_STRING,0,0, NULL, sizeof("" _str "") - 1, {(const void *)("" _str "")}} |
Auto/static initializer for sw_datum name values.
Names are a subtype of strings, and use the same value and length fields.
For example:
#define SW_DATUM_NOTHING {SW_DATUM_TYPE_NOTHING} |
Auto/static initializer for sw_datum nothing values.
For example:
This type is more likely to be returned by a match call than created by module code.
#define SW_DATUM_NULL {SW_DATUM_TYPE_NULL} |
Auto/static initializer for sw_datum null values.
For example:
#define SW_DATUM_OPTIONALKEY | ( | type, | |
name | |||
) | {SW_DATUM_BIT_##type|SW_DATUM_BIT_NOTHING,SW_DATUM_STRING(""name""),SW_DATUM_NOTHING} |
A key initializer macro to help build the sw_data_match structure.
For example:
Note the shortening of the type field for simplicity in the usual case - the macro prepends SW_DATUM_BIT_
to this. Consequently, if more than one type is acceptable then others must be ORed in full, e.g.:
#define SW_DATUM_REQUIREDKEY | ( | type, | |
name | |||
) | {SW_DATUM_BIT_##type,SW_DATUM_STRING(""name""),SW_DATUM_NOTHING} |
A key initializer macro to help build the sw_data_match structure.
For example:
Note the shortening of the type field for simplicity in the usual case - the macro prepends SW_DATUM_BIT_
to this. Consequently, if more than one type is acceptable then others must be ORed in full, e.g.:
#define SW_DATUM_STACK | ( | _stack, | |
_len | |||
) | {SW_DATUM_TYPE_ARRAY, SW_DATUM_SUBTYPE_STACK_ARRAY,0,0, NULL, (_len), { (void *)(_stack) }} |
Auto/static initializer for sw_datum stack values.
This is unlikely to be useful.
#define SW_DATUM_STRING | ( | _str | ) | {SW_DATUM_TYPE_STRING, 0,0,0, NULL, sizeof("" _str "") - 1, {(const void *)("" _str "")}} |
typedef HqnResult sw_data_result |
Type of return values from sw_data_api functions.
This is a subclass of HqnResult that also supports some specific extra error codes generated by sw_data_api functions (declared as the SW_DATA_RESULT enumeration). Before assigning to values of HqnResult type or any of its other subclasses, sw_data_result values must be converted to change the data API specific values to HQN_RESULT_SUCCESS or a monitor UID error code greater than MON_CLASS_ERROR. This can be done by calling the function swdata_result_translate().
Structured data instance type.
Modules may create raw sw_datum values, including arrays and dictionaries (associative arrays), but must ensure that all fields are initialised properly. Static initializers are provided which can be used to initialise local datums, which can then be used directly or copied to initialise dynamically allocated datums.
For a raw sw_datum array of n elements, value.opaque points to a contiguous array of n sw_datum items. For a dictionary of n key/value pairs it points to a contiguous array of n * 2 sw_datum items. (Raw stacks are not useful because their size cannot be safely changed, so push and pop are not supported.) The owner field must be set to NULL for raw datums created by a module, and should never be modified for data provided to the module. Note however it is possible for a module to implement the sw_data_api itself and hence build 'owned' datums.
Modules may treat all arrays and dictionaries as opaque and use the api access methods even for values it has created itself. However, arrays and dictionaries with a non-NULL owner are always opaque and their contents can only be accessed using the API.
anonymous enum |
Version numbers defined for the structured data API.
enum SW_DATA_RESULT |
Return values from sw_data_api functions.
All error values are guaranteed to be greater than or equal to SW_DATA_ERROR. Errors may be implementation dependent so all return values greater than or equal to SW_DATA_ERROR must be treated as errors, even if not explicitly listed as a method return value.
enum SW_DATUM_BITS |
Data type bits.
These are used to select allowable types in the sw_data_match structure's type_mask field.
enum SW_DATUM_SUBTYPES |
Data subtypes for structured data.
These values allow data types to be subtyped. Strings and arrays are subtyped, to indicate names and stacks respectively.
enum SW_DATUM_TYPES |
Data types for structured data.
These definitions closely follow Postscript use, but also support other data hierarchy forms.
Data types are divided into three categories.
The data types SW_DATUM_TYPE_NOTHING and SW_DATUM_TYPE_INVALID are pseudo-types which are used by the RIP to indicate certain conditions have occurred, such as missing or invalid data in data matches. They will not be retrieved through the sw_data_api getter functions and cannot be stored through the sw_data_api setter functions.
Transparent data types are SW_DATUM_TYPE_NULL, SW_DATUM_TYPE_BOOLEAN, SW_DATUM_TYPE_INTEGER, SW_DATUM_TYPE_FLOAT, and SW_DATUM_TYPE_STRING. Values of these types can be examined directly, by looking at the appropriate field of the sw_datum::value union. The null type has no union branch, it is a type with a singleton value. Strings are not zero-terminated, so the sw_datum::length field must be used to delimit their size.
Opaque data types are SW_DATUM_TYPE_ARRAY, SW_DATUM_TYPE_DICT, and SW_DATUM_TYPE_BLOB. Datum of these types must only be accessed through the sw_data_api method functions. In the case of arrays and dictionaries (associative arrays), the length can be examined to determine the array length or the maximum storage space in the dictionary respectively.
void sw_datum_get_integer | ( | const sw_datum * | datum, |
int | value, | ||
sw_data_result | result | ||
) |
A utility macro to extract an integer value from a sw_datum object of integer or float type.
This prototype exists for Splint and Doxygen. There is no actual function of this name.
[in] | datum | The object from which to extract an integer. |
[out] | value | The returned integer value. |
[out] | result | The return value of the macro. |
SW_DATA_OK | Success. The value entry is filled with the integer value of the datum. |
SW_DATA_ERROR_RANGECHECK | Returned if the datum value is not exactly representable as an integer. |
SW_DATA_ERROR_TYPECHECK | Returned if the datum value is not an integer or a real. |
SW_DATA_ERROR_INVALIDACCESS | Returned if the datum is invalid. |
void sw_datum_get_real | ( | const sw_datum * | datum, |
float_or_double_specifier | type, | ||
float_or_double | value, | ||
sw_data_result | result | ||
) |
A utility macro to extract a real value from a sw_datum object of integer or float type.
This prototype exists for Splint and Doxygen. There is no actual function of this name.
[in] | datum | The object from which to extract a value. |
[in] | type | The required type of value - this MUST be float or double. |
[out] | value | The real value extracted from the sw_datum. This must be a float or double. |
[out] | result | The return value of the extraction. |
SW_DATA_OK | Success. The value entry is filled with the real value of the datum. |
SW_DATA_ERROR_TYPECHECK | Returned if the datum value is not an integer or a real. |
SW_DATA_ERROR_INVALIDACCESS | Returned if the datum is invalid. |
HqnResult swdata_result_translate | ( | sw_data_result | result | ) |
Translate a data API-specific error code to a generic HqnResult error code.
[in] | result | One of the SW_DATA_RESULT values, or an error value greater than MON_CLASS_ERROR. |