Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Functions
String table

String table is a data type to store integers or pointers to more complex data in pairs. More...

Data Structures

struct  sol_str_table
 String table element type. More...
 
struct  sol_str_table_int64
 String/int64_t table type. More...
 
struct  sol_str_table_ptr
 String/Pointer table type. More...
 

Macros

#define SOL_STR_TABLE_INT64_ITEM(_key, _val)
 Helper macro to make easier to declare a <key, value> pair. More...
 
#define sol_str_table_int64_lookup(_table_int64, _key, _pval)
 Similar to sol_str_table_int64_lookup_fallback, but returning true/false. More...
 
#define SOL_STR_TABLE_INT64_NOT_FOUND   INT64_MAX
 flag to detect key 'misses' in sol_str_table_int64_lookup. More...
 
#define SOL_STR_TABLE_ITEM(_key, _val)   { .key = SOL_STR_STATIC_ASSERT_LITERAL(_key), .len = sizeof(_key) - 1, .val = _val }
 Helper macro to make easier to declare a <key, int16_t> pair. More...
 
#define sol_str_table_lookup(_table, _key, _pval)
 Similar to sol_str_table_lookup_fallback, but returning true/false. More...
 
#define SOL_STR_TABLE_NOT_FOUND   INT16_MAX
 flag to detect key 'misses' in sol_str_table_lookup. More...
 
#define SOL_STR_TABLE_PTR_ITEM(_key, _val)
 Helper macro to make easier to declare a <key, value> pair. More...
 
#define sol_str_table_ptr_lookup(_table_ptr, _key, _pval)
 Similar to sol_str_table_ptr_lookup_fallback, but returning true/false. More...
 

Typedefs

typedef struct sol_str_table sol_str_table
 String table element type. More...
 
typedef struct sol_str_table_int64 sol_str_table_int64
 String/int64_t table type. More...
 
typedef struct sol_str_table_ptr sol_str_table_ptr
 String/Pointer table type. More...
 

Functions

const struct sol_str_tablesol_str_table_entry_lookup (const struct sol_str_table *table, const struct sol_str_slice key)
 Retrieves the table entry associated with a given key from the string/integer table. More...
 
const struct sol_str_table_int64sol_str_table_int64_entry_lookup (const struct sol_str_table_int64 *table, const struct sol_str_slice key)
 Retrieves the table entry associated with a given key from the string/pointer table. More...
 
int64_t sol_str_table_int64_lookup_fallback (const struct sol_str_table_int64 *table_int64, const struct sol_str_slice key, int64_t fallback)
 Retrieves the value associated with a given key from the string/int64_t table. More...
 
int16_t sol_str_table_lookup_fallback (const struct sol_str_table *table, const struct sol_str_slice key, int16_t fallback)
 Retrieves the value associated with a given key from the string table. More...
 
const struct sol_str_table_ptrsol_str_table_ptr_entry_lookup (const struct sol_str_table_ptr *table, const struct sol_str_slice key)
 Retrieves the table entry associated with a given key from the string/pointer table. More...
 
const void * sol_str_table_ptr_lookup_fallback (const struct sol_str_table_ptr *table_ptr, const struct sol_str_slice key, const void *fallback)
 Retrieves the value associated with a given key from the string/pointer table. More...
 

Detailed Description

String table is a data type to store integers or pointers to more complex data in pairs.

It could be a table of <string, 16-bit integer>, <string, int64_t> or <string, pointer> pairs.

Macro Definition Documentation

#define SOL_STR_TABLE_INT64_ITEM (   _key,
  _val 
)
Value:
.len = sizeof(_key) - 1, \
.val = _val }
#define SOL_STR_STATIC_ASSERT_LITERAL(_s)
Helper macro to assert that the parameter is a string literal.
Definition: sol-str-slice.h:57

Helper macro to make easier to declare a <key, value> pair.

Parameters
_keyPair's key (string)
_valPair's value (int64_t)
#define sol_str_table_int64_lookup (   _table_int64,
  _key,
  _pval 
)
Value:
({ \
int64_t _v = sol_str_table_int64_lookup_fallback(_table_int64, \
*_pval = _v; \
})
int64_t sol_str_table_int64_lookup_fallback(const struct sol_str_table_int64 *table_int64, const struct sol_str_slice key, int64_t fallback)
Retrieves the value associated with a given key from the string/int64_t table.
#define SOL_STR_TABLE_INT64_NOT_FOUND
flag to detect key 'misses' in sol_str_table_int64_lookup.
Definition: sol-str-table.h:291

Similar to sol_str_table_int64_lookup_fallback, but returning true/false.

Returns true/false depending if key is found/not found and write the found value in _pval. If not found, errno is set to ENOENT. If parameters where invalid, errno is set to EINVAL.

Parameters
_table_int64The string/int64_t table
_keyKey to search
_pvalint64_t to int64_t that will hold the found value
See Also
sol_str_table_lookup_fallback
#define SOL_STR_TABLE_INT64_NOT_FOUND   INT64_MAX

flag to detect key 'misses' in sol_str_table_int64_lookup.

#define SOL_STR_TABLE_ITEM (   _key,
  _val 
)    { .key = SOL_STR_STATIC_ASSERT_LITERAL(_key), .len = sizeof(_key) - 1, .val = _val }

Helper macro to make easier to declare a <key, int16_t> pair.

For larger integers see struct sol_str_table_int64, for pointers see struct sol_str_table_ptr.

Parameters
_keyPair's key (string)
_valPair's value (integer)
#define sol_str_table_lookup (   _table,
  _key,
  _pval 
)
Value:
({ \
int16_t _v = sol_str_table_lookup_fallback(_table, _key, INT16_MAX); \
if (_v != INT16_MAX) \
*_pval = _v; \
_v != INT16_MAX; \
})
int16_t sol_str_table_lookup_fallback(const struct sol_str_table *table, const struct sol_str_slice key, int16_t fallback)
Retrieves the value associated with a given key from the string table.

Similar to sol_str_table_lookup_fallback, but returning true/false.

Returns true/false depending if key is found/not found and write the found value in _pval. If not found, errno is set to ENOENT. If parameters were invalid, errno is set to EINVAL.

Note
Uses SOL_STR_TABLE_NOT_FOUND as a flag to detect when key isn't found, so this value cannot be used in the string table for use with this macro.
Parameters
_tableThe string table
_keyKey to search
_pvalPointer that will hold the found value
See Also
sol_str_table_lookup_fallback
#define SOL_STR_TABLE_NOT_FOUND   INT16_MAX

flag to detect key 'misses' in sol_str_table_lookup.

#define SOL_STR_TABLE_PTR_ITEM (   _key,
  _val 
)
Value:
.val = _val, \
.len = sizeof(_key) - 1 }
#define SOL_STR_STATIC_ASSERT_LITERAL(_s)
Helper macro to assert that the parameter is a string literal.
Definition: sol-str-slice.h:57

Helper macro to make easier to declare a <key, value> pair.

Parameters
_keyPair's key (string)
_valPair's value (pointer)
#define sol_str_table_ptr_lookup (   _table_ptr,
  _key,
  _pval 
)
Value:
({ \
const void *_v = sol_str_table_ptr_lookup_fallback(_table_ptr, \
_key, NULL); \
if (_v != NULL) \
*_pval = _v; \
_v != NULL; \
})
const void * sol_str_table_ptr_lookup_fallback(const struct sol_str_table_ptr *table_ptr, const struct sol_str_slice key, const void *fallback)
Retrieves the value associated with a given key from the string/pointer table.

Similar to sol_str_table_ptr_lookup_fallback, but returning true/false.

Returns true/false depending if key is found/not found and write the found value in _pval. If not found, errno is set to ENOENT. If parameters were invalid, errno is set to EINVAL.

Parameters
_table_ptrThe string/pointer table
_keyKey to search
_pvalPointer to pointer that will hold the found value
See Also
sol_str_table_lookup_fallback

Typedef Documentation

typedef struct sol_str_table sol_str_table

String table element type.

For larger integers see struct sol_str_table_int64, for pointers see struct sol_str_table_ptr.

String/int64_t table type.

String/Pointer table type.

Function Documentation

const struct sol_str_table* sol_str_table_entry_lookup ( const struct sol_str_table table,
const struct sol_str_slice  key 
)

Retrieves the table entry associated with a given key from the string/integer table.

Searches table for key string and returns its table entry pointer. If key isn't found (or a bad table argument is passed), NULL is returned and errno is set (either to EINVAL or to ENOENT).

Parameters
tableString/integer table
keyKey to search
Returns
If key is found, it returns its table entry, otherwise NULL is returned and errno is set to ENOENT if the item was not found or to EINVAL if parameters were invalid.
const struct sol_str_table_int64* sol_str_table_int64_entry_lookup ( const struct sol_str_table_int64 table,
const struct sol_str_slice  key 
)

Retrieves the table entry associated with a given key from the string/pointer table.

Searches table for key string and returns its table entry pointer. If key isn't found (or a bad table argument is passed), NULL is returned and errno is set (either to EINVAL or to ENOENT).

Parameters
tableString/pointer table
keyKey to search
Returns
If key is found, it returns its table entry, otherwise NULL is returned and errno is set to ENOENT if the item was not found or to EINVAL if parameters were invalid.
int64_t sol_str_table_int64_lookup_fallback ( const struct sol_str_table_int64 table_int64,
const struct sol_str_slice  key,
int64_t  fallback 
)

Retrieves the value associated with a given key from the string/int64_t table.

Searches table for key string and returns its int64_t value. If key isn't found, fallback is returned.

Parameters
table_int64String/int64_t table
keyKey to search
fallbackFallback int64_t
Returns
If key is found, return its value, otherwise fallback is returned and errno is set to ENOENT if item is not found of EINVAL if parameters were invalid.
int16_t sol_str_table_lookup_fallback ( const struct sol_str_table table,
const struct sol_str_slice  key,
int16_t  fallback 
)

Retrieves the value associated with a given key from the string table.

Searches the string table for key and returns its value. If key isn't found, fallback is returned.

Parameters
tableString table
keyKey to search
fallbackFallback value
Returns
If key is found, return its value, otherwise fallback is returned and errno is set to ENOENT if item is not found of EINVAL if parameters were invalid.
const struct sol_str_table_ptr* sol_str_table_ptr_entry_lookup ( const struct sol_str_table_ptr table,
const struct sol_str_slice  key 
)

Retrieves the table entry associated with a given key from the string/pointer table.

Searches table for key string and returns its table entry pointer. If key isn't found (or a bad table argument is passed), NULL is returned and errno is set (either to EINVAL or to ENOENT).

Parameters
tableString/pointer table
keyKey to search
Returns
If key is found, it returns its table entry, otherwise NULL is returned and errno is set to ENOENT if the item was not found or to EINVAL if parameters were invalid.
const void* sol_str_table_ptr_lookup_fallback ( const struct sol_str_table_ptr table_ptr,
const struct sol_str_slice  key,
const void *  fallback 
)

Retrieves the value associated with a given key from the string/pointer table.

Searches table for key string and returns its pointer. If key isn't found, fallback is returned.

Parameters
table_ptrString/pointer table
keyKey to search
fallbackFallback pointer
Returns
If key is found, return its value, otherwise fallback is returned and errno is set to ENOENT if item is not found of EINVAL if parameters were invalid.