The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Functions
table.h File Reference

Lookup table functions. More...

#include <ctype.h>
#include <string.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
+ Include dependency graph for table.h:

Go to the source code of this file.

Data Structures

struct  fr_table_elem_name_t
 
struct  fr_table_num_indexed_bit_pos_t
 An element in a table indexed by bit position. More...
 
struct  fr_table_num_indexed_t
 An element in a table indexed by numeric value. More...
 
struct  fr_table_num_ordered_t
 An element in an arbitrarily ordered array of name to num mappings. More...
 
struct  fr_table_num_sorted_t
 An element in a lexicographically sorted array of name to num mappings. More...
 
struct  fr_table_ptr_ordered_t
 An element in an arbitrarily ordered array of name to ptr mappings. More...
 
struct  fr_table_ptr_sorted_t
 An element in a lexicographically sorted array of name to ptr mappings. More...
 

Macros

#define ELEM_LEN(_offset)   (*((fr_table_elem_name_t const *)(_offset))).len
 
#define ELEM_STR(_offset)   (*((fr_table_elem_name_t const *)(_offset))).str
 
#define fr_table_max_needle_len(_table)
 
#define fr_table_str_by_str_value(_table, _str_value, _def)
 Brute force search a sorted or ordered ptr table, assuming the pointers are strings. More...
 
#define fr_table_str_by_value(_table, _number, _def)
 Convert an integer to a string. More...
 
#define fr_table_value_by_longest_prefix(_match_len, _table, _name, _name_len, _def)
 Find the longest string match using a sorted or ordered table. More...
 
#define fr_table_value_by_str(_table, _name, _def)
 Convert a string to a value using a sorted or ordered table. More...
 
#define fr_table_value_by_substr(_table, _name, _name_len, _def)
 Convert a partial string to a value using an ordered or sorted table. More...
 
#define NAME_NUMBER_NOT_FOUND   INT32_MIN
 Macro to use as dflt. More...
 
#define TABLE_IDX(_table, _idx, _element_size)   (((uint8_t const *)(_table)) + ((_idx) * (_element_size)))
 
#define TABLE_TYPE_NAME_FUNC(_func, _our_table_type, _our_name, _our_def_type, _our_return_type)
 Create a type-specific name-to-value function. More...
 
#define TABLE_TYPE_NAME_FUNC_RPTR(_func, _our_table_type, _our_name, _our_def_type, _our_out_type)
 Create a type-specific name-to-value function. More...
 
#define TABLE_TYPE_NAME_LEN_FUNC(_func, _our_table_type, _our_name, _our_def_type, _our_return_type)
 Create a type-specific name-to-value function that can perform substring matching with a 'name_len' argument. More...
 
#define TABLE_TYPE_NAME_LEN_FUNC_RPTR(_func, _our_table_type, _our_name, _our_def_type, _our_out_type)
 Create a type-specific name-to-value function that can perform substring matching with a 'name_len' argument. More...
 
#define TABLE_TYPE_NAME_MATCH_LEN_FUNC(_func, _our_table_type, _our_name, _our_def_type, _our_return_type)
 Create a type-specific name-to-value function that can perform substring matching with a 'name_len' argument, and passes back the length of the matched string. More...
 
#define TABLE_TYPE_NAME_MATCH_LEN_FUNC_RPTR(_func, _our_table_type, _our_name, _our_def_type, _our_out_type)
 Create a type-specific name-to-value function that can perform substring matching with a 'name_len' argument, and passes back the length of the matched string. More...
 
#define TABLE_TYPE_NEEDLE_LEN_FUNC(_our_table_type, _our_name)
 
#define TABLE_TYPE_VALUE_FUNC(_our_table_type, _our_name, _our_value_type)
 Create a type-specific value-to-name function. More...
 
#define TABLE_TYPE_VALUE_INDEX_BIT_FIELD_FUNC(_our_table_type, _our_name, _our_value_type)
 Create a type-specific value-to-name function, which uses the highest bit set in the value as an index into the table. More...
 
#define TABLE_TYPE_VALUE_INDEX_FUNC(_our_table_type, _our_name, _our_value_type)
 Create a type-specific value-to-name function, which uses the value as an index into the table. More...
 

Functions

char const * _fr_table_ptr_by_str_value (fr_table_ptr_sorted_t const *table, size_t table_len, char const *str_val, char const *def)
 Brute force search a sorted or ordered ptr table, assuming the pointers are strings. More...
 
char const * fr_table_indexed_str_by_bit_field (fr_table_num_indexed_bit_pos_t const *table, size_t table_len, uint64_t number, char const *def)
 
char const * fr_table_indexed_str_by_num (fr_table_num_indexed_t const *table, size_t table_len, unsigned int number, char const *def)
 
int fr_table_ordered_num_by_longest_prefix (size_t *match_len, fr_table_num_ordered_t const *table, size_t table_len, char const *name, ssize_t name_len, int def)
 
int fr_table_ordered_num_by_str (fr_table_num_ordered_t const *table, size_t table_len, char const *name, int def)
 
int fr_table_ordered_num_by_substr (fr_table_num_ordered_t const *table, size_t table_len, char const *name, ssize_t name_len, int def)
 
void * fr_table_ordered_ptr_by_longest_prefix (size_t *match_len, fr_table_ptr_ordered_t const *table, size_t table_len, char const *name, ssize_t name_len, void const *def)
 
void * fr_table_ordered_ptr_by_str (fr_table_ptr_ordered_t const *table, size_t table_len, char const *name, void const *def)
 
void * fr_table_ordered_ptr_by_substr (fr_table_ptr_ordered_t const *table, size_t table_len, char const *name, ssize_t name_len, void const *def)
 
char const * fr_table_ordered_str_by_num (fr_table_num_ordered_t const *table, size_t table_len, int number, char const *def)
 
char const * fr_table_ordered_str_by_ptr (fr_table_ptr_ordered_t const *table, size_t table_len, void const *ptr, char const *def)
 
int fr_table_sorted_num_by_longest_prefix (size_t *match_len, fr_table_num_sorted_t const *table, size_t table_len, char const *name, ssize_t name_len, int def)
 
int fr_table_sorted_num_by_str (fr_table_num_sorted_t const *table, size_t table_len, char const *name, int def)
 
int fr_table_sorted_num_by_substr (fr_table_num_sorted_t const *table, size_t table_len, char const *name, ssize_t name_len, int def)
 
void * fr_table_sorted_ptr_by_longest_prefix (size_t *match_len, fr_table_ptr_sorted_t const *table, size_t table_len, char const *name, ssize_t name_len, void const *def)
 
void * fr_table_sorted_ptr_by_str (fr_table_ptr_sorted_t const *table, size_t table_len, char const *name, void const *def)
 
void * fr_table_sorted_ptr_by_substr (fr_table_ptr_sorted_t const *table, size_t table_len, char const *name, ssize_t name_len, void const *def)
 
char const * fr_table_sorted_str_by_num (fr_table_num_sorted_t const *table, size_t table_len, int number, char const *def)
 
char const * fr_table_sorted_str_by_ptr (fr_table_ptr_sorted_t const *table, size_t table_len, void const *ptr, char const *def)
 
static void const * table_ordered_value_by_longest_prefix (size_t *match_len, void const *table, size_t table_len, size_t element_size, char const *name, ssize_t name_len)
 Find the longest string match using an arbitrarily ordered table. More...
 
static void const * table_ordered_value_by_str (void const *table, size_t table_len, size_t element_size, char const *name)
 Convert a string to a value using an arbitrarily ordered table. More...
 
static void const * table_ordered_value_by_substr (void const *table, size_t table_len, size_t element_size, char const *name, ssize_t name_len)
 Convert a string matching part of name to an integer using an arbitrarily ordered table. More...
 
static void const * table_sorted_value_by_longest_prefix (size_t *match_len, void const *table, size_t table_len, size_t element_size, char const *name, ssize_t name_len)
 Find the longest string match using a lexicographically sorted table. More...
 
static void const * table_sorted_value_by_str (void const *table, size_t table_len, size_t element_size, char const *name)
 Convert a string to a value using a lexicographically sorted table. More...
 
static void const * table_sorted_value_by_substr (void const *table, size_t table_len, size_t element_size, char const *name, ssize_t name_len)
 Convert a string matching part of name to an integer using a lexicographically sorted table. More...
 

Detailed Description

Lookup table functions.

Id
5d94d934fbd9666fabd2f3152c4c4e3a9ffa7829

Definition in file table.h.


Data Structure Documentation

◆ fr_table_elem_name_t

struct fr_table_elem_name_t

Definition at line 41 of file table.h.

Data Fields
size_t len Literal string length.
char const * str Literal string.

◆ fr_table_num_indexed_bit_pos_t

struct fr_table_num_indexed_bit_pos_t

An element in a table indexed by bit position.

i.e. if only the first bit is set in a bitfield, the entry at index 0 will be returned.

Definition at line 83 of file table.h.

+ Collaboration diagram for fr_table_num_indexed_bit_pos_t:
Data Fields
fr_table_elem_name_t name
uint64_t value

◆ fr_table_num_indexed_t

struct fr_table_num_indexed_t

An element in a table indexed by numeric value.

i.e. if the value is 0, we return the string mapped to the first element of the table.

Definition at line 92 of file table.h.

+ Collaboration diagram for fr_table_num_indexed_t:
Data Fields
fr_table_elem_name_t name
unsigned int value

◆ fr_table_num_ordered_t

struct fr_table_num_ordered_t

An element in an arbitrarily ordered array of name to num mappings.

Definition at line 57 of file table.h.

+ Collaboration diagram for fr_table_num_ordered_t:
Data Fields
fr_table_elem_name_t name
int value

◆ fr_table_num_sorted_t

struct fr_table_num_sorted_t

An element in a lexicographically sorted array of name to num mappings.

Definition at line 49 of file table.h.

+ Collaboration diagram for fr_table_num_sorted_t:
Data Fields
fr_table_elem_name_t name
int value

◆ fr_table_ptr_ordered_t

struct fr_table_ptr_ordered_t

An element in an arbitrarily ordered array of name to ptr mappings.

Definition at line 73 of file table.h.

+ Collaboration diagram for fr_table_ptr_ordered_t:
Data Fields
fr_table_elem_name_t name
void const * value

◆ fr_table_ptr_sorted_t

struct fr_table_ptr_sorted_t

An element in a lexicographically sorted array of name to ptr mappings.

Definition at line 65 of file table.h.

+ Collaboration diagram for fr_table_ptr_sorted_t:
Data Fields
fr_table_elem_name_t name
void const * value

Macro Definition Documentation

◆ ELEM_LEN

#define ELEM_LEN (   _offset)    (*((fr_table_elem_name_t const *)(_offset))).len

Definition at line 106 of file table.h.

◆ ELEM_STR

#define ELEM_STR (   _offset)    (*((fr_table_elem_name_t const *)(_offset))).str

Definition at line 105 of file table.h.

◆ fr_table_max_needle_len

#define fr_table_max_needle_len (   _table)
Value:
_Generic((_table), \
fr_table_num_sorted_t const * : fr_table_num_sorted_max_needle_len, \
fr_table_num_ordered_t const * : fr_table_num_ordered_max_needle_len, \
fr_table_num_sorted_t * : fr_table_num_sorted_max_needle_len, \
fr_table_num_ordered_t * : fr_table_num_ordered_max_needle_len, \
fr_table_ptr_sorted_t const * : fr_table_ptr_sorted_max_needle_len, \
fr_table_ptr_ordered_t const * : fr_table_ptr_ordered_max_needle_len, \
fr_table_ptr_sorted_t * : fr_table_ptr_sorted_max_needle_len, \
fr_table_ptr_ordered_t * : fr_table_ptr_ordered_max_needle_len, \
fr_table_num_indexed_bit_pos_t * : fr_table_num_indexed_bit_pos_max_needle_len, \
fr_table_num_indexed_bit_pos_t const * : fr_table_num_indexed_bit_pos_max_needle_len, \
fr_table_num_indexed_t * : fr_table_num_indexed_max_needle_len, \
fr_table_num_indexed_t const * : fr_table_num_indexed_max_needle_len \
)(_table, _table ## _len)
An element in a table indexed by bit position.
Definition: table.h:83
An element in a table indexed by numeric value.
Definition: table.h:92
An element in an arbitrarily ordered array of name to num mappings.
Definition: table.h:57
An element in a lexicographically sorted array of name to num mappings.
Definition: table.h:49
An element in an arbitrarily ordered array of name to ptr mappings.
Definition: table.h:73
An element in a lexicographically sorted array of name to ptr mappings.
Definition: table.h:65

Definition at line 803 of file table.h.

◆ fr_table_str_by_str_value

#define fr_table_str_by_str_value (   _table,
  _str_value,
  _def 
)
Value:
_Generic((_table), \
fr_table_ptr_sorted_t const * : _fr_table_ptr_by_str_value((fr_table_ptr_sorted_t const *)_table, _table ## _len, _str_value, _def), \
fr_table_ptr_ordered_t const * : _fr_table_ptr_by_str_value((fr_table_ptr_sorted_t const *)_table, _table ## _len, _str_value, _def), \
fr_table_ptr_sorted_t * : _fr_table_ptr_by_str_value((fr_table_ptr_sorted_t const *)_table, _table ## _len, _str_value, _def), \
fr_table_ptr_ordered_t * : _fr_table_ptr_by_str_value((fr_table_ptr_sorted_t const *)_table, _table ## _len, _str_value, _def))
char const * _fr_table_ptr_by_str_value(fr_table_ptr_sorted_t const *table, size_t table_len, char const *str_val, char const *def)
Brute force search a sorted or ordered ptr table, assuming the pointers are strings.
Definition: table.c:36

Brute force search a sorted or ordered ptr table, assuming the pointers are strings.

Parameters
[in]_tableto search in.
[in]_str_valueto compare against the ptr field.
[in]_defdefault value.

Definition at line 625 of file table.h.

◆ fr_table_str_by_value

#define fr_table_str_by_value (   _table,
  _number,
  _def 
)
Value:
_Generic((_table), \
)(_table, _table ## _len, _number, _def)
char const * fr_table_sorted_str_by_ptr(fr_table_ptr_sorted_t const *table, size_t table_len, void const *ptr, char const *def)
char const * fr_table_ordered_str_by_num(fr_table_num_ordered_t const *table, size_t table_len, int number, char const *def)
char const * fr_table_ordered_str_by_ptr(fr_table_ptr_ordered_t const *table, size_t table_len, void const *ptr, char const *def)
char const * fr_table_sorted_str_by_num(fr_table_num_sorted_t const *table, size_t table_len, int number, char const *def)
char const * fr_table_indexed_str_by_num(fr_table_num_indexed_t const *table, size_t table_len, unsigned int number, char const *def)
char const * fr_table_indexed_str_by_bit_field(fr_table_num_indexed_bit_pos_t const *table, size_t table_len, uint64_t number, char const *def)

Convert an integer to a string.

Parameters
[in]_tableto search in.
[in]_numberto resolve to a string.
[in]_defDefault string to return if there's no match.
Returns
  • _def if _number name matched no entries in the table.
  • the string value of the matching entry.

Definition at line 772 of file table.h.

◆ fr_table_value_by_longest_prefix

#define fr_table_value_by_longest_prefix (   _match_len,
  _table,
  _name,
  _name_len,
  _def 
)
Value:
_Generic((_table), \
)(_match_len, _table, _table ## _len, _name, _name_len, _def)
int fr_table_ordered_num_by_longest_prefix(size_t *match_len, fr_table_num_ordered_t const *table, size_t table_len, char const *name, ssize_t name_len, int def)
void * fr_table_ordered_ptr_by_longest_prefix(size_t *match_len, fr_table_ptr_ordered_t const *table, size_t table_len, char const *name, ssize_t name_len, void const *def)
void * fr_table_sorted_ptr_by_longest_prefix(size_t *match_len, fr_table_ptr_sorted_t const *table, size_t table_len, char const *name, ssize_t name_len, void const *def)
int fr_table_sorted_num_by_longest_prefix(size_t *match_len, fr_table_num_sorted_t const *table, size_t table_len, char const *name, ssize_t name_len, int def)

Find the longest string match using a sorted or ordered table.

Parameters
[out]_match_lenHow much of the input string matched.
[in]_tableto search in.
[in]_nameto resolve to a number.
[in]_name_lenThe amount of name to match.
[in]_defDefault value if no entry matched.
Returns
  • _def if name matched no entries in the table.
  • the value of the matching entry.

Definition at line 732 of file table.h.

◆ fr_table_value_by_str

#define fr_table_value_by_str (   _table,
  _name,
  _def 
)
Value:
_Generic((_table), \
)(_table, _table ## _len, _name, _def)
void * fr_table_ordered_ptr_by_str(fr_table_ptr_ordered_t const *table, size_t table_len, char const *name, void const *def)
void * fr_table_sorted_ptr_by_str(fr_table_ptr_sorted_t const *table, size_t table_len, char const *name, void const *def)
int fr_table_sorted_num_by_str(fr_table_num_sorted_t const *table, size_t table_len, char const *name, int def)
int fr_table_ordered_num_by_str(fr_table_num_ordered_t const *table, size_t table_len, char const *name, int def)

Convert a string to a value using a sorted or ordered table.

Parameters
[in]_tableto search in.
[in]_nameto resolve to a number.
[in]_defDefault value if no entry matched.
Returns
  • _def if name matched no entries in the table.
  • the numeric value of the matching entry.

Definition at line 653 of file table.h.

◆ fr_table_value_by_substr

#define fr_table_value_by_substr (   _table,
  _name,
  _name_len,
  _def 
)
Value:
_Generic((_table), \
)(_table, _table ## _len, _name, _name_len, _def)
int fr_table_ordered_num_by_substr(fr_table_num_ordered_t const *table, size_t table_len, char const *name, ssize_t name_len, int def)
int fr_table_sorted_num_by_substr(fr_table_num_sorted_t const *table, size_t table_len, char const *name, ssize_t name_len, int def)
void * fr_table_sorted_ptr_by_substr(fr_table_ptr_sorted_t const *table, size_t table_len, char const *name, ssize_t name_len, void const *def)
void * fr_table_ordered_ptr_by_substr(fr_table_ptr_ordered_t const *table, size_t table_len, char const *name, ssize_t name_len, void const *def)

Convert a partial string to a value using an ordered or sorted table.

Parameters
[in]_tableto search in.
[in]_nameto resolve to a number.
[in]_name_lenThe amount of name to match. If < 0, the length of the name in the table element will be used as the maximum match length.
[in]_defDefault value if no entry matched.
Returns
  • _def if name matched no entries in the table.
  • the numeric value of the matching entry.

Definition at line 693 of file table.h.

◆ NAME_NUMBER_NOT_FOUND

#define NAME_NUMBER_NOT_FOUND   INT32_MIN

Macro to use as dflt.

Definition at line 100 of file table.h.

◆ TABLE_IDX

#define TABLE_IDX (   _table,
  _idx,
  _element_size 
)    (((uint8_t const *)(_table)) + ((_idx) * (_element_size)))

Definition at line 104 of file table.h.

◆ TABLE_TYPE_NAME_FUNC

#define TABLE_TYPE_NAME_FUNC (   _func,
  _our_table_type,
  _our_name,
  _our_def_type,
  _our_return_type 
)
Value:
_our_return_type _our_name(_our_table_type table, size_t table_len, char const *name, _our_def_type def) \
{ \
_our_return_type ret; \
_our_table_type found; \
found = (_our_table_type)_func(table, table_len, sizeof(((_our_table_type)0)[0]), name); \
if (!found) { \
memcpy(&ret, &def, sizeof(ret)); \
return ret; \
} \
memcpy(&ret, &found->value, sizeof(ret)); \
return ret; \
}
static char const * name

Create a type-specific name-to-value function.

Parameters
[in]_funcUsed for resolving the name portion of an array element to a value. Should be one of the following:
  • table_sorted_value_by_str - for lexicographically sorted tables.
  • table_ordered_value_by_str - for arbitrarily ordered tables.
[in]_our_table_typeC type of the table elements.
[in]_our_namename of the search function to define.
[in]_our_def_typeC type of the default value.
[in]_our_return_typeC type of the return value, i.e. the value part of the element.

Definition at line 119 of file table.h.

◆ TABLE_TYPE_NAME_FUNC_RPTR

#define TABLE_TYPE_NAME_FUNC_RPTR (   _func,
  _our_table_type,
  _our_name,
  _our_def_type,
  _our_out_type 
)
Value:
bool _our_name(_our_out_type *out, _our_table_type table, size_t table_len, char const *name, _our_def_type def) \
{ \
_our_table_type found; \
found = (_our_table_type)_func(table, table_len, sizeof(((_our_table_type)0)[0]), name); \
if (!found) { \
*out = def; \
return false; \
} \
*out = &found->value; \
return true; \
}
static size_t char ** out
Definition: value.h:997

Create a type-specific name-to-value function.

Parameters
[in]_funcUsed for resolving the name portion of an array element to a value. Should be one of the following:
  • table_sorted_value_by_str - for lexicographically sorted tables.
  • table_ordered_value_by_str - for arbitrarily ordered tables.
[in]_our_table_typeC type of the table elements.
[in]_our_namename of the search function to define.
[in]_our_def_typeC type of the default value.
[in]_our_out_typeC type of the return/output value, i.e. the value part of the element.

Definition at line 144 of file table.h.

◆ TABLE_TYPE_NAME_LEN_FUNC

#define TABLE_TYPE_NAME_LEN_FUNC (   _func,
  _our_table_type,
  _our_name,
  _our_def_type,
  _our_return_type 
)
Value:
_our_return_type _our_name(_our_table_type table, size_t table_len, char const *name, ssize_t name_len, _our_def_type def) \
{ \
_our_return_type ret; \
_our_table_type found; \
found = (_our_table_type)_func(table, table_len, sizeof(((_our_table_type)0)[0]), name, name_len); \
if (!found) { \
memcpy(&ret, &def, sizeof(ret)); \
return ret; \
} \
memcpy(&ret, &found->value, sizeof(ret)); \
return ret; \
}
long int ssize_t
Definition: merged_model.c:24

Create a type-specific name-to-value function that can perform substring matching with a 'name_len' argument.

Parameters
[in]_funcUsed for resolving the name portion of an array element to a value. Should be one of the following:
  • table_sorted_value_by_substr - for lexicographically sorted tables with partial matching.
  • table_ordered_value_by_substr - for arbitrarily ordered tables. with partial matching.
[in]_our_table_typeC type of the table elements. Must contain two fields, an fr_table_elem_name_t called name and an arbitraryily typed field called value. A pointer to thi
[in]_our_namename of the search function to define.
[in]_our_def_typeC type of the default value.
[in]_our_return_typeC type of the return value, i.e. the value part of the element.

Definition at line 173 of file table.h.

◆ TABLE_TYPE_NAME_LEN_FUNC_RPTR

#define TABLE_TYPE_NAME_LEN_FUNC_RPTR (   _func,
  _our_table_type,
  _our_name,
  _our_def_type,
  _our_out_type 
)
Value:
bool _our_name(_our_out_type *out, _our_table_type table, size_t table_len, char const *name, ssize_t name_len, _our_def_type def) \
{ \
_our_table_type found; \
found = (_our_table_type)_func(table, table_len, sizeof(((_our_table_type)0)[0]), name, name_len); \
if (!found) { \
*out = def; \
return false; \
} \
*out = &found->value; \
return true; \
}

Create a type-specific name-to-value function that can perform substring matching with a 'name_len' argument.

Note
The functions created by this macro return true on a match, false on no match, and write a pointer to the value field of the table element to the 'out' argument.
Parameters
[in]_funcUsed for resolving the name portion of an array element to a value. Should be one of the following:
  • table_sorted_value_by_substr - for lexicographically sorted tables with partial matching.
  • table_ordered_value_by_substr - for arbitrarily ordered tables. with partial matching.
[in]_our_table_typeC type of the table elements. Must contain two fields, an fr_table_elem_name_t called name and an arbitraryily typed field called value. A pointer to thi
[in]_our_namename of the search function to define.
[in]_our_def_typeC type of the default value.
[in]_our_out_typeC type of the return/output value, i.e. the value part of the element.

Definition at line 206 of file table.h.

◆ TABLE_TYPE_NAME_MATCH_LEN_FUNC

#define TABLE_TYPE_NAME_MATCH_LEN_FUNC (   _func,
  _our_table_type,
  _our_name,
  _our_def_type,
  _our_return_type 
)
Value:
_our_return_type _our_name(size_t *match_len, _our_table_type table, size_t table_len, char const *name, ssize_t name_len, _our_def_type def) \
{ \
_our_return_type ret; \
_our_table_type found; \
found = (_our_table_type)_func(match_len, table, table_len, sizeof(((_our_table_type)0)[0]), name, name_len); \
if (!found) { \
memcpy(&ret, &def, sizeof(ret)); \
return ret; \
} \
memcpy(&ret, &found->value, sizeof(ret)); \
return ret; \
}

Create a type-specific name-to-value function that can perform substring matching with a 'name_len' argument, and passes back the length of the matched string.

Note
The functions created by this macro return the value field of the table element.
Parameters
[in]_funcUsed for resolving the name portion of an array element to a value. Should be one of the following:
  • table_sorted_value_by_longest_prefix - for lexicographically sorted tables with longest prefix match.
  • table_ordered_value_by_longest_prefix - for arbitrarily ordered tables with longest prefix match.
[in]_our_table_typeC type of the table elements.
[in]_our_namename of the search function to define.
[in]_our_def_typeC type of the default value.
[in]_our_return_typeC type of the return value, i.e. the value part of the element.

Definition at line 234 of file table.h.

◆ TABLE_TYPE_NAME_MATCH_LEN_FUNC_RPTR

#define TABLE_TYPE_NAME_MATCH_LEN_FUNC_RPTR (   _func,
  _our_table_type,
  _our_name,
  _our_def_type,
  _our_out_type 
)
Value:
bool _our_name(size_t *match_len, _our_out_type *out, _our_table_type table, size_t table_len, char const *name, ssize_t name_len, _our_def_type def) \
{ \
_our_table_type found; \
found = (_our_table_type)_func(match_len, table, table_len, sizeof(((_our_table_type)0)[0]), name, name_len); \
if (!found) { \
*out = def; \
return false; \
} \
*out = &found->value; \
return true; \
}

Create a type-specific name-to-value function that can perform substring matching with a 'name_len' argument, and passes back the length of the matched string.

Note
The functions created by this macro return true on a match, false on no match, and write a pointer to the value field of the table element to the 'out' argument.
Parameters
[in]_funcUsed for resolving the name portion of an array element to a value. Should be one of the following:
  • table_sorted_value_by_longest_prefix - for lexicographically sorted tables with longest prefix match.
  • table_ordered_value_by_longest_prefix - for arbitrarily ordered tables with longest prefix match.
[in]_our_table_typeC type of the table elements.
[in]_our_namename of the search function to define.
[in]_our_def_typeC type of the default value.
[in]_our_out_typeC type of the return/output value, i.e. the value part of the element.

Definition at line 264 of file table.h.

◆ TABLE_TYPE_NEEDLE_LEN_FUNC

#define TABLE_TYPE_NEEDLE_LEN_FUNC (   _our_table_type,
  _our_name 
)
Value:
static inline size_t _our_name(_our_table_type table, size_t table_len) \
{ \
size_t i, max = 0; \
for (i = 0; i < table_len; i++) if (table->name.len > max) max = table->name.len; \
return max; \
}

Definition at line 788 of file table.h.

◆ TABLE_TYPE_VALUE_FUNC

#define TABLE_TYPE_VALUE_FUNC (   _our_table_type,
  _our_name,
  _our_value_type 
)
Value:
char const *_our_name(_our_table_type table, size_t table_len, _our_value_type value, char const *def) \
{ \
size_t i; \
for (i = 0; i < table_len; i++) if (table[i].value == value) return table[i].name.str; \
return def; \
}
Test enumeration values.
Definition: dict_test.h:92

Create a type-specific value-to-name function.

Parameters
[in]_our_table_typeC type of the table elements.
[in]_our_namename of the search function to define.
[in]_our_return_typeC type of the value field of the table element.

Definition at line 283 of file table.h.

◆ TABLE_TYPE_VALUE_INDEX_BIT_FIELD_FUNC

#define TABLE_TYPE_VALUE_INDEX_BIT_FIELD_FUNC (   _our_table_type,
  _our_name,
  _our_value_type 
)
Value:
char const *_our_name(_our_table_type table, size_t table_len, _our_value_type value, char const *def) \
{ \
uint8_t idx = fr_high_bit_pos(value); \
if (idx >= table_len) return def; \
return table[idx].name.str; \
}
static uint8_t fr_high_bit_pos(uint64_t num)
Find the highest order high bit in an unsigned 64 bit integer.
Definition: math.h:36

Create a type-specific value-to-name function, which uses the highest bit set in the value as an index into the table.

Parameters
[in]_our_table_typeC type of the table elements.
[in]_our_namename of the search function to define.
[in]_our_return_typeC type of the value field of the table element.

Definition at line 297 of file table.h.

◆ TABLE_TYPE_VALUE_INDEX_FUNC

#define TABLE_TYPE_VALUE_INDEX_FUNC (   _our_table_type,
  _our_name,
  _our_value_type 
)
Value:
char const *_our_name(_our_table_type table, size_t table_len, _our_value_type value, char const *def) \
{ \
if (value >= table_len) return def; \
return table[value].name.str; \
}

Create a type-specific value-to-name function, which uses the value as an index into the table.

Parameters
[in]_our_table_typeC type of the table elements.
[in]_our_namename of the search function to define.
[in]_our_return_typeC type of the value field of the table element.

Definition at line 311 of file table.h.

Function Documentation

◆ _fr_table_ptr_by_str_value()

char const* _fr_table_ptr_by_str_value ( fr_table_ptr_sorted_t const *  table,
size_t  table_len,
char const *  str_val,
char const *  def 
)

Brute force search a sorted or ordered ptr table, assuming the pointers are strings.

Parameters
[in]tableto search in.
[in]table_lenNumber of elements in the table.
[in]str_valto compare against the ptr field.
[in]defdefault value.

Definition at line 36 of file table.c.

+ Here is the call graph for this function:

◆ fr_table_indexed_str_by_bit_field()

char const* fr_table_indexed_str_by_bit_field ( fr_table_num_indexed_bit_pos_t const *  table,
size_t  table_len,
uint64_t  number,
char const *  def 
)

◆ fr_table_indexed_str_by_num()

char const* fr_table_indexed_str_by_num ( fr_table_num_indexed_t const *  table,
size_t  table_len,
unsigned int  number,
char const *  def 
)

◆ fr_table_ordered_num_by_longest_prefix()

int fr_table_ordered_num_by_longest_prefix ( size_t match_len,
fr_table_num_ordered_t const *  table,
size_t  table_len,
char const *  name,
ssize_t  name_len,
int  def 
)

◆ fr_table_ordered_num_by_str()

int fr_table_ordered_num_by_str ( fr_table_num_ordered_t const *  table,
size_t  table_len,
char const *  name,
int  def 
)

◆ fr_table_ordered_num_by_substr()

int fr_table_ordered_num_by_substr ( fr_table_num_ordered_t const *  table,
size_t  table_len,
char const *  name,
ssize_t  name_len,
int  def 
)

◆ fr_table_ordered_ptr_by_longest_prefix()

void* fr_table_ordered_ptr_by_longest_prefix ( size_t match_len,
fr_table_ptr_ordered_t const *  table,
size_t  table_len,
char const *  name,
ssize_t  name_len,
void const *  def 
)

◆ fr_table_ordered_ptr_by_str()

void* fr_table_ordered_ptr_by_str ( fr_table_ptr_ordered_t const *  table,
size_t  table_len,
char const *  name,
void const *  def 
)

◆ fr_table_ordered_ptr_by_substr()

void* fr_table_ordered_ptr_by_substr ( fr_table_ptr_ordered_t const *  table,
size_t  table_len,
char const *  name,
ssize_t  name_len,
void const *  def 
)

◆ fr_table_ordered_str_by_num()

char const* fr_table_ordered_str_by_num ( fr_table_num_ordered_t const *  table,
size_t  table_len,
int  number,
char const *  def 
)
+ Here is the caller graph for this function:

◆ fr_table_ordered_str_by_ptr()

char const* fr_table_ordered_str_by_ptr ( fr_table_ptr_ordered_t const *  table,
size_t  table_len,
void const *  ptr,
char const *  def 
)

◆ fr_table_sorted_num_by_longest_prefix()

int fr_table_sorted_num_by_longest_prefix ( size_t match_len,
fr_table_num_sorted_t const *  table,
size_t  table_len,
char const *  name,
ssize_t  name_len,
int  def 
)

◆ fr_table_sorted_num_by_str()

int fr_table_sorted_num_by_str ( fr_table_num_sorted_t const *  table,
size_t  table_len,
char const *  name,
int  def 
)

◆ fr_table_sorted_num_by_substr()

int fr_table_sorted_num_by_substr ( fr_table_num_sorted_t const *  table,
size_t  table_len,
char const *  name,
ssize_t  name_len,
int  def 
)

◆ fr_table_sorted_ptr_by_longest_prefix()

void* fr_table_sorted_ptr_by_longest_prefix ( size_t match_len,
fr_table_ptr_sorted_t const *  table,
size_t  table_len,
char const *  name,
ssize_t  name_len,
void const *  def 
)

◆ fr_table_sorted_ptr_by_str()

void* fr_table_sorted_ptr_by_str ( fr_table_ptr_sorted_t const *  table,
size_t  table_len,
char const *  name,
void const *  def 
)

◆ fr_table_sorted_ptr_by_substr()

void* fr_table_sorted_ptr_by_substr ( fr_table_ptr_sorted_t const *  table,
size_t  table_len,
char const *  name,
ssize_t  name_len,
void const *  def 
)

◆ fr_table_sorted_str_by_num()

char const* fr_table_sorted_str_by_num ( fr_table_num_sorted_t const *  table,
size_t  table_len,
int  number,
char const *  def 
)

◆ fr_table_sorted_str_by_ptr()

char const* fr_table_sorted_str_by_ptr ( fr_table_ptr_sorted_t const *  table,
size_t  table_len,
void const *  ptr,
char const *  def 
)

◆ table_ordered_value_by_longest_prefix()

static void const* table_ordered_value_by_longest_prefix ( size_t match_len,
void const *  table,
size_t  table_len,
size_t  element_size,
char const *  name,
ssize_t  name_len 
)
static

Find the longest string match using an arbitrarily ordered table.

i.e. given name of "food", and table of f, foo, of - foo would be returned.

Parameters
[out]match_lenHow much of the input string matched.
[in]tableto search in.
[in]table_lenThe number of elements in the table.
[in]element_sizeSize of elements in the table.
[in]nameto locate.
[in]name_lenthe maximum amount of name that should be matched.
Returns
  • num value of matching entry.
  • def if no matching entries.

Definition at line 568 of file table.h.

◆ table_ordered_value_by_str()

static void const* table_ordered_value_by_str ( void const *  table,
size_t  table_len,
size_t  element_size,
char const *  name 
)
static

Convert a string to a value using an arbitrarily ordered table.

Parameters
[in]tableto search in.
[in]table_lenThe number of elements in the table.
[in]element_sizeSize of elements in the table.
[in]nameto resolve to a number.
Returns
  • value of matching entry.
  • NULL if no matching entries.

Definition at line 367 of file table.h.

+ Here is the call graph for this function:

◆ table_ordered_value_by_substr()

static void const* table_ordered_value_by_substr ( void const *  table,
size_t  table_len,
size_t  element_size,
char const *  name,
ssize_t  name_len 
)
static

Convert a string matching part of name to an integer using an arbitrarily ordered table.

Parameters
[in]tableto search in.
[in]table_lenThe number of elements in the table.
[in]element_sizeSize of elements in the table.
[in]nameto locate.
[in]name_lenthe maximum amount of name that should be matched. If < 0, the length of the name in the table offsetent will be used as the maximum match length.
Returns
  • value of matching entry.
  • NULL if no matching entries.

Definition at line 443 of file table.h.

+ Here is the call graph for this function:

◆ table_sorted_value_by_longest_prefix()

static void const* table_sorted_value_by_longest_prefix ( size_t match_len,
void const *  table,
size_t  table_len,
size_t  element_size,
char const *  name,
ssize_t  name_len 
)
static

Find the longest string match using a lexicographically sorted table.

Performs a binary search in the specified table, returning the longest offsetent which is a prefix of name.

i.e. given name of "food", and table of f, foo, of - foo would be returned.

Note
The table MUST be sorted lexicographically, else the result may be incorrect.
Parameters
[out]match_lenHow much of the input string matched.
[in]tableto search in.
[in]table_lenThe number of elements in the table.
[in]element_sizeSize of elements in the table.
[in]nameto locate.
[in]name_lenthe maximum amount of name that should be matched.
Returns
  • num value of matching entry.
  • NULL if no matching entries.

Definition at line 492 of file table.h.

+ Here is the call graph for this function:

◆ table_sorted_value_by_str()

static void const* table_sorted_value_by_str ( void const *  table,
size_t  table_len,
size_t  element_size,
char const *  name 
)
static

Convert a string to a value using a lexicographically sorted table.

Parameters
[in]tableto search in.
[in]table_lenThe number of elements in the table.
[in]element_sizeSize of elements in the table.
[in]nameto resolve to a value.
Returns
  • value of matching entry.
  • NULL if no matching entries.

Definition at line 328 of file table.h.

+ Here is the call graph for this function:

◆ table_sorted_value_by_substr()

static void const* table_sorted_value_by_substr ( void const *  table,
size_t  table_len,
size_t  element_size,
char const *  name,
ssize_t  name_len 
)
static

Convert a string matching part of name to an integer using a lexicographically sorted table.

Parameters
[in]tableto search in.
[in]table_lenThe number of elements in the table.
[in]element_sizeSize of elements in the table.
[in]nameto locate.
[in]name_lenthe maximum amount of name that should be matched. If < 0, the length of the name in the table offsetent will be used as the maximum match length.
Returns
  • value of matching entry.
  • NULL if no matching entries.

Definition at line 395 of file table.h.

+ Here is the call graph for this function: