#include <stdint.h>
#include <stdbool.h>
#include "returncodes.h"
Typedefs | |
typedef enum swi_dset_Type | swi_dset_Type_t |
Enum to define data types supported in Data Set object. | |
typedef struct swi_dset_Iterator | swi_dset_Iterator_t |
struct to deal with incoming data. | |
Enumerations | |
enum | swi_dset_Type { SWI_DSET_UNSUPPORTED, SWI_DSET_NIL, SWI_DSET_INTEGER, SWI_DSET_FLOAT, SWI_DSET_STRING, SWI_DSET_BOOL } |
Enum to define data types supported in Data Set object. More... | |
Functions | |
rc_ReturnCode_t | swi_dset_Destroy (swi_dset_Iterator_t *data) |
Destroys explicitly a data iterator. | |
rc_ReturnCode_t | swi_dset_Next (swi_dset_Iterator_t *data) |
General purpose function to iterate over received data. | |
const char * | swi_dset_GetName (swi_dset_Iterator_t *data) |
Retrieves the name of current element in the iterator. | |
swi_dset_Type_t | swi_dset_GetType (swi_dset_Iterator_t *data) |
Retrieves the type of current element in the iterator. | |
int64_t | swi_dset_ToInteger (swi_dset_Iterator_t *data) |
Returns integer value of data iterator current element. | |
double | swi_dset_ToFloat (swi_dset_Iterator_t *data) |
Returns float value of data iterator current element. | |
bool | swi_dset_ToBool (swi_dset_Iterator_t *data) |
Returns boolean value of data iterator current element. | |
const char * | swi_dset_ToString (swi_dset_Iterator_t *data) |
Returns string value of data iterator current element. | |
rc_ReturnCode_t | swi_dset_GetIntegerByName (swi_dset_Iterator_t *data, const char *namePtr, int64_t *valuePtr) |
Retrieves an integer value of an element in the data iterator (not necessarily the current element), using element name to find/select it. | |
rc_ReturnCode_t | swi_dset_GetFloatByName (swi_dset_Iterator_t *data, const char *namePtr, double *valuePtr) |
Retrieves a float value of an element in the data iterator (not necessarily the current element), using element name to find/select it. | |
rc_ReturnCode_t | swi_dset_GetStringByName (swi_dset_Iterator_t *data, const char *namePtr, const char **valuePtr) |
Retrieves a string value of an element in the data iterator (not necessarily the current element), using element name to find/select it. | |
rc_ReturnCode_t | swi_dset_GetTypeByName (swi_dset_Iterator_t *data, const char *namePtr, swi_dset_Type_t *typePtr) |
Retrieves the type of an element given its name. |
typedef struct swi_dset_Iterator swi_dset_Iterator_t |
struct to deal with incoming data.
swi_dset_Iterator_t has one current element and each element has
2 different kind of APIs are provided:
Please note that:
Memory allocation will be done internally by the functions returning the data iterator. Data availability (i.e. memory deallocation) will be specified in the documentation of each function providing this kind of swi_dset_Iterator_t.
enum swi_dset_Type |
Enum to define data types supported in Data Set object.
rc_ReturnCode_t swi_dset_Destroy | ( | swi_dset_Iterator_t * | data | ) |
Destroys explicitly a data iterator.
Refer to each API documentation, but most of the time the API returning this object will allocate it and release it, so API documentation will explicitly mention that you have to call this API to collect the resources attached to the data iterator.
RC_BAD_FORMAT if data parameter is invalid
data | [IN] the data iterator to destroy. |
rc_ReturnCode_t swi_dset_GetFloatByName | ( | swi_dset_Iterator_t * | data, | |
const char * | namePtr, | |||
double * | valuePtr | |||
) |
Retrieves a float value of an element in the data iterator (not necessarily the current element), using element name to find/select it.
RC_BAD_PARAMETER when the element was found according requested name, but the element had different type so value can not be returned.
RC_NOT_FOUND when requested name was not found in the data iterator.
data | [IN] iterator object to search in |
namePtr | [IN] name of the element to find |
valuePtr | [OUT] float pointer to store element value. |
rc_ReturnCode_t swi_dset_GetIntegerByName | ( | swi_dset_Iterator_t * | data, | |
const char * | namePtr, | |||
int64_t * | valuePtr | |||
) |
Retrieves an integer value of an element in the data iterator (not necessarily the current element), using element name to find/select it.
RC_BAD_PARAMETER when the element was found according requested name, but the element had different type so value can not be returned.
RC_NOT_FOUND when requested name was not found in the data iterator.
data | [IN] iterator object to search in |
namePtr | [IN] name of the element to find |
valuePtr | [OUT] integer pointer to store element value. |
const char* swi_dset_GetName | ( | swi_dset_Iterator_t * | data | ) |
Retrieves the name of current element in the iterator.
data | [IN] iterator object, that will provide the element which info will be retrieved. |
rc_ReturnCode_t swi_dset_GetStringByName | ( | swi_dset_Iterator_t * | data, | |
const char * | namePtr, | |||
const char ** | valuePtr | |||
) |
Retrieves a string value of an element in the data iterator (not necessarily the current element), using element name to find/select it.
RC_BAD_PARAMETER when the element was found according requested name, but the element had different type so value can not be returned.
RC_NOT_FOUND when requested name was not found in the data iterator.
data | [IN] iterator object to search in |
namePtr | [IN] name of the element to find |
valuePtr | [OUT] string pointer to store element value. |
swi_dset_Type_t swi_dset_GetType | ( | swi_dset_Iterator_t * | data | ) |
Retrieves the type of current element in the iterator.
It is strongly advised to call this function to get current element type prior calling one of the swi_dataE_To* function, so that the user can choose the appropriate function to get element value.
SWI_DSET_UNSUPPORTED in case of error
data | [IN] iterator object, that will provide the element which info will be retrieved. |
rc_ReturnCode_t swi_dset_GetTypeByName | ( | swi_dset_Iterator_t * | data, | |
const char * | namePtr, | |||
swi_dset_Type_t * | typePtr | |||
) |
Retrieves the type of an element given its name.
Element value is then ready to be retrieved using the appropriate swi_dataE_To* function.
This API is useful when user knows the name of the element that the application will receive, but not the type of this element.
RC_NOT_FOUND when requested name was not found in the data iterator.
data | [IN] iterator object to search in |
namePtr | [IN] the name of the element to select |
typePtr | [OUT] the type of the selected element |
rc_ReturnCode_t swi_dset_Next | ( | swi_dset_Iterator_t * | data | ) |
General purpose function to iterate over received data.
Specific functions to retrieve value for most common types are defined below. Please note that the order of the elements is not guaranteed, caller is strongly advised to rely on elements' name rather than on the order.
RC_BAD_FORMAT if data parameter is invalid
RC_NOT_FOUND when no more data are available, i.e previous call returned last received value.
data | [IN] iterator object to iterate over. The iterator will be given as parameter on data reception function(s). |
bool swi_dset_ToBool | ( | swi_dset_Iterator_t * | data | ) |
Returns boolean value of data iterator current element.
Returned value is undefined if the current element type is not SWI_DSET_BOOL, so it is strongly advised to call swi_dset_GetType before using this function.
data | [IN] iterator object, that will provide the element which float value will be returned. |
double swi_dset_ToFloat | ( | swi_dset_Iterator_t * | data | ) |
Returns float value of data iterator current element.
Returned value is undefined if the current element type is not SWI_DSET_FLOAT, so it is strongly advised to call swi_dset_GetType before using this function.
data | [IN] iterator object, that will provide the element which float value will be returned. |
int64_t swi_dset_ToInteger | ( | swi_dset_Iterator_t * | data | ) |
Returns integer value of data iterator current element.
Returned value is undefined if the current element type is not SWI_DSET_INTEGER, so it is strongly advised to call swi_dset_GetType before using this function.
data | [IN] iterator object, that will provide the element which integer value will be returned. |
const char* swi_dset_ToString | ( | swi_dset_Iterator_t * | data | ) |
Returns string value of data iterator current element.
Returned value is undefined if the current element type is not SWI_DSET_STRING, so it is strongly advised to call swi_dset_GetType before using this function.
data | [IN] iterator object, that will provide the element which string value will be returned. |