Named enumerations.
More...
Go to the source code of this file.
Named enumerations.
Definition in file Enum.h.
◆ MakeEnumAlias
#define MakeEnumAlias |
( |
|
en, |
|
|
|
al |
|
) |
| |
Value: { \
.name = #en, \
.alias = #al, \
.value = en, \
}
Creates an EnumName alias for en
for use with valueof
.
- See also
- valueof(constEnumName *, const char *, int)
Definition at line 58 of file Enum.h.
◆ MakeEnumName
#define MakeEnumName |
( |
|
en | ) |
|
Value: { \
.name = #en, \
.alias = NULL, \
.value = en, \
}
Creates an EnumName for en
for use with valueof
.
- See also
- valueof(const EnumName *, const char *, int)
Definition at line 47 of file Enum.h.
◆ MakeEnumNames
#define MakeEnumNames |
( |
|
... | ) |
|
Value: { \
__VA_ARGS__, \
{ \
.name = NULL, \
.value = 0 \
} \
}
Creates a null-terminated array of EnumNames.
Definition at line 68 of file Enum.h.
◆ nameof()
Marshal value
, returning a String of OR
'ed EnumNames for the given enum value.
- Parameters
-
names | A null-terminated array of EnumNames. |
value | The enum value, which may be a bitwise OR of multiple enum values. |
- Returns
- A String of EnumNames matching value, or
NULL
.
Definition at line 31 of file Enum.c.
31 {
32
34 if (name->value == value) {
36 }
37 }
38
40
42 if (name->value) {
43 if ((name->value & value) == name->value) {
44 if (string == NULL) {
46 } else {
48 }
50 }
51 }
52 }
53
55}
MutableString * string(void)
Returns a new MutableString.
void appendCharacters(MutableString *self, const char *chars)
Appends the specified UTF-8 encoded C string.
String * stringWithCharacters(const char *chars)
Returns a new String by copying chars.
◆ valueof()
Parse string
, returning the corresponding enum value.
- Parameters
-
names | A null-terminated array of EnumNames. |
chars | A null-terminated C string. |
- Returns
- The
value
of the EnumName matching string
, or -1
.
Definition at line 57 of file Enum.c.
57 {
58
59 int value = 0;
60
61 const char *c = chars;
62 while (*c) {
63 const size_t size = strcspn(c, " |");
64 if (size) {
66 for (en = names; en->
name; en++) {
67 if (strncmp(en->
name, c, size) == 0) {
69 break;
70 }
71 if (en->
alias && strncmp(en->
alias, c, size) == 0) {
73 break;
74 }
75 }
76 if (en->
name == NULL) {
77 fprintf(stderr, "%s: Unknown character sequence: %s\n", __func__, c);
78 }
79 }
80 c += size;
81 c += strspn(c, " |");
82 }
83
84 return value;
85}