| Wireshark 4.7.3 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
params.h
Go to the documentation of this file.
1
11#pragma once
12
16 typedef struct {
17 const char* name;
18 const char* description;
19 int value;
20} enum_val_t;
21
22/* ----- Public enum_val_t "Helper" macros ----- */
23/*
24 * Reuse the macro format of the list of value strings (that is used by value_string.h
25 * for generating definitions of enum and/or value strings array) to generating
26 * enum_val_t array. For example, there is a macro of a value strings list like:
27 *
28 * #define foo_VALUE_STRING_LIST(XXX) \
29 * XXX( FOO_A, 1, "aaa" ) \
30 * XXX( FOO_B, 3, "bbb" )
31 *
32 * The code VS_LIST_TO_ENUM_VAL_T_ARRAY_STATIC(foo, foo_ev); will define a static enum_val_t array:
33 *
34 * static const enum_val_t foo_ev[] = {
35 * { "aaa", "aaa", 1 },
36 * { "bbb", "bbb", 3 },
37 * { NULL, NULL, 0 }
38 * };
39 *
40 * The code VS_LIST_TO_ENUM_VAL_T_ARRAY_GLOBAL_DEF(foo, foo_ev); will define a global enum_val_t array:
41 *
42 * const enum_val_t foo_ev[] = {
43 * { "aaa", "aaa", 1 },
44 * { "bbb", "bbb", 3 },
45 * { NULL, NULL, 0 }
46 * };
47 *
48 * The code VS_LIST_TO_ENUM_VAL_T_ARRAY_GLOBAL_DCL(foo_ev); will declare a extern enum_val_t array:
49 *
50 * extern const enum_val_t foo_ev[];
51 */
52#define VS_LIST_TO_ENUM_VAL_T_ARRAY_STATIC( array_name, new_array_name) static _EV_ARRAY_XXX(array_name, new_array_name, _VALUE_STRING_LIST, _EV_ARRAY_ENTRY_FROM_VS)
53#define VS_LIST_TO_ENUM_VAL_T_ARRAY_GLOBAL_DEF(array_name, new_array_name) _EV_ARRAY_XXX(array_name, new_array_name, _VALUE_STRING_LIST, _EV_ARRAY_ENTRY_FROM_VS)
54#define VS_LIST_TO_ENUM_VAL_T_ARRAY_GLOBAL_DCL(new_array_name) extern const enum_val_t new_array_name[]
55
56/*
57 * Provide the capability to define a list of enum_val_t(s) once and
58 * then to expand the list as an enum and/or as a enum_val_t array.:
59 *
60 * #define foo2_ENUM_VAL_T_LIST(XXX) \
61 * XXX( FOO_A, 1, "aaa", "The description of aaa" ) \
62 * XXX( FOO_B, 3, "bbb", "The description of bbb" )
63 *
64 * The code ENUM_VAL_T_ENUM(foo2); will define an enumeration type:
65 *
66 * enum {
67 * FOO_A = 1,
68 * FOO_B = 3,
69 * _foo_ENUM_DUMMY = 0
70 * };
71 * Note, you can use code "typedef ENUM_VAL_T_ENUM(foo2) enum_foo_t;" to define a
72 * named enumeration.
73 *
74 * The code ENUM_VAL_T_ARRAY_STATIC(foo2); will define a static enum_val_t array:
75 *
76 * static const enum_val_t foo2[] = {
77 * { "aaa", "The description of aaa", 1 },
78 * { "bbb", "The description of bbb", 3 },
79 * { NULL, NULL, 0 }
80 * };
81 *
82 * The code ENUM_VAL_T_ARRAY_GLOBAL_DEF(foo2); will define a global enum_val_t array:
83 *
84 * const enum_val_t foo2[] = {
85 * { "aaa", "The description of aaa", 1 },
86 * { "bbb", "The description of bbb", 3 },
87 * { NULL, NULL, 0 }
88 * };
89 *
90 * The code VS_LIST_TO_ENUM_VAL_T_ARRAY_GLOBAL_DCL(foo2); will declare a extern enum_val_t array:
91 *
92 * extern const enum_val_t foo2[];
93 */
94#define ENUM_VAL_T_ENUM(array_name) _EV_ENUM_XXX(array_name, _ENUM_VAL_T_LIST, _EV_ENUM_ENTRY)
95#define ENUM_VAL_T_ARRAY_STATIC( array_name) static _EV_ARRAY_XXX(array_name, array_name, _ENUM_VAL_T_LIST, _EV_ARRAY_ENTRY)
96#define ENUM_VAL_T_ARRAY_GLOBAL_DEF(array_name) _EV_ARRAY_XXX(array_name, array_name, _ENUM_VAL_T_LIST, _EV_ARRAY_ENTRY)
97#define ENUM_VAL_T_ARRAY_GLOBAL_DCL(array_name) extern const enum_val_t array_name[]
98
99/*
100 * Reuse the format of enum_val list to create value_string array:
101 *
102 * The code ENUM_VAL_T_TO_VS_ARRAY_STATIC(foo2, foo2_vs); will define a static value_string array from an enum_val list:
103 *
104 * static const value_string foo2_vs[] = {
105 * { 1, "aaa" },
106 * { 3, "bbb" },
107 * { 0, NULL }
108 * };
109 *
110 * The code ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DEF(foo2, foo2_vs); will define a global value_string array from an enum_val list:
111 *
112 * const value_string foo2_vs[] = {
113 * { 1, "aaa" },
114 * { 3, "bbb" },
115 * { 0, NULL }
116 * };
117 *
118 * The code ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DCL(foo2_vs); will declare a extern value_string array from an enum_val list:
119 *
120 * extern const value_string foo2_vs[];
121 *
122 * The macros ENUM_VAL_T_TO_VS_ARRAY_STATIC2, ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DEF2 and ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DCL2
123 * are similar to ENUM_VAL_T_TO_VS_ARRAY_STATIC, ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DEF and ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DCL
124 * except that ENUM_VAL_T_TO_VS_ARRAY_XXX(s) uses the 'name' field of enum_val list as the 'string' field of value_string,
125 * and ENUM_VAL_T_TO_VS_ARRAY_XXX2(s) uses the 'enum_name' field.
126 *
127 * Similarly, The macros ENUM_VAL_T_TO_VS_ARRAY_XXX3(s) uses the 'description' field of enum_val list as the 'string'
128 * field of value_string.
129 */
130#define ENUM_VAL_T_TO_VS_ARRAY_STATIC( array_name, new_array_name) static _EV_TO_VS_ARRAY_XXX(array_name, new_array_name, _ENUM_VAL_T_LIST, _VS_ARRAY_ENTRY_FROM_EV)
131#define ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DEF(array_name, new_array_name) _EV_TO_VS_ARRAY_XXX(array_name, new_array_name, _ENUM_VAL_T_LIST, _VS_ARRAY_ENTRY_FROM_EV)
132#define ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DCL(new_array_name) extern const value_string new_array_name[]
133
134#define ENUM_VAL_T_TO_VS_ARRAY_STATIC2( array_name, new_array_name) static _EV_TO_VS_ARRAY_XXX(array_name, new_array_name, _ENUM_VAL_T_LIST, _VS_ARRAY_ENTRY_FROM_EV2)
135#define ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DEF2(array_name, new_array_name) _EV_TO_VS_ARRAY_XXX(array_name, new_array_name, _ENUM_VAL_T_LIST, _VS_ARRAY_ENTRY_FROM_EV2)
136#define ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DCL2(new_array_name) extern const value_string new_array_name[]
137
138#define ENUM_VAL_T_TO_VS_ARRAY_STATIC3( array_name, new_array_name) static _EV_TO_VS_ARRAY_XXX(array_name, new_array_name, _ENUM_VAL_T_LIST, _VS_ARRAY_ENTRY_FROM_EV3)
139#define ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DEF3(array_name, new_array_name) _EV_TO_VS_ARRAY_XXX(array_name, new_array_name, _ENUM_VAL_T_LIST, _VS_ARRAY_ENTRY_FROM_EV3)
140#define ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DCL3(new_array_name) extern const value_string new_array_name[]
141
142/* -- Private macros -- */
143#define _EV_ARRAY_XXX(array_name, new_array_name, array_suffix, macro) \
144 const enum_val_t new_array_name[] = { \
145 array_name##array_suffix(macro) \
146 { NULL, NULL, 0 } \
147}
148
149#define _EV_ARRAY_ENTRY(enum_name, value, name, description) { name, description, value },
150#define _EV_ARRAY_ENTRY_FROM_VS(enum_name, value, string) { string, string, value },
151
152#define _EV_ENUM_XXX(array_name, array_suffix, macro) \
153 enum { \
154 array_name##array_suffix(macro) \
155 _##array_name##_ENUM_DUMMY = 0 \
156}
157
158#define _EV_ENUM_ENTRY(enum_name, value, name, description) enum_name = value,
159
160#define _EV_TO_VS_ARRAY_XXX(array_name, new_array_name, array_suffix, macro) \
161 const value_string new_array_name[] = { \
162 array_name##array_suffix(macro) \
163 { 0, NULL } \
164}
165#define _VS_ARRAY_ENTRY_FROM_EV(enum_name, value, name, description) { value, name }
166#define _VS_ARRAY_ENTRY_FROM_EV2(enum_name, value, name, description) { value, #enum_name }
167#define _VS_ARRAY_ENTRY_FROM_EV3(enum_name, value, name, description) { value, description }
enum_val_t
Defines a single named value within an enumerated preference or option type.
Definition params.h:16
enum_val_t::description
const char * description
Definition params.h:18
enum_val_t::value
int value
Definition params.h:19
enum_val_t::name
const char * name
Definition params.h:17