add isl_pw_qpolynomial_foreach_lifted_piece
[isl.git] / include / isl_arg.h
blob2a84d3ebe03054b8f397cd44121e1a7dcf67254d
1 /*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8 */
10 #ifndef ISL_ARG_H
11 #define ISL_ARG_H
13 #include <stddef.h>
15 struct isl_arg_choice {
16 const char *name;
17 unsigned value;
20 enum isl_arg_type {
21 isl_arg_end,
22 isl_arg_choice,
23 isl_arg_bool,
24 isl_arg_child
27 struct isl_arg {
28 enum isl_arg_type type;
29 char short_name;
30 const char *long_name;
31 size_t offset;
32 union {
33 struct {
34 struct isl_arg_choice *choice;
35 unsigned default_value;
36 } choice;
37 struct {
38 unsigned default_value;
39 } b;
40 struct {
41 struct isl_arg *child;
42 size_t size;
43 } child;
44 } u;
47 #define ISL_ARG_CHOICE(st,f,s,l,c,d) { \
48 .type = isl_arg_choice, \
49 .short_name = s, \
50 .long_name = l, \
51 .offset = offsetof(st, f), \
52 .u = { .choice = { .choice = c, .default_value = d } } \
54 #define ISL_ARG_BOOL(st,f,s,l,d) { \
55 .type = isl_arg_bool, \
56 .short_name = s, \
57 .long_name = l, \
58 .offset = offsetof(st, f), \
59 .u = { .b = { .default_value = d } } \
61 #define ISL_ARG_CHILD(st,f,l,c) { \
62 .type = isl_arg_child, \
63 .long_name = l, \
64 .offset = offsetof(st, f), \
65 .u = { .child = { .child = c, .size = sizeof(*((st *)NULL)->f) } }\
67 #define ISL_ARG_END { isl_arg_end }
69 void isl_arg_set_defaults(struct isl_arg *arg, void *opt);
70 int isl_arg_parse(struct isl_arg *arg, int argc, char **argv, void *opt);
72 #define ISL_ARG_DECL(prefix,st,arg) \
73 st *prefix ## _new_with_defaults(); \
74 int prefix ## _parse(st *opt, int argc, char **argv);
76 #define ISL_ARG_DEF(prefix,st,arg) \
77 st *prefix ## _new_with_defaults() \
78 { \
79 st *opt = (st *)calloc(1, sizeof(st)); \
80 if (opt) \
81 isl_arg_set_defaults(arg, opt); \
82 return opt; \
83 } \
85 int prefix ## _parse(st *opt, int argc, char **argv) \
86 { \
87 return isl_arg_parse(arg, argc, argv, opt); \
90 #endif