| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "efi-string.h" |
| 5 |
#include "macro.h" |
| 6 |
|
| 7 |
#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \ |
| 8 |
scope const char* name##_to_string(type i) { \ |
| 9 |
assert(i >= 0 && i < (type) ELEMENTSOF(name##_table)); \ |
| 10 |
return name##_table[i]; \ |
| 11 |
} |
| 12 |
|
| 13 |
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type, scope) \ |
| 14 |
scope type name##_from_string(const char *s) { \ |
| 15 |
if (!s) \ |
| 16 |
return (type) -1; \ |
| 17 |
for (size_t i = 0; i < ELEMENTSOF(name##_table); ++i) \ |
| 18 |
if (streq8(name##_table[i], s)) \ |
| 19 |
return (type) i; \ |
| 20 |
return (type) -1; \ |
| 21 |
} |
| 22 |
|
| 23 |
#define _DEFINE_STRING_TABLE_LOOKUP(name, type, scope) \ |
| 24 |
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type, scope) \ |
| 25 |
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type, scope) |
| 26 |
|
| 27 |
#define DEFINE_STRING_TABLE_LOOKUP(name, type) _DEFINE_STRING_TABLE_LOOKUP(name, type,) |
| 28 |
#define DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,) |
| 29 |
#define DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type,) |
| 30 |
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP(name, type) _DEFINE_STRING_TABLE_LOOKUP(name, type, static) |
| 31 |
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,static) |
| 32 |
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(name, type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type, static) |