11#ifndef __VALUE_STRING_H__
12#define __VALUE_STRING_H__
16#include "ws_symbol_export.h"
39 #define foo_VALUE_STRING_LIST(XXX) \
40 XXX( FOO_A, 1, "aaa" ) \
41 XXX( FOO_B, 3, "bbb" )
44 VALUE_STRING_ENUM(foo);
48 VALUE_STRING_ARRAY(foo);
51 VALUE_STRING_ARRAY_GLOBAL_DEF(foo);
52 VALUE_STRING_ARRAY_GLOBAL_DCL(foo);
55 #define bar_VALUE_STRING_LIST(XXX) \
59 VALUE_STRING_ENUM2(bar);
60 VALUE_STRING_ARRAY2(bar);
65#define VALUE_STRING_ENUM( array_name) _VS_ENUM_XXX( array_name, _VS_ENUM_ENTRY)
66#define VALUE_STRING_ARRAY( array_name) _VS_ARRAY_SC_XXX(array_name, _VS_ARRAY_ENTRY, static)
67#define VALUE_STRING_ARRAY_GLOBAL_DEF( array_name) _VS_ARRAY_XXX(array_name, _VS_ARRAY_ENTRY)
68#define VALUE_STRING_ARRAY_GLOBAL_DCL( array_name) _VS_ARRAY_SC_TYPE_NAME(array_name, extern)
70#define VALUE_STRING_ENUM2( array_name) _VS_ENUM_XXX( array_name, _VS_ENUM_ENTRY2)
71#define VALUE_STRING_ARRAY2( array_name) _VS_ARRAY_SC_XXX(array_name, _VS_ARRAY_ENTRY2, static)
72#define VALUE_STRING_ARRAY2_GLOBAL_DEF( array_name) _VS_ARRAY_XXX(array_name, _VS_ARRAY_ENTRY2)
73#define VALUE_STRING_ARRAY2_GLOBAL_DCL( array_name) _VS_ARRAY_SC_TYPE_NAME(array_name, extern)
76#define _VS_ENUM_XXX(array_name, macro) \
78 array_name##_VALUE_STRING_LIST(macro) \
79 _##array_name##_ENUM_DUMMY = 0 \
82#define _VS_ARRAY_SC_XXX(array_name, macro, sc) \
83 _VS_ARRAY_SC_TYPE_NAME(array_name, sc) = { \
84 array_name##_VALUE_STRING_LIST(macro) \
88#define _VS_ARRAY_XXX(array_name, macro) \
89 _VS_ARRAY_TYPE_NAME(array_name) = { \
90 array_name##_VALUE_STRING_LIST(macro) \
94#define _VS_ARRAY_SC_TYPE_NAME(array_name, sc) sc const value_string array_name[]
95#define _VS_ARRAY_TYPE_NAME(array_name) const value_string array_name[]
97#define _VS_ENUM_ENTRY( name, value, string) name = value,
98#define _VS_ARRAY_ENTRY(name, value, string) { value, string },
100#define _VS_ENUM_ENTRY2( name, value) name = value,
101#define _VS_ARRAY_ENTRY2(name, value) { value, #name },
106val_to_str(
const uint32_t val,
const value_string *vs,
const char *fmt)
116val_to_str_const(
const uint32_t val,
const value_string *vs,
const char *unknown_str);
120try_val_to_str(
const uint32_t val,
const value_string *vs);
124try_val_to_str_idx(
const uint32_t val,
const value_string *vs,
int *idx);
128char_val_to_str(
char val,
const value_string *vs,
const char *msg);
139val64_to_str(
const uint64_t val,
const val64_string *vs,
const char *fmt)
144val64_to_str_const(
const uint64_t val,
const val64_string *vs,
const char *unknown_str);
148try_val64_to_str(
const uint64_t val,
const val64_string *vs);
152try_val64_to_str_idx(
const uint64_t val,
const val64_string *vs,
int *idx);
158str_to_val(
const char *val,
const value_string *vs,
const uint32_t err_val);
170 _value_string_match2_t _vs_match2;
171 uint32_t _vs_first_value;
172 unsigned _vs_num_entries;
175 const char *_vs_name;
178#define VALUE_STRING_EXT_VS_P(x) (x)->_vs_p
179#define VALUE_STRING_EXT_VS_NUM_ENTRIES(x) (x)->_vs_num_entries
180#define VALUE_STRING_EXT_VS_NAME(x) (x)->_vs_name
185#define VALUE_STRING_EXT_INIT(x) { _try_val_to_str_ext_init, 0, G_N_ELEMENTS(x)-1, x, #x }
189value_string_ext_new(
const value_string *vs,
unsigned vs_tot_num_entries,
const char *vs_name);
207val_to_str_ext_const(
const uint32_t val,
value_string_ext *vs,
const char *unknown_str);
223 _val64_string_match2_t _vs_match2;
224 uint64_t _vs_first_value;
225 unsigned _vs_num_entries;
228 const char *_vs_name;
231#define VAL64_STRING_EXT_VS_P(x) (x)->_vs_p
232#define VAL64_STRING_EXT_VS_NUM_ENTRIES(x) (x)->_vs_num_entries
233#define VAL64_STRING_EXT_VS_NAME(x) (x)->_vs_name
238#define VAL64_STRING_EXT_INIT(x) { _try_val64_to_str_ext_init, 0, G_N_ELEMENTS(x)-1, x, #x }
242val64_string_ext_new(
const val64_string *vs,
unsigned vs_tot_num_entries,
const char *vs_name);
260val64_to_str_ext_const(
const uint64_t val,
val64_string_ext *vs,
const char *unknown_str);
268try_val64_to_str_idx_ext(
const uint64_t val,
val64_string_ext *vse,
int *idx);
279str_to_str(
const char *val,
const string_string *vs,
const char *fmt)
288try_str_to_str_idx(
const char *val,
const string_string *vs,
int *idx);
300rval_to_str(
const uint32_t val,
const range_string *rs,
const char *fmt)
305rval_to_str_const(
const uint32_t val,
const range_string *rs,
const char *unknown_str);
309try_rval_to_str(
const uint32_t val,
const range_string *rs);
313try_rval_to_str_idx(
const uint32_t val,
const range_string *rs,
int *idx);
317try_rval64_to_str(
const uint64_t val,
const range_string *rs);
321try_rval64_to_str_idx(
const uint64_t val,
const range_string *rs,
int *idx);
326 const uint8_t *value;
327 const size_t value_length;
333bytesval_to_str(
const uint8_t *val,
const size_t val_len,
const bytes_string *bs,
const char *fmt)
338try_bytesval_to_str(
const uint8_t *val,
const size_t val_len,
const bytes_string *bs);
342bytesprefix_to_str(
const uint8_t *haystack,
const size_t haystack_len,
const bytes_string *bs,
const char *fmt)
347try_bytesprefix_to_str(
const uint8_t *haystack,
const size_t haystack_len,
const bytes_string *bs);
Definition value_string.h:325
Definition value_string.h:292
Definition value_string.h:272
Definition value_string.h:222
Definition value_string.h:132
Definition value_string.h:169
Definition value_string.h:25
Definition wmem_allocator.h:27