11#ifndef __VALUE_STRING_H__
12#define __VALUE_STRING_H__
16#include "ws_symbol_export.h"
41 #define foo_VALUE_STRING_LIST(XXX) \
42 XXX( FOO_A, 1, "aaa" ) \
43 XXX( FOO_B, 3, "bbb" )
46 VALUE_STRING_ENUM(foo);
50 VALUE_STRING_ARRAY(foo);
53 VALUE_STRING_ARRAY_GLOBAL_DEF(foo);
54 VALUE_STRING_ARRAY_GLOBAL_DCL(foo);
57 #define bar_VALUE_STRING_LIST(XXX) \
61 VALUE_STRING_ENUM2(bar);
62 VALUE_STRING_ARRAY2(bar);
67#define VALUE_STRING_ENUM( array_name) _VS_ENUM_XXX( array_name, _VS_ENUM_ENTRY)
68#define VALUE_STRING_ARRAY( array_name) _VS_ARRAY_SC_XXX(array_name, _VS_ARRAY_ENTRY, static)
69#define VALUE_STRING_ARRAY_GLOBAL_DEF( array_name) _VS_ARRAY_XXX(array_name, _VS_ARRAY_ENTRY)
70#define VALUE_STRING_ARRAY_GLOBAL_DCL( array_name) _VS_ARRAY_SC_TYPE_NAME(array_name, extern)
72#define VALUE_STRING_ENUM2( array_name) _VS_ENUM_XXX( array_name, _VS_ENUM_ENTRY2)
73#define VALUE_STRING_ARRAY2( array_name) _VS_ARRAY_SC_XXX(array_name, _VS_ARRAY_ENTRY2, static)
74#define VALUE_STRING_ARRAY2_GLOBAL_DEF( array_name) _VS_ARRAY_XXX(array_name, _VS_ARRAY_ENTRY2)
75#define VALUE_STRING_ARRAY2_GLOBAL_DCL( array_name) _VS_ARRAY_SC_TYPE_NAME(array_name, extern)
78#define _VS_ENUM_XXX(array_name, macro) \
80 array_name##_VALUE_STRING_LIST(macro) \
81 _##array_name##_ENUM_DUMMY = 0 \
84#define _VS_ARRAY_SC_XXX(array_name, macro, sc) \
85 _VS_ARRAY_SC_TYPE_NAME(array_name, sc) = { \
86 array_name##_VALUE_STRING_LIST(macro) \
90#define _VS_ARRAY_XXX(array_name, macro) \
91 _VS_ARRAY_TYPE_NAME(array_name) = { \
92 array_name##_VALUE_STRING_LIST(macro) \
96#define _VS_ARRAY_SC_TYPE_NAME(array_name, sc) sc const value_string array_name[]
97#define _VS_ARRAY_TYPE_NAME(array_name) const value_string array_name[]
99#define _VS_ENUM_ENTRY( name, value, string) name = value,
100#define _VS_ARRAY_ENTRY(name, value, string) { value, string },
102#define _VS_ENUM_ENTRY2( name, value) name = value,
103#define _VS_ARRAY_ENTRY2(name, value) { value, #name },
108val_to_str(
const uint32_t val,
const value_string *vs,
const char *fmt)
118val_to_str_const(
const uint32_t val,
const value_string *vs,
const char *unknown_str);
122try_val_to_str(
const uint32_t val,
const value_string *vs);
126try_val_to_str_idx(
const uint32_t val,
const value_string *vs,
int *idx);
142val64_to_str_const(
const uint64_t val,
const val64_string *vs,
const char *unknown_str);
146try_val64_to_str(
const uint64_t val,
const val64_string *vs);
150try_val64_to_str_idx(
const uint64_t val,
const val64_string *vs,
int *idx);
156str_to_val(
const char *val,
const value_string *vs,
const uint32_t err_val);
168 _value_string_match2_t _vs_match2;
169 uint32_t _vs_first_value;
170 unsigned _vs_num_entries;
173 const char *_vs_name;
176#define VALUE_STRING_EXT_VS_P(x) (x)->_vs_p
177#define VALUE_STRING_EXT_VS_NUM_ENTRIES(x) (x)->_vs_num_entries
178#define VALUE_STRING_EXT_VS_NAME(x) (x)->_vs_name
183#define VALUE_STRING_EXT_INIT(x) { _try_val_to_str_ext_init, 0, G_N_ELEMENTS(x)-1, x, #x }
187value_string_ext_new(
const value_string *vs,
unsigned vs_tot_num_entries,
const char *vs_name);
205val_to_str_ext_const(
const uint32_t val,
value_string_ext *vs,
const char *unknown_str);
221 _val64_string_match2_t _vs_match2;
222 uint64_t _vs_first_value;
223 unsigned _vs_num_entries;
226 const char *_vs_name;
229#define VAL64_STRING_EXT_VS_P(x) (x)->_vs_p
230#define VAL64_STRING_EXT_VS_NUM_ENTRIES(x) (x)->_vs_num_entries
231#define VAL64_STRING_EXT_VS_NAME(x) (x)->_vs_name
235value_str_value_compare(
const void* a,
const void* b);
240#define VAL64_STRING_EXT_INIT(x) { _try_val64_to_str_ext_init, 0, G_N_ELEMENTS(x)-1, x, #x }
244val64_string_ext_new(
const val64_string *vs,
unsigned vs_tot_num_entries,
const char *vs_name);
257val64_to_str_ext_const(
const uint64_t val,
val64_string_ext *vs,
const char *unknown_str);
265try_val64_to_str_idx_ext(
const uint64_t val,
val64_string_ext *vse,
int *idx);
285try_str_to_str_idx(
const char *val,
const string_string *vs,
int *idx);
302rval_to_str_const(
const uint32_t val,
const range_string *rs,
const char *unknown_str);
306try_rval_to_str(
const uint32_t val,
const range_string *rs);
310try_rval_to_str_idx(
const uint32_t val,
const range_string *rs,
int *idx);
314try_rval64_to_str(
const uint64_t val,
const range_string *rs);
318try_rval64_to_str_idx(
const uint64_t val,
const range_string *rs,
int *idx);
334 const uint8_t *value;
335 const size_t value_length;
346try_bytesval_to_str(
const uint8_t *val,
const size_t val_len,
const bytes_string *bs);
355try_bytesprefix_to_str(
const uint8_t *haystack,
const size_t haystack_len,
const bytes_string *bs);
Definition value_string.h:333
Definition value_string.h:289
Definition value_string.h:269
Definition value_string.h:322
Definition value_string.h:220
Definition value_string.h:130
Definition value_string.h:167
Definition value_string.h:27
Definition wmem_allocator.h:27