librfn
An ad-hoc utility library
enum.h
Go to the documentation of this file.
1 /*
2  * enum.h
3  *
4  * Part of librfn (a general utility library from redfelineninja.org.uk)
5  *
6  * Copyright (C) 2012-2014 Daniel Thompson <daniel@redfelineninja.org.uk>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published
10  * by the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  */
13 
14 #ifndef RF_ENUM_H_
15 #define RF_ENUM_H_
16 
43 typedef struct {
44  const char *s;
45  int e;
47 
54 #define RF_ENUMTABLE_INITIALIZER(...) { __VA_ARGS__, RF_ENUMTABLE_TERMINATOR }
55 
56 #define RF_ENUM_OUT_OF_RANGE -19830927
57 #define RF_ENUMTABLE_TERMINATOR { NULL, 0 }
58 
59 
60 const char *rf_enum2string(rf_enumtable_t *t, int e);
61 int rf_string2enum(rf_enumtable_t *t, const char *s);
62 
64 #endif // RF_ENUM_H_
const char * rf_enum2string(rf_enumtable_t *t, int e)
Definition: enum.c:18
int rf_string2enum(rf_enumtable_t *t, const char *s)
Definition: enum.c:28
Lookup table used for the conversions.
Definition: enum.h:43
const char * s
Definition: enum.h:44