Elektra 0.11.0
conversion.c File Reference

Elektra High Level API. More...

#include "kdbease.h"
#include "kdbhelper.h"
#include <ctype.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "macros/type_create_to_value.h"

Macros

#define TYPE_CONVERSION_SIGNATURE(TYPE, TYPE_NAME, NAME_MACRO)
 Convert string to TYPE.
 

Functions

int elektraKeyToString (const Key *key, const char **variable)
 Converts a Key to string.
 
int elektraKeyToBoolean (const Key *key, kdb_boolean_t *variable)
 Converts a Key to boolean.
 
int elektraKeyToChar (const Key *key, kdb_char_t *variable)
 Converts a Key to char.
 
int elektraKeyToOctet (const Key *key, kdb_octet_t *variable)
 Converts a Key to octet.
 
int elektraKeyToShort (const Key *key, kdb_short_t *variable)
 Converts a Key to short.
 
int elektraKeyToUnsignedShort (const Key *key, kdb_unsigned_short_t *variable)
 Converts a Key to unsigned_short.
 
int elektraKeyToLong (const Key *key, kdb_long_t *variable)
 Converts a Key to long.
 
int elektraKeyToUnsignedLong (const Key *key, kdb_unsigned_long_t *variable)
 Converts a Key to unsigned_long.
 
int elektraKeyToLongLong (const Key *key, kdb_long_long_t *variable)
 Converts a Key to long_long.
 
int elektraKeyToUnsignedLongLong (const Key *key, kdb_unsigned_long_long_t *variable)
 Converts a Key to unsigned_long_long.
 
int elektraKeyToFloat (const Key *key, kdb_float_t *variable)
 Converts a Key to float.
 
int elektraKeyToDouble (const Key *key, kdb_double_t *variable)
 Converts a Key to double.
 
char * elektraBooleanToString (kdb_boolean_t value)
 Converts a boolean to string.
 
char * elektraCharToString (kdb_char_t value)
 Converts a char to string.
 
char * elektraOctetToString (kdb_octet_t value)
 Converts an octet to string.
 
char * elektraShortToString (kdb_short_t value)
 Converts a short to string.
 
char * elektraUnsignedShortToString (kdb_unsigned_short_t value)
 Converts an unsigned short to string.
 
char * elektraLongToString (kdb_long_t value)
 Converts a long to string.
 
char * elektraUnsignedLongToString (kdb_unsigned_long_t value)
 Converts an unsigned long to string.
 
char * elektraLongLongToString (kdb_long_long_t value)
 Converts a long long to string.
 
char * elektraUnsignedLongLongToString (kdb_unsigned_long_long_t value)
 Converts an unsigned long long to string.
 
char * elektraFloatToString (kdb_float_t value)
 Converts a float to string.
 
char * elektraDoubleToString (kdb_double_t value)
 Converts a double to string.
 

Detailed Description

Elektra High Level API.

Macro Definition Documentation

◆ TYPE_CONVERSION_SIGNATURE

TYPE_CONVERSION_SIGNATURE ( TYPE,
TYPE_NAME,
NAME_MACRO )
Value:
int NAME_MACRO (TYPE_NAME) (const Key * KEY_PARAM_NAME, TYPE * VARIABLE_PARAM_NAME)

Convert string to TYPE.

The variable is only changed if no conversion error occurred

Example: int variable = 1234; if (!NAME_MACRO (TYPE_NAME) (key, &variable)) { // conversion failed // variable == 1234 } // variable was changed

Parameters
keykey
variablepointer to variable
Return values
1on success
0on conversion error

Function Documentation

◆ elektraBooleanToString()

char * elektraBooleanToString ( kdb_boolean_t value)

Converts a boolean to string.

The string is allocated with elektraMalloc() and must be disposed of with elektraFree().

Parameters
valuethe boolean to convert
Returns
a new string allocated with elektraMalloc, or 0 on error

◆ elektraCharToString()

char * elektraCharToString ( kdb_char_t value)

Converts a char to string.

The string is allocated with elektraMalloc() and must be disposed of with elektraFree().

Parameters
valuethe value to convert
Returns
a new string allocated with elektraMalloc, or 0 on error

◆ elektraDoubleToString()

char * elektraDoubleToString ( kdb_double_t value)

Converts a double to string.

The string is allocated with elektraMalloc() and must be disposed of with elektraFree().

Parameters
valuethe value to convert
Returns
a new string allocated with elektraMalloc, or 0 on error

◆ elektraFloatToString()

char * elektraFloatToString ( kdb_float_t value)

Converts a float to string.

The string is allocated with elektraMalloc() and must be disposed of with elektraFree().

Parameters
valuethe value to convert
Returns
a new string allocated with elektraMalloc, or 0 on error

◆ elektraKeyToBoolean()

int elektraKeyToBoolean ( const Key * key,
kdb_boolean_t * variable )

Converts a Key to boolean.

The value "1" is regarded as true, anything is as false.

The variable pointed to by variable is unchanged, if an error occurs.

Parameters
keythe key to convert
variablepointer to the output variable
Return values
1on success
0otherwise

Create key to type conversion function.

This supermacro creates the following functions:

  • int NAME_MACRO (TYPE_NAME) (Key * key, TYPE * variable)
Parameters
TYPEvalid C type (e.g. int or kdb_short_t)
TYPE_NAMEname suffix for the functions (e.g. Int or UnsignedLong)
VALUE_TYPEoptional, defaults to TYPE. Ideally a larger type assigned to variable value for checking the range before the variable is updated
TO_VALUEexpression for converting string (variable containing the key value) to VALUE_TYPE
CHECK_CONVERSIONoptional, defaults to true. A boolean expression. Allows to check the range after conversion. Use ELEKTRA_TYPE_CHECK_CONVERSION to check if a conversion using strto*()-functions was successful and ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (RANGE) to check additionally for a specified range.
CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if CHECK_CONVERSION evaluates to false.
PRE_CHECK_CONVERSION_BLOCKoptional, defaults to empty. Allows to add additional code for pre-conversion checks (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK_BLOCK)
PRE_CHECK_CONVERSIONoptional, defaults to true. A boolean expression to check the contents of string before conversion (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK).
PRE_CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if PRE_CHECK_CONVERSION evaluates to false.
DISABLE_UNDEF_PARAMETERSdefine to disable undefining of parameters after the macro. Use if parameters are used within another supermacro.
CODE_ONLYoptional, defaults to 0. Set to 1 to only generate the function body. This is useful, if you want to create a function with a custom signature for example.
KEY_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'key' otherwise. The name of the variable/parameter containing the Key, whose value will be converted
VARIABLE_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'variable' otherwise. The name of the variable/parameter containing the pointer to where the result should be written

Convert string to TYPE.

The variable is only changed if no conversion error occurred

Example: int variable = 1234; if (!NAME_MACRO (TYPE_NAME) (key, &variable)) { // conversion failed // variable == 1234 } // variable was changed

Parameters
keykey
variablepointer to variable
Return values
1on success
0on conversion error

◆ elektraKeyToChar()

int elektraKeyToChar ( const Key * key,
kdb_char_t * variable )

Converts a Key to char.

The variable pointed to by variable is unchanged, if an error occurs.

Parameters
keythe key to convert
variablepointer to the output variable
Return values
1on success
0otherwise

Create key to type conversion function.

This supermacro creates the following functions:

  • int NAME_MACRO (TYPE_NAME) (Key * key, TYPE * variable)
Parameters
TYPEvalid C type (e.g. int or kdb_short_t)
TYPE_NAMEname suffix for the functions (e.g. Int or UnsignedLong)
VALUE_TYPEoptional, defaults to TYPE. Ideally a larger type assigned to variable value for checking the range before the variable is updated
TO_VALUEexpression for converting string (variable containing the key value) to VALUE_TYPE
CHECK_CONVERSIONoptional, defaults to true. A boolean expression. Allows to check the range after conversion. Use ELEKTRA_TYPE_CHECK_CONVERSION to check if a conversion using strto*()-functions was successful and ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (RANGE) to check additionally for a specified range.
CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if CHECK_CONVERSION evaluates to false.
PRE_CHECK_CONVERSION_BLOCKoptional, defaults to empty. Allows to add additional code for pre-conversion checks (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK_BLOCK)
PRE_CHECK_CONVERSIONoptional, defaults to true. A boolean expression to check the contents of string before conversion (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK).
PRE_CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if PRE_CHECK_CONVERSION evaluates to false.
DISABLE_UNDEF_PARAMETERSdefine to disable undefining of parameters after the macro. Use if parameters are used within another supermacro.
CODE_ONLYoptional, defaults to 0. Set to 1 to only generate the function body. This is useful, if you want to create a function with a custom signature for example.
KEY_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'key' otherwise. The name of the variable/parameter containing the Key, whose value will be converted
VARIABLE_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'variable' otherwise. The name of the variable/parameter containing the pointer to where the result should be written

Convert string to TYPE.

The variable is only changed if no conversion error occurred

Example: int variable = 1234; if (!NAME_MACRO (TYPE_NAME) (key, &variable)) { // conversion failed // variable == 1234 } // variable was changed

Parameters
keykey
variablepointer to variable
Return values
1on success
0on conversion error

◆ elektraKeyToDouble()

int elektraKeyToDouble ( const Key * key,
kdb_double_t * variable )

Converts a Key to double.

The variable pointed to by variable is unchanged, if an error occurs.

Parameters
keythe key to convert
variablepointer to the output variable
Return values
1on success
0otherwise

Create key to type conversion function.

This supermacro creates the following functions:

  • int NAME_MACRO (TYPE_NAME) (Key * key, TYPE * variable)
Parameters
TYPEvalid C type (e.g. int or kdb_short_t)
TYPE_NAMEname suffix for the functions (e.g. Int or UnsignedLong)
VALUE_TYPEoptional, defaults to TYPE. Ideally a larger type assigned to variable value for checking the range before the variable is updated
TO_VALUEexpression for converting string (variable containing the key value) to VALUE_TYPE
CHECK_CONVERSIONoptional, defaults to true. A boolean expression. Allows to check the range after conversion. Use ELEKTRA_TYPE_CHECK_CONVERSION to check if a conversion using strto*()-functions was successful and ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (RANGE) to check additionally for a specified range.
CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if CHECK_CONVERSION evaluates to false.
PRE_CHECK_CONVERSION_BLOCKoptional, defaults to empty. Allows to add additional code for pre-conversion checks (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK_BLOCK)
PRE_CHECK_CONVERSIONoptional, defaults to true. A boolean expression to check the contents of string before conversion (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK).
PRE_CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if PRE_CHECK_CONVERSION evaluates to false.
DISABLE_UNDEF_PARAMETERSdefine to disable undefining of parameters after the macro. Use if parameters are used within another supermacro.
CODE_ONLYoptional, defaults to 0. Set to 1 to only generate the function body. This is useful, if you want to create a function with a custom signature for example.
KEY_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'key' otherwise. The name of the variable/parameter containing the Key, whose value will be converted
VARIABLE_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'variable' otherwise. The name of the variable/parameter containing the pointer to where the result should be written

Convert string to TYPE.

The variable is only changed if no conversion error occurred

Example: int variable = 1234; if (!NAME_MACRO (TYPE_NAME) (key, &variable)) { // conversion failed // variable == 1234 } // variable was changed

Parameters
keykey
variablepointer to variable
Return values
1on success
0on conversion error

◆ elektraKeyToFloat()

int elektraKeyToFloat ( const Key * key,
kdb_float_t * variable )

Converts a Key to float.

The variable pointed to by variable is unchanged, if an error occurs.

Parameters
keythe key to convert
variablepointer to the output variable
Return values
1on success
0otherwise

Create key to type conversion function.

This supermacro creates the following functions:

  • int NAME_MACRO (TYPE_NAME) (Key * key, TYPE * variable)
Parameters
TYPEvalid C type (e.g. int or kdb_short_t)
TYPE_NAMEname suffix for the functions (e.g. Int or UnsignedLong)
VALUE_TYPEoptional, defaults to TYPE. Ideally a larger type assigned to variable value for checking the range before the variable is updated
TO_VALUEexpression for converting string (variable containing the key value) to VALUE_TYPE
CHECK_CONVERSIONoptional, defaults to true. A boolean expression. Allows to check the range after conversion. Use ELEKTRA_TYPE_CHECK_CONVERSION to check if a conversion using strto*()-functions was successful and ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (RANGE) to check additionally for a specified range.
CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if CHECK_CONVERSION evaluates to false.
PRE_CHECK_CONVERSION_BLOCKoptional, defaults to empty. Allows to add additional code for pre-conversion checks (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK_BLOCK)
PRE_CHECK_CONVERSIONoptional, defaults to true. A boolean expression to check the contents of string before conversion (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK).
PRE_CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if PRE_CHECK_CONVERSION evaluates to false.
DISABLE_UNDEF_PARAMETERSdefine to disable undefining of parameters after the macro. Use if parameters are used within another supermacro.
CODE_ONLYoptional, defaults to 0. Set to 1 to only generate the function body. This is useful, if you want to create a function with a custom signature for example.
KEY_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'key' otherwise. The name of the variable/parameter containing the Key, whose value will be converted
VARIABLE_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'variable' otherwise. The name of the variable/parameter containing the pointer to where the result should be written

Convert string to TYPE.

The variable is only changed if no conversion error occurred

Example: int variable = 1234; if (!NAME_MACRO (TYPE_NAME) (key, &variable)) { // conversion failed // variable == 1234 } // variable was changed

Parameters
keykey
variablepointer to variable
Return values
1on success
0on conversion error

◆ elektraKeyToLong()

int elektraKeyToLong ( const Key * key,
kdb_long_t * variable )

Converts a Key to long.

The variable pointed to by variable is unchanged, if an error occurs.

Parameters
keythe key to convert
variablepointer to the output variable
Return values
1on success
0otherwise

Create key to type conversion function.

This supermacro creates the following functions:

  • int NAME_MACRO (TYPE_NAME) (Key * key, TYPE * variable)
Parameters
TYPEvalid C type (e.g. int or kdb_short_t)
TYPE_NAMEname suffix for the functions (e.g. Int or UnsignedLong)
VALUE_TYPEoptional, defaults to TYPE. Ideally a larger type assigned to variable value for checking the range before the variable is updated
TO_VALUEexpression for converting string (variable containing the key value) to VALUE_TYPE
CHECK_CONVERSIONoptional, defaults to true. A boolean expression. Allows to check the range after conversion. Use ELEKTRA_TYPE_CHECK_CONVERSION to check if a conversion using strto*()-functions was successful and ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (RANGE) to check additionally for a specified range.
CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if CHECK_CONVERSION evaluates to false.
PRE_CHECK_CONVERSION_BLOCKoptional, defaults to empty. Allows to add additional code for pre-conversion checks (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK_BLOCK)
PRE_CHECK_CONVERSIONoptional, defaults to true. A boolean expression to check the contents of string before conversion (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK).
PRE_CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if PRE_CHECK_CONVERSION evaluates to false.
DISABLE_UNDEF_PARAMETERSdefine to disable undefining of parameters after the macro. Use if parameters are used within another supermacro.
CODE_ONLYoptional, defaults to 0. Set to 1 to only generate the function body. This is useful, if you want to create a function with a custom signature for example.
KEY_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'key' otherwise. The name of the variable/parameter containing the Key, whose value will be converted
VARIABLE_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'variable' otherwise. The name of the variable/parameter containing the pointer to where the result should be written

Convert string to TYPE.

The variable is only changed if no conversion error occurred

Example: int variable = 1234; if (!NAME_MACRO (TYPE_NAME) (key, &variable)) { // conversion failed // variable == 1234 } // variable was changed

Parameters
keykey
variablepointer to variable
Return values
1on success
0on conversion error

◆ elektraKeyToLongLong()

int elektraKeyToLongLong ( const Key * key,
kdb_long_long_t * variable )

Converts a Key to long_long.

The variable pointed to by variable is unchanged, if an error occurs.

Parameters
keythe key to convert
variablepointer to the output variable
Return values
1on success
0otherwise

Create key to type conversion function.

This supermacro creates the following functions:

  • int NAME_MACRO (TYPE_NAME) (Key * key, TYPE * variable)
Parameters
TYPEvalid C type (e.g. int or kdb_short_t)
TYPE_NAMEname suffix for the functions (e.g. Int or UnsignedLong)
VALUE_TYPEoptional, defaults to TYPE. Ideally a larger type assigned to variable value for checking the range before the variable is updated
TO_VALUEexpression for converting string (variable containing the key value) to VALUE_TYPE
CHECK_CONVERSIONoptional, defaults to true. A boolean expression. Allows to check the range after conversion. Use ELEKTRA_TYPE_CHECK_CONVERSION to check if a conversion using strto*()-functions was successful and ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (RANGE) to check additionally for a specified range.
CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if CHECK_CONVERSION evaluates to false.
PRE_CHECK_CONVERSION_BLOCKoptional, defaults to empty. Allows to add additional code for pre-conversion checks (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK_BLOCK)
PRE_CHECK_CONVERSIONoptional, defaults to true. A boolean expression to check the contents of string before conversion (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK).
PRE_CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if PRE_CHECK_CONVERSION evaluates to false.
DISABLE_UNDEF_PARAMETERSdefine to disable undefining of parameters after the macro. Use if parameters are used within another supermacro.
CODE_ONLYoptional, defaults to 0. Set to 1 to only generate the function body. This is useful, if you want to create a function with a custom signature for example.
KEY_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'key' otherwise. The name of the variable/parameter containing the Key, whose value will be converted
VARIABLE_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'variable' otherwise. The name of the variable/parameter containing the pointer to where the result should be written

Convert string to TYPE.

The variable is only changed if no conversion error occurred

Example: int variable = 1234; if (!NAME_MACRO (TYPE_NAME) (key, &variable)) { // conversion failed // variable == 1234 } // variable was changed

Parameters
keykey
variablepointer to variable
Return values
1on success
0on conversion error

◆ elektraKeyToOctet()

int elektraKeyToOctet ( const Key * key,
kdb_octet_t * variable )

Converts a Key to octet.

The variable pointed to by variable is unchanged, if an error occurs.

Parameters
keythe key to convert
variablepointer to the output variable
Return values
1on success
0otherwise

Create key to type conversion function.

This supermacro creates the following functions:

  • int NAME_MACRO (TYPE_NAME) (Key * key, TYPE * variable)
Parameters
TYPEvalid C type (e.g. int or kdb_short_t)
TYPE_NAMEname suffix for the functions (e.g. Int or UnsignedLong)
VALUE_TYPEoptional, defaults to TYPE. Ideally a larger type assigned to variable value for checking the range before the variable is updated
TO_VALUEexpression for converting string (variable containing the key value) to VALUE_TYPE
CHECK_CONVERSIONoptional, defaults to true. A boolean expression. Allows to check the range after conversion. Use ELEKTRA_TYPE_CHECK_CONVERSION to check if a conversion using strto*()-functions was successful and ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (RANGE) to check additionally for a specified range.
CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if CHECK_CONVERSION evaluates to false.
PRE_CHECK_CONVERSION_BLOCKoptional, defaults to empty. Allows to add additional code for pre-conversion checks (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK_BLOCK)
PRE_CHECK_CONVERSIONoptional, defaults to true. A boolean expression to check the contents of string before conversion (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK).
PRE_CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if PRE_CHECK_CONVERSION evaluates to false.
DISABLE_UNDEF_PARAMETERSdefine to disable undefining of parameters after the macro. Use if parameters are used within another supermacro.
CODE_ONLYoptional, defaults to 0. Set to 1 to only generate the function body. This is useful, if you want to create a function with a custom signature for example.
KEY_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'key' otherwise. The name of the variable/parameter containing the Key, whose value will be converted
VARIABLE_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'variable' otherwise. The name of the variable/parameter containing the pointer to where the result should be written

Convert string to TYPE.

The variable is only changed if no conversion error occurred

Example: int variable = 1234; if (!NAME_MACRO (TYPE_NAME) (key, &variable)) { // conversion failed // variable == 1234 } // variable was changed

Parameters
keykey
variablepointer to variable
Return values
1on success
0on conversion error

◆ elektraKeyToShort()

int elektraKeyToShort ( const Key * key,
kdb_short_t * variable )

Converts a Key to short.

The variable pointed to by variable is unchanged, if an error occurs.

Parameters
keythe key to convert
variablepointer to the output variable
Return values
1on success
0otherwise

Create key to type conversion function.

This supermacro creates the following functions:

  • int NAME_MACRO (TYPE_NAME) (Key * key, TYPE * variable)
Parameters
TYPEvalid C type (e.g. int or kdb_short_t)
TYPE_NAMEname suffix for the functions (e.g. Int or UnsignedLong)
VALUE_TYPEoptional, defaults to TYPE. Ideally a larger type assigned to variable value for checking the range before the variable is updated
TO_VALUEexpression for converting string (variable containing the key value) to VALUE_TYPE
CHECK_CONVERSIONoptional, defaults to true. A boolean expression. Allows to check the range after conversion. Use ELEKTRA_TYPE_CHECK_CONVERSION to check if a conversion using strto*()-functions was successful and ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (RANGE) to check additionally for a specified range.
CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if CHECK_CONVERSION evaluates to false.
PRE_CHECK_CONVERSION_BLOCKoptional, defaults to empty. Allows to add additional code for pre-conversion checks (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK_BLOCK)
PRE_CHECK_CONVERSIONoptional, defaults to true. A boolean expression to check the contents of string before conversion (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK).
PRE_CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if PRE_CHECK_CONVERSION evaluates to false.
DISABLE_UNDEF_PARAMETERSdefine to disable undefining of parameters after the macro. Use if parameters are used within another supermacro.
CODE_ONLYoptional, defaults to 0. Set to 1 to only generate the function body. This is useful, if you want to create a function with a custom signature for example.
KEY_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'key' otherwise. The name of the variable/parameter containing the Key, whose value will be converted
VARIABLE_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'variable' otherwise. The name of the variable/parameter containing the pointer to where the result should be written

Convert string to TYPE.

The variable is only changed if no conversion error occurred

Example: int variable = 1234; if (!NAME_MACRO (TYPE_NAME) (key, &variable)) { // conversion failed // variable == 1234 } // variable was changed

Parameters
keykey
variablepointer to variable
Return values
1on success
0on conversion error

◆ elektraKeyToString()

int elektraKeyToString ( const Key * key,
const char ** variable )

Converts a Key to string.

The variable pointed to by variable is unchanged, if an error occurs.

Parameters
keythe key to convert
variablepointer to the output variable
Return values
1on success
0otherwise

Create key to type conversion function.

This supermacro creates the following functions:

  • int NAME_MACRO (TYPE_NAME) (Key * key, TYPE * variable)
Parameters
TYPEvalid C type (e.g. int or kdb_short_t)
TYPE_NAMEname suffix for the functions (e.g. Int or UnsignedLong)
VALUE_TYPEoptional, defaults to TYPE. Ideally a larger type assigned to variable value for checking the range before the variable is updated
TO_VALUEexpression for converting string (variable containing the key value) to VALUE_TYPE
CHECK_CONVERSIONoptional, defaults to true. A boolean expression. Allows to check the range after conversion. Use ELEKTRA_TYPE_CHECK_CONVERSION to check if a conversion using strto*()-functions was successful and ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (RANGE) to check additionally for a specified range.
CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if CHECK_CONVERSION evaluates to false.
PRE_CHECK_CONVERSION_BLOCKoptional, defaults to empty. Allows to add additional code for pre-conversion checks (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK_BLOCK)
PRE_CHECK_CONVERSIONoptional, defaults to true. A boolean expression to check the contents of string before conversion (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK).
PRE_CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if PRE_CHECK_CONVERSION evaluates to false.
DISABLE_UNDEF_PARAMETERSdefine to disable undefining of parameters after the macro. Use if parameters are used within another supermacro.
CODE_ONLYoptional, defaults to 0. Set to 1 to only generate the function body. This is useful, if you want to create a function with a custom signature for example.
KEY_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'key' otherwise. The name of the variable/parameter containing the Key, whose value will be converted
VARIABLE_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'variable' otherwise. The name of the variable/parameter containing the pointer to where the result should be written

Convert string to TYPE.

The variable is only changed if no conversion error occurred

Example: int variable = 1234; if (!NAME_MACRO (TYPE_NAME) (key, &variable)) { // conversion failed // variable == 1234 } // variable was changed

Parameters
keykey
variablepointer to variable
Return values
1on success
0on conversion error

◆ elektraKeyToUnsignedLong()

int elektraKeyToUnsignedLong ( const Key * key,
kdb_unsigned_long_t * variable )

Converts a Key to unsigned_long.

The variable pointed to by variable is unchanged, if an error occurs.

Parameters
keythe key to convert
variablepointer to the output variable
Return values
1on success
0otherwise

Create key to type conversion function.

This supermacro creates the following functions:

  • int NAME_MACRO (TYPE_NAME) (Key * key, TYPE * variable)
Parameters
TYPEvalid C type (e.g. int or kdb_short_t)
TYPE_NAMEname suffix for the functions (e.g. Int or UnsignedLong)
VALUE_TYPEoptional, defaults to TYPE. Ideally a larger type assigned to variable value for checking the range before the variable is updated
TO_VALUEexpression for converting string (variable containing the key value) to VALUE_TYPE
CHECK_CONVERSIONoptional, defaults to true. A boolean expression. Allows to check the range after conversion. Use ELEKTRA_TYPE_CHECK_CONVERSION to check if a conversion using strto*()-functions was successful and ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (RANGE) to check additionally for a specified range.
CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if CHECK_CONVERSION evaluates to false.
PRE_CHECK_CONVERSION_BLOCKoptional, defaults to empty. Allows to add additional code for pre-conversion checks (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK_BLOCK)
PRE_CHECK_CONVERSIONoptional, defaults to true. A boolean expression to check the contents of string before conversion (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK).
PRE_CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if PRE_CHECK_CONVERSION evaluates to false.
DISABLE_UNDEF_PARAMETERSdefine to disable undefining of parameters after the macro. Use if parameters are used within another supermacro.
CODE_ONLYoptional, defaults to 0. Set to 1 to only generate the function body. This is useful, if you want to create a function with a custom signature for example.
KEY_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'key' otherwise. The name of the variable/parameter containing the Key, whose value will be converted
VARIABLE_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'variable' otherwise. The name of the variable/parameter containing the pointer to where the result should be written

Convert string to TYPE.

The variable is only changed if no conversion error occurred

Example: int variable = 1234; if (!NAME_MACRO (TYPE_NAME) (key, &variable)) { // conversion failed // variable == 1234 } // variable was changed

Parameters
keykey
variablepointer to variable
Return values
1on success
0on conversion error

◆ elektraKeyToUnsignedLongLong()

int elektraKeyToUnsignedLongLong ( const Key * key,
kdb_unsigned_long_long_t * variable )

Converts a Key to unsigned_long_long.

The variable pointed to by variable is unchanged, if an error occurs.

Parameters
keythe key to convert
variablepointer to the output variable
Return values
1on success
0otherwise

Create key to type conversion function.

This supermacro creates the following functions:

  • int NAME_MACRO (TYPE_NAME) (Key * key, TYPE * variable)
Parameters
TYPEvalid C type (e.g. int or kdb_short_t)
TYPE_NAMEname suffix for the functions (e.g. Int or UnsignedLong)
VALUE_TYPEoptional, defaults to TYPE. Ideally a larger type assigned to variable value for checking the range before the variable is updated
TO_VALUEexpression for converting string (variable containing the key value) to VALUE_TYPE
CHECK_CONVERSIONoptional, defaults to true. A boolean expression. Allows to check the range after conversion. Use ELEKTRA_TYPE_CHECK_CONVERSION to check if a conversion using strto*()-functions was successful and ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (RANGE) to check additionally for a specified range.
CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if CHECK_CONVERSION evaluates to false.
PRE_CHECK_CONVERSION_BLOCKoptional, defaults to empty. Allows to add additional code for pre-conversion checks (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK_BLOCK)
PRE_CHECK_CONVERSIONoptional, defaults to true. A boolean expression to check the contents of string before conversion (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK).
PRE_CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if PRE_CHECK_CONVERSION evaluates to false.
DISABLE_UNDEF_PARAMETERSdefine to disable undefining of parameters after the macro. Use if parameters are used within another supermacro.
CODE_ONLYoptional, defaults to 0. Set to 1 to only generate the function body. This is useful, if you want to create a function with a custom signature for example.
KEY_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'key' otherwise. The name of the variable/parameter containing the Key, whose value will be converted
VARIABLE_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'variable' otherwise. The name of the variable/parameter containing the pointer to where the result should be written

Convert string to TYPE.

The variable is only changed if no conversion error occurred

Example: int variable = 1234; if (!NAME_MACRO (TYPE_NAME) (key, &variable)) { // conversion failed // variable == 1234 } // variable was changed

Parameters
keykey
variablepointer to variable
Return values
1on success
0on conversion error

◆ elektraKeyToUnsignedShort()

int elektraKeyToUnsignedShort ( const Key * key,
kdb_unsigned_short_t * variable )

Converts a Key to unsigned_short.

The variable pointed to by variable is unchanged, if an error occurs.

Parameters
keythe key to convert
variablepointer to the output variable
Return values
1on success
0otherwise

Create key to type conversion function.

This supermacro creates the following functions:

  • int NAME_MACRO (TYPE_NAME) (Key * key, TYPE * variable)
Parameters
TYPEvalid C type (e.g. int or kdb_short_t)
TYPE_NAMEname suffix for the functions (e.g. Int or UnsignedLong)
VALUE_TYPEoptional, defaults to TYPE. Ideally a larger type assigned to variable value for checking the range before the variable is updated
TO_VALUEexpression for converting string (variable containing the key value) to VALUE_TYPE
CHECK_CONVERSIONoptional, defaults to true. A boolean expression. Allows to check the range after conversion. Use ELEKTRA_TYPE_CHECK_CONVERSION to check if a conversion using strto*()-functions was successful and ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (RANGE) to check additionally for a specified range.
CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if CHECK_CONVERSION evaluates to false.
PRE_CHECK_CONVERSION_BLOCKoptional, defaults to empty. Allows to add additional code for pre-conversion checks (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK_BLOCK)
PRE_CHECK_CONVERSIONoptional, defaults to true. A boolean expression to check the contents of string before conversion (e.g. ELEKTRA_TYPE_NEGATIVE_PRE_CHECK).
PRE_CHECK_FAIL_BLOCKoptional, defaults to logging a warning in the key. The code to be executed (before returning 0), if PRE_CHECK_CONVERSION evaluates to false.
DISABLE_UNDEF_PARAMETERSdefine to disable undefining of parameters after the macro. Use if parameters are used within another supermacro.
CODE_ONLYoptional, defaults to 0. Set to 1 to only generate the function body. This is useful, if you want to create a function with a custom signature for example.
KEY_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'key' otherwise. The name of the variable/parameter containing the Key, whose value will be converted
VARIABLE_PARAM_NAMEmust be set, #if CODE_ONLY, will be set to 'variable' otherwise. The name of the variable/parameter containing the pointer to where the result should be written

Convert string to TYPE.

The variable is only changed if no conversion error occurred

Example: int variable = 1234; if (!NAME_MACRO (TYPE_NAME) (key, &variable)) { // conversion failed // variable == 1234 } // variable was changed

Parameters
keykey
variablepointer to variable
Return values
1on success
0on conversion error

◆ elektraLongLongToString()

char * elektraLongLongToString ( kdb_long_long_t value)

Converts a long long to string.

The string is allocated with elektraMalloc() and must be disposed of with elektraFree().

Parameters
valuethe value to convert
Returns
a new string allocated with elektraMalloc, or 0 on error

◆ elektraLongToString()

char * elektraLongToString ( kdb_long_t value)

Converts a long to string.

The string is allocated with elektraMalloc() and must be disposed of with elektraFree().

Parameters
valuethe value to convert
Returns
a new string allocated with elektraMalloc, or 0 on error

◆ elektraOctetToString()

char * elektraOctetToString ( kdb_octet_t value)

Converts an octet to string.

The string is allocated with elektraMalloc() and must be disposed of with elektraFree().

Parameters
valuethe value to convert
Returns
a new string allocated with elektraMalloc, or 0 on error

◆ elektraShortToString()

char * elektraShortToString ( kdb_short_t value)

Converts a short to string.

The string is allocated with elektraMalloc() and must be disposed of with elektraFree().

Parameters
valuethe value to convert
Returns
a new string allocated with elektraMalloc, or 0 on error

◆ elektraUnsignedLongLongToString()

char * elektraUnsignedLongLongToString ( kdb_unsigned_long_long_t value)

Converts an unsigned long long to string.

The string is allocated with elektraMalloc() and must be disposed of with elektraFree().

Parameters
valuethe value to convert
Returns
a new string allocated with elektraMalloc, or 0 on error

◆ elektraUnsignedLongToString()

char * elektraUnsignedLongToString ( kdb_unsigned_long_t value)

Converts an unsigned long to string.

The string is allocated with elektraMalloc() and must be disposed of with elektraFree().

Parameters
valuethe value to convert
Returns
a new string allocated with elektraMalloc, or 0 on error

◆ elektraUnsignedShortToString()

char * elektraUnsignedShortToString ( kdb_unsigned_short_t value)

Converts an unsigned short to string.

The string is allocated with elektraMalloc() and must be disposed of with elektraFree().

Parameters
valuethe value to convert
Returns
a new string allocated with elektraMalloc, or 0 on error