Good day and welcome to the FIRM XMALLOC*() macros. These macros are provided for...
[libfirm] / ir / libcore / lc_opts_enum.h
1 /*
2   libcore: library for basic data structures and algorithms.
3   Copyright (C) 2005  IPD Goos, Universit"at Karlsruhe, Germany
4
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9
10   This library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public
16   License along with this library; if not, write to the Free Software
17   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19
20   Option management library. Enum extensions.
21 */
22
23 #ifndef _LC_OPTS_ENUM_T
24 #define _LC_OPTS_ENUM_T
25
26 #include <libcore/lc_opts.h>
27
28 #define _LC_OPT_DECL_ENUM(T, N)                 \
29 typedef struct {                                \
30         const char *name;                             \
31         T value;                                      \
32 } lc_opt_enum_ ## N ## _items_t;                \
33                                                 \
34 typedef struct {                                \
35         T* value;                                     \
36         const lc_opt_enum_ ## N ## _items_t *items;   \
37 } lc_opt_enum_ ## N ## _var_t;                  \
38 \
39 int lc_opt_enum_ ## N ## _cb(const char *name, lc_opt_type_t type, void *data, size_t len, ...); \
40 int lc_opt_enum_ ## N ## _dump(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t len); \
41 int lc_opt_enum_ ## N ## _dump_vals(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t len); \
42
43 #define _LC_OPT_ENT_ENUM(N, name, desc, var) \
44         _LC_OPT_ENT(name, desc, lc_opt_type_enum, var, 0, lc_opt_enum_ ## N ## _cb, lc_opt_enum_ ## N ## _dump, lc_opt_enum_ ## N ## _dump_vals)
45
46 _LC_OPT_DECL_ENUM(int, int)
47 _LC_OPT_DECL_ENUM(unsigned, mask)
48 _LC_OPT_DECL_ENUM(void *, ptr)
49 _LC_OPT_DECL_ENUM(const void *, const_ptr)
50
51 #define LC_OPT_ENT_ENUM_INT(name, desc, var)                            _LC_OPT_ENT_ENUM(int, name, desc, var)
52 #define LC_OPT_ENT_ENUM_MASK(name, desc, var)                           _LC_OPT_ENT_ENUM(mask, name, desc, var)
53 #define LC_OPT_ENT_ENUM_PTR(name, desc, var)                            _LC_OPT_ENT_ENUM(ptr, name, desc, var)
54 #define LC_OPT_ENT_ENUM_CONST_PTR(name, desc, var)                      _LC_OPT_ENT_ENUM(const_ptr, name, desc, var)
55
56 typedef struct {
57         const char *name;
58         int (*value)(void);
59 } lc_opt_enum_func_ptr_items_t;
60
61 typedef struct {
62         int (**value)(void);
63         const lc_opt_enum_func_ptr_items_t *items;
64 } lc_opt_enum_func_ptr_var_t;
65
66 #define LC_OPT_ENT_ENUM_FUNC_PTR(name, desc, var)       _LC_OPT_ENT_ENUM(func_ptr, name, desc, var)
67
68 int lc_opt_enum_func_ptr_cb(const char *name, lc_opt_type_t type, void *data, size_t len, ...);
69 int lc_opt_enum_func_ptr_dump(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t len);
70 int lc_opt_enum_func_ptr_dump_vals(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t len);
71
72 #endif