1use super::{BasicSet, Context, Error, LibISLError};
5use libc::uintptr_t;
6use std::ffi::CStr;
7use std::os::raw::c_char;
8
9pub struct BasicSetList {
11 pub ptr: uintptr_t,
12 pub should_free_on_drop: bool,
13}
14
15extern "C" {
16
17 fn isl_basic_set_list_add(list: uintptr_t, el: uintptr_t) -> uintptr_t;
18
19 fn isl_basic_set_list_alloc(ctx: uintptr_t, n: i32) -> uintptr_t;
20
21 fn isl_basic_set_list_clear(list: uintptr_t) -> uintptr_t;
22
23 fn isl_basic_set_list_coefficients(list: uintptr_t) -> uintptr_t;
24
25 fn isl_basic_set_list_concat(list1: uintptr_t, list2: uintptr_t) -> uintptr_t;
26
27 fn isl_basic_set_list_copy(list: uintptr_t) -> uintptr_t;
28
29 fn isl_basic_set_list_drop(list: uintptr_t, first: u32, n: u32) -> uintptr_t;
30
31 fn isl_basic_set_list_dump(list: uintptr_t) -> ();
32
33 fn isl_basic_set_list_free(list: uintptr_t) -> uintptr_t;
34
35 fn isl_basic_set_list_from_basic_set(el: uintptr_t) -> uintptr_t;
36
37 fn isl_basic_set_list_get_at(list: uintptr_t, index: i32) -> uintptr_t;
38
39 fn isl_basic_set_list_get_basic_set(list: uintptr_t, index: i32) -> uintptr_t;
40
41 fn isl_basic_set_list_get_ctx(list: uintptr_t) -> uintptr_t;
42
43 fn isl_basic_set_list_insert(list: uintptr_t, pos: u32, el: uintptr_t) -> uintptr_t;
44
45 fn isl_basic_set_list_intersect(list: uintptr_t) -> uintptr_t;
46
47 fn isl_basic_set_list_n_basic_set(list: uintptr_t) -> i32;
48
49 fn isl_basic_set_list_reverse(list: uintptr_t) -> uintptr_t;
50
51 fn isl_basic_set_list_set_at(list: uintptr_t, index: i32, el: uintptr_t) -> uintptr_t;
52
53 fn isl_basic_set_list_set_basic_set(list: uintptr_t, index: i32, el: uintptr_t) -> uintptr_t;
54
55 fn isl_basic_set_list_size(list: uintptr_t) -> i32;
56
57 fn isl_basic_set_list_swap(list: uintptr_t, pos1: u32, pos2: u32) -> uintptr_t;
58
59 fn isl_basic_set_list_to_str(list: uintptr_t) -> *const c_char;
60
61}
62
63impl BasicSetList {
64 pub fn add(self, el: BasicSet) -> Result<BasicSetList, LibISLError> {
66 let list = self;
67 let isl_rs_ctx = list.get_ctx();
68 let mut list = list;
69 list.do_not_free_on_drop();
70 let list = list.ptr;
71 let mut el = el;
72 el.do_not_free_on_drop();
73 let el = el.ptr;
74 let isl_rs_result = unsafe { isl_basic_set_list_add(list, el) };
75 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
76 should_free_on_drop: true };
77 let err = isl_rs_ctx.last_error();
78 if err != Error::None_ {
79 let err_msg = isl_rs_ctx.last_error_msg();
80 isl_rs_ctx.reset_error();
81 return Err(LibISLError::new(err, err_msg));
82 }
83 Ok(isl_rs_result)
84 }
85
86 pub fn alloc(ctx: &Context, n: i32) -> Result<BasicSetList, LibISLError> {
88 let isl_rs_ctx = Context { ptr: ctx.ptr,
89 should_free_on_drop: false };
90 let ctx = ctx.ptr;
91 let isl_rs_result = unsafe { isl_basic_set_list_alloc(ctx, n) };
92 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
93 should_free_on_drop: true };
94 let err = isl_rs_ctx.last_error();
95 if err != Error::None_ {
96 let err_msg = isl_rs_ctx.last_error_msg();
97 isl_rs_ctx.reset_error();
98 return Err(LibISLError::new(err, err_msg));
99 }
100 Ok(isl_rs_result)
101 }
102
103 pub fn clear(self) -> Result<BasicSetList, LibISLError> {
105 let list = self;
106 let isl_rs_ctx = list.get_ctx();
107 let mut list = list;
108 list.do_not_free_on_drop();
109 let list = list.ptr;
110 let isl_rs_result = unsafe { isl_basic_set_list_clear(list) };
111 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
112 should_free_on_drop: true };
113 let err = isl_rs_ctx.last_error();
114 if err != Error::None_ {
115 let err_msg = isl_rs_ctx.last_error_msg();
116 isl_rs_ctx.reset_error();
117 return Err(LibISLError::new(err, err_msg));
118 }
119 Ok(isl_rs_result)
120 }
121
122 pub fn coefficients(self) -> Result<BasicSetList, LibISLError> {
124 let list = self;
125 let isl_rs_ctx = list.get_ctx();
126 let mut list = list;
127 list.do_not_free_on_drop();
128 let list = list.ptr;
129 let isl_rs_result = unsafe { isl_basic_set_list_coefficients(list) };
130 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
131 should_free_on_drop: true };
132 let err = isl_rs_ctx.last_error();
133 if err != Error::None_ {
134 let err_msg = isl_rs_ctx.last_error_msg();
135 isl_rs_ctx.reset_error();
136 return Err(LibISLError::new(err, err_msg));
137 }
138 Ok(isl_rs_result)
139 }
140
141 pub fn concat(self, list2: BasicSetList) -> Result<BasicSetList, LibISLError> {
143 let list1 = self;
144 let isl_rs_ctx = list1.get_ctx();
145 let mut list1 = list1;
146 list1.do_not_free_on_drop();
147 let list1 = list1.ptr;
148 let mut list2 = list2;
149 list2.do_not_free_on_drop();
150 let list2 = list2.ptr;
151 let isl_rs_result = unsafe { isl_basic_set_list_concat(list1, list2) };
152 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
153 should_free_on_drop: true };
154 let err = isl_rs_ctx.last_error();
155 if err != Error::None_ {
156 let err_msg = isl_rs_ctx.last_error_msg();
157 isl_rs_ctx.reset_error();
158 return Err(LibISLError::new(err, err_msg));
159 }
160 Ok(isl_rs_result)
161 }
162
163 pub fn copy(&self) -> Result<BasicSetList, LibISLError> {
165 let list = self;
166 let isl_rs_ctx = list.get_ctx();
167 let list = list.ptr;
168 let isl_rs_result = unsafe { isl_basic_set_list_copy(list) };
169 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
170 should_free_on_drop: true };
171 let err = isl_rs_ctx.last_error();
172 if err != Error::None_ {
173 let err_msg = isl_rs_ctx.last_error_msg();
174 isl_rs_ctx.reset_error();
175 return Err(LibISLError::new(err, err_msg));
176 }
177 Ok(isl_rs_result)
178 }
179
180 pub fn drop(self, first: u32, n: u32) -> Result<BasicSetList, LibISLError> {
182 let list = self;
183 let isl_rs_ctx = list.get_ctx();
184 let mut list = list;
185 list.do_not_free_on_drop();
186 let list = list.ptr;
187 let isl_rs_result = unsafe { isl_basic_set_list_drop(list, first, n) };
188 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
189 should_free_on_drop: true };
190 let err = isl_rs_ctx.last_error();
191 if err != Error::None_ {
192 let err_msg = isl_rs_ctx.last_error_msg();
193 isl_rs_ctx.reset_error();
194 return Err(LibISLError::new(err, err_msg));
195 }
196 Ok(isl_rs_result)
197 }
198
199 pub fn dump(&self) -> Result<(), LibISLError> {
201 let list = self;
202 let isl_rs_ctx = list.get_ctx();
203 let list = list.ptr;
204 let isl_rs_result = unsafe { isl_basic_set_list_dump(list) };
205 let err = isl_rs_ctx.last_error();
206 if err != Error::None_ {
207 let err_msg = isl_rs_ctx.last_error_msg();
208 isl_rs_ctx.reset_error();
209 return Err(LibISLError::new(err, err_msg));
210 }
211 Ok(isl_rs_result)
212 }
213
214 pub fn free(self) -> Result<BasicSetList, LibISLError> {
216 let list = self;
217 let isl_rs_ctx = list.get_ctx();
218 let mut list = list;
219 list.do_not_free_on_drop();
220 let list = list.ptr;
221 let isl_rs_result = unsafe { isl_basic_set_list_free(list) };
222 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
223 should_free_on_drop: true };
224 let err = isl_rs_ctx.last_error();
225 if err != Error::None_ {
226 let err_msg = isl_rs_ctx.last_error_msg();
227 isl_rs_ctx.reset_error();
228 return Err(LibISLError::new(err, err_msg));
229 }
230 Ok(isl_rs_result)
231 }
232
233 pub fn from_basic_set(el: BasicSet) -> Result<BasicSetList, LibISLError> {
235 let isl_rs_ctx = el.get_ctx();
236 let mut el = el;
237 el.do_not_free_on_drop();
238 let el = el.ptr;
239 let isl_rs_result = unsafe { isl_basic_set_list_from_basic_set(el) };
240 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
241 should_free_on_drop: true };
242 let err = isl_rs_ctx.last_error();
243 if err != Error::None_ {
244 let err_msg = isl_rs_ctx.last_error_msg();
245 isl_rs_ctx.reset_error();
246 return Err(LibISLError::new(err, err_msg));
247 }
248 Ok(isl_rs_result)
249 }
250
251 pub fn get_at(&self, index: i32) -> Result<BasicSet, LibISLError> {
253 let list = self;
254 let isl_rs_ctx = list.get_ctx();
255 let list = list.ptr;
256 let isl_rs_result = unsafe { isl_basic_set_list_get_at(list, index) };
257 let isl_rs_result = BasicSet { ptr: isl_rs_result,
258 should_free_on_drop: true };
259 let err = isl_rs_ctx.last_error();
260 if err != Error::None_ {
261 let err_msg = isl_rs_ctx.last_error_msg();
262 isl_rs_ctx.reset_error();
263 return Err(LibISLError::new(err, err_msg));
264 }
265 Ok(isl_rs_result)
266 }
267
268 pub fn get_basic_set(&self, index: i32) -> Result<BasicSet, LibISLError> {
270 let list = self;
271 let isl_rs_ctx = list.get_ctx();
272 let list = list.ptr;
273 let isl_rs_result = unsafe { isl_basic_set_list_get_basic_set(list, index) };
274 let isl_rs_result = BasicSet { ptr: isl_rs_result,
275 should_free_on_drop: true };
276 let err = isl_rs_ctx.last_error();
277 if err != Error::None_ {
278 let err_msg = isl_rs_ctx.last_error_msg();
279 isl_rs_ctx.reset_error();
280 return Err(LibISLError::new(err, err_msg));
281 }
282 Ok(isl_rs_result)
283 }
284
285 pub fn get_ctx(&self) -> Context {
287 let list = self;
288 let list = list.ptr;
289 let isl_rs_result = unsafe { isl_basic_set_list_get_ctx(list) };
290 let isl_rs_result = Context { ptr: isl_rs_result,
291 should_free_on_drop: false };
292 isl_rs_result
293 }
294
295 pub fn insert(self, pos: u32, el: BasicSet) -> Result<BasicSetList, LibISLError> {
297 let list = self;
298 let isl_rs_ctx = list.get_ctx();
299 let mut list = list;
300 list.do_not_free_on_drop();
301 let list = list.ptr;
302 let mut el = el;
303 el.do_not_free_on_drop();
304 let el = el.ptr;
305 let isl_rs_result = unsafe { isl_basic_set_list_insert(list, pos, el) };
306 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
307 should_free_on_drop: true };
308 let err = isl_rs_ctx.last_error();
309 if err != Error::None_ {
310 let err_msg = isl_rs_ctx.last_error_msg();
311 isl_rs_ctx.reset_error();
312 return Err(LibISLError::new(err, err_msg));
313 }
314 Ok(isl_rs_result)
315 }
316
317 pub fn intersect(self) -> Result<BasicSet, LibISLError> {
319 let list = self;
320 let isl_rs_ctx = list.get_ctx();
321 let mut list = list;
322 list.do_not_free_on_drop();
323 let list = list.ptr;
324 let isl_rs_result = unsafe { isl_basic_set_list_intersect(list) };
325 let isl_rs_result = BasicSet { ptr: isl_rs_result,
326 should_free_on_drop: true };
327 let err = isl_rs_ctx.last_error();
328 if err != Error::None_ {
329 let err_msg = isl_rs_ctx.last_error_msg();
330 isl_rs_ctx.reset_error();
331 return Err(LibISLError::new(err, err_msg));
332 }
333 Ok(isl_rs_result)
334 }
335
336 pub fn n_basic_set(&self) -> Result<i32, LibISLError> {
338 let list = self;
339 let isl_rs_ctx = list.get_ctx();
340 let list = list.ptr;
341 let isl_rs_result = unsafe { isl_basic_set_list_n_basic_set(list) };
342 let err = isl_rs_ctx.last_error();
343 if err != Error::None_ {
344 let err_msg = isl_rs_ctx.last_error_msg();
345 isl_rs_ctx.reset_error();
346 return Err(LibISLError::new(err, err_msg));
347 }
348 Ok(isl_rs_result)
349 }
350
351 pub fn reverse(self) -> Result<BasicSetList, LibISLError> {
353 let list = self;
354 let isl_rs_ctx = list.get_ctx();
355 let mut list = list;
356 list.do_not_free_on_drop();
357 let list = list.ptr;
358 let isl_rs_result = unsafe { isl_basic_set_list_reverse(list) };
359 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
360 should_free_on_drop: true };
361 let err = isl_rs_ctx.last_error();
362 if err != Error::None_ {
363 let err_msg = isl_rs_ctx.last_error_msg();
364 isl_rs_ctx.reset_error();
365 return Err(LibISLError::new(err, err_msg));
366 }
367 Ok(isl_rs_result)
368 }
369
370 pub fn set_at(self, index: i32, el: BasicSet) -> Result<BasicSetList, LibISLError> {
372 let list = self;
373 let isl_rs_ctx = list.get_ctx();
374 let mut list = list;
375 list.do_not_free_on_drop();
376 let list = list.ptr;
377 let mut el = el;
378 el.do_not_free_on_drop();
379 let el = el.ptr;
380 let isl_rs_result = unsafe { isl_basic_set_list_set_at(list, index, el) };
381 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
382 should_free_on_drop: true };
383 let err = isl_rs_ctx.last_error();
384 if err != Error::None_ {
385 let err_msg = isl_rs_ctx.last_error_msg();
386 isl_rs_ctx.reset_error();
387 return Err(LibISLError::new(err, err_msg));
388 }
389 Ok(isl_rs_result)
390 }
391
392 pub fn set_basic_set(self, index: i32, el: BasicSet) -> Result<BasicSetList, LibISLError> {
394 let list = self;
395 let isl_rs_ctx = list.get_ctx();
396 let mut list = list;
397 list.do_not_free_on_drop();
398 let list = list.ptr;
399 let mut el = el;
400 el.do_not_free_on_drop();
401 let el = el.ptr;
402 let isl_rs_result = unsafe { isl_basic_set_list_set_basic_set(list, index, el) };
403 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
404 should_free_on_drop: true };
405 let err = isl_rs_ctx.last_error();
406 if err != Error::None_ {
407 let err_msg = isl_rs_ctx.last_error_msg();
408 isl_rs_ctx.reset_error();
409 return Err(LibISLError::new(err, err_msg));
410 }
411 Ok(isl_rs_result)
412 }
413
414 pub fn size(&self) -> Result<i32, LibISLError> {
416 let list = self;
417 let isl_rs_ctx = list.get_ctx();
418 let list = list.ptr;
419 let isl_rs_result = unsafe { isl_basic_set_list_size(list) };
420 let err = isl_rs_ctx.last_error();
421 if err != Error::None_ {
422 let err_msg = isl_rs_ctx.last_error_msg();
423 isl_rs_ctx.reset_error();
424 return Err(LibISLError::new(err, err_msg));
425 }
426 Ok(isl_rs_result)
427 }
428
429 pub fn swap(self, pos1: u32, pos2: u32) -> Result<BasicSetList, LibISLError> {
431 let list = self;
432 let isl_rs_ctx = list.get_ctx();
433 let mut list = list;
434 list.do_not_free_on_drop();
435 let list = list.ptr;
436 let isl_rs_result = unsafe { isl_basic_set_list_swap(list, pos1, pos2) };
437 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
438 should_free_on_drop: true };
439 let err = isl_rs_ctx.last_error();
440 if err != Error::None_ {
441 let err_msg = isl_rs_ctx.last_error_msg();
442 isl_rs_ctx.reset_error();
443 return Err(LibISLError::new(err, err_msg));
444 }
445 Ok(isl_rs_result)
446 }
447
448 pub fn to_str(&self) -> Result<&str, LibISLError> {
450 let list = self;
451 let isl_rs_ctx = list.get_ctx();
452 let list = list.ptr;
453 let isl_rs_result = unsafe { isl_basic_set_list_to_str(list) };
454 let isl_rs_result = unsafe { CStr::from_ptr(isl_rs_result) };
455 let isl_rs_result = isl_rs_result.to_str().unwrap();
456 let err = isl_rs_ctx.last_error();
457 if err != Error::None_ {
458 let err_msg = isl_rs_ctx.last_error_msg();
459 isl_rs_ctx.reset_error();
460 return Err(LibISLError::new(err, err_msg));
461 }
462 Ok(isl_rs_result)
463 }
464
465 pub fn do_not_free_on_drop(&mut self) {
468 self.should_free_on_drop = false;
469 }
470}
471
472impl Drop for BasicSetList {
473 fn drop(&mut self) {
474 if self.should_free_on_drop {
475 unsafe {
476 isl_basic_set_list_free(self.ptr);
477 }
478 }
479 }
480}