2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2011 INRIA Saclay
5 * Use of this software is governed by the GNU LGPLv2.1 license
7 * Written by Sven Verdoolaege, K.U.Leuven, Departement
8 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
9 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
10 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
13 #define xCAT(A,B) A ## B
14 #define CAT(A,B) xCAT(A,B)
16 #define EL CAT(isl_,BASE)
17 #define xFN(TYPE,NAME) TYPE ## _ ## NAME
18 #define FN(TYPE,NAME) xFN(TYPE,NAME)
19 #define xLIST(EL) EL ## _list
20 #define LIST(EL) xLIST(EL)
22 isl_ctx
*FN(LIST(EL
),get_ctx
)(__isl_keep
LIST(EL
) *list
)
24 return list
? list
->ctx
: NULL
;
27 __isl_give
LIST(EL
) *FN(LIST(EL
),alloc
)(isl_ctx
*ctx
, int n
)
32 isl_die(ctx
, isl_error_invalid
,
33 "cannot create list of negative length",
35 list
= isl_alloc(ctx
, LIST(EL
),
36 sizeof(LIST(EL
)) + (n
- 1) * sizeof(struct EL
*));
48 __isl_give
LIST(EL
) *FN(LIST(EL
),copy
)(__isl_keep
LIST(EL
) *list
)
57 __isl_give
LIST(EL
) *FN(LIST(EL
),dup
)(__isl_keep
LIST(EL
) *list
)
65 dup
= FN(LIST(EL
),alloc
)(FN(LIST(EL
),get_ctx
)(list
), list
->n
);
68 for (i
= 0; i
< list
->n
; ++i
)
69 dup
= FN(LIST(EL
),add
)(dup
, FN(EL
,copy
)(list
->p
[i
]));
73 __isl_give
LIST(EL
) *FN(LIST(EL
),add
)(__isl_take
LIST(EL
) *list
,
74 __isl_take
struct EL
*el
)
78 isl_assert(list
->ctx
, list
->n
< list
->size
, goto error
);
79 list
->p
[list
->n
] = el
;
84 FN(LIST(EL
),free
)(list
);
88 void FN(LIST(EL
),free
)(__isl_take
LIST(EL
) *list
)
98 isl_ctx_deref(list
->ctx
);
99 for (i
= 0; i
< list
->n
; ++i
)
100 FN(EL
,free
)(list
->p
[i
]);
104 int FN(FN(LIST(EL
),n
),BASE
)(__isl_keep
LIST(EL
) *list
)
106 return list
? list
->n
: 0;
109 __isl_give EL
*FN(FN(LIST(EL
),get
),BASE
)(__isl_keep
LIST(EL
) *list
, int index
)
113 if (index
< 0 || index
>= list
->n
)
114 isl_die(list
->ctx
, isl_error_invalid
,
115 "index out of bounds", return NULL
);
116 return FN(EL
,copy
)(list
->p
[index
]);
119 int FN(LIST(EL
),foreach
)(__isl_keep
LIST(EL
) *list
,
120 int (*fn
)(__isl_take EL
*el
, void *user
), void *user
)
127 for (i
= 0; i
< list
->n
; ++i
) {
128 EL
*el
= FN(EL
,copy(list
->p
[i
]));
131 if (fn(el
, user
) < 0)
138 __isl_give isl_printer
*CAT(isl_printer_print_
,LIST(BASE
))(
139 __isl_take isl_printer
*p
, __isl_keep
LIST(EL
) *list
)
145 p
= isl_printer_print_str(p
, "(");
146 for (i
= 0; i
< list
->n
; ++i
) {
148 p
= isl_printer_print_str(p
, ",");
149 p
= CAT(isl_printer_print_
,BASE
)(p
, list
->p
[i
]);
151 p
= isl_printer_print_str(p
, ")");
158 void FN(LIST(EL
),dump
)(__isl_keep
LIST(EL
) *list
)
160 isl_printer
*printer
;
165 printer
= isl_printer_to_file(FN(LIST(EL
),get_ctx
)(list
), stderr
);
166 printer
= CAT(isl_printer_print_
,LIST(BASE
))(printer
, list
);
167 printer
= isl_printer_end_line(printer
);
169 isl_printer_free(printer
);