Move the CASE_RETURN_STRING macro to util-macros.h

No point redefining this everywhere

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-09-24 09:03:27 +10:00
parent a89309558a
commit ad87b67906
3 changed files with 8 additions and 4 deletions

View file

@ -131,7 +131,6 @@ ei_dispatch(struct ei *ei)
static const char *
ei_event_type_to_string(enum ei_event_type type)
{
#define CASE_RETURN_STRING(_t) case _t: return #_t
switch(type) {
CASE_RETURN_STRING(EI_EVENT_CONNECT);
CASE_RETURN_STRING(EI_EVENT_DISCONNECT);
@ -140,7 +139,6 @@ ei_event_type_to_string(enum ei_event_type type)
CASE_RETURN_STRING(EI_EVENT_DEVICE_SUSPENDED);
CASE_RETURN_STRING(EI_EVENT_DEVICE_RESUMED);
}
#undef CASE_RETURN_STRING
assert(!"Unhandled event type");
}

View file

@ -100,7 +100,6 @@ eis_dispatch(struct eis *eis)
static const char *
eis_event_type_to_string(enum eis_event_type type)
{
#define CASE_RETURN_STRING(_t) case _t: return #_t
switch(type) {
CASE_RETURN_STRING(EIS_EVENT_CLIENT_CONNECT);
CASE_RETURN_STRING(EIS_EVENT_CLIENT_DISCONNECT);
@ -118,7 +117,6 @@ eis_event_type_to_string(enum eis_event_type type)
CASE_RETURN_STRING(EIS_EVENT_TOUCH_UP);
CASE_RETURN_STRING(EIS_EVENT_TOUCH_MOTION);
}
#undef CASE_RETURN_STRING
assert(!"Unhandled event type");
}

View file

@ -32,6 +32,14 @@
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
#define ARRAY_FOR_EACH(_arr, _elem) \
for (size_t _i = 0; _i < ARRAY_LENGTH(_arr) && (_elem = &_arr[_i]); _i++)
/**
* Use to stringify a switch case value:
* switch (foo) {
* CASE_RETURN_STRING(ENUMVALUE);
* CASE_RETURN_STRING(OTHERVALUE);
* }
*/
#define CASE_RETURN_STRING(_x) case _x: return #_x
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b))