isl_rs/bindings/
set_list.rs

1// Automatically generated by isl_bindings_generator.
2// LICENSE: MIT
3
4use super::{Context, Error, LibISLError, Set};
5use libc::uintptr_t;
6use std::ffi::{CStr, CString};
7use std::os::raw::c_char;
8
9/// Wraps `isl_set_list`.
10pub struct SetList {
11    pub ptr: uintptr_t,
12    pub should_free_on_drop: bool,
13}
14
15extern "C" {
16
17    fn isl_set_list_add(list: uintptr_t, el: uintptr_t) -> uintptr_t;
18
19    fn isl_set_list_alloc(ctx: uintptr_t, n: i32) -> uintptr_t;
20
21    fn isl_set_list_clear(list: uintptr_t) -> uintptr_t;
22
23    fn isl_set_list_concat(list1: uintptr_t, list2: uintptr_t) -> uintptr_t;
24
25    fn isl_set_list_copy(list: uintptr_t) -> uintptr_t;
26
27    fn isl_set_list_drop(list: uintptr_t, first: u32, n: u32) -> uintptr_t;
28
29    fn isl_set_list_dump(list: uintptr_t) -> ();
30
31    fn isl_set_list_free(list: uintptr_t) -> uintptr_t;
32
33    fn isl_set_list_from_set(el: uintptr_t) -> uintptr_t;
34
35    fn isl_set_list_get_at(list: uintptr_t, index: i32) -> uintptr_t;
36
37    fn isl_set_list_get_ctx(list: uintptr_t) -> uintptr_t;
38
39    fn isl_set_list_get_set(list: uintptr_t, index: i32) -> uintptr_t;
40
41    fn isl_set_list_insert(list: uintptr_t, pos: u32, el: uintptr_t) -> uintptr_t;
42
43    fn isl_set_list_n_set(list: uintptr_t) -> i32;
44
45    fn isl_set_list_read_from_str(ctx: uintptr_t, str_: *const c_char) -> uintptr_t;
46
47    fn isl_set_list_reverse(list: uintptr_t) -> uintptr_t;
48
49    fn isl_set_list_set_at(list: uintptr_t, index: i32, el: uintptr_t) -> uintptr_t;
50
51    fn isl_set_list_set_set(list: uintptr_t, index: i32, el: uintptr_t) -> uintptr_t;
52
53    fn isl_set_list_size(list: uintptr_t) -> i32;
54
55    fn isl_set_list_swap(list: uintptr_t, pos1: u32, pos2: u32) -> uintptr_t;
56
57    fn isl_set_list_to_str(list: uintptr_t) -> *const c_char;
58
59    fn isl_set_list_union(list: uintptr_t) -> uintptr_t;
60
61}
62
63impl SetList {
64    /// Wraps `isl_set_list_add`.
65    pub fn add(self, el: Set) -> Result<SetList, 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_set_list_add(list, el) };
75        let isl_rs_result = SetList { 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    /// Wraps `isl_set_list_alloc`.
87    pub fn alloc(ctx: &Context, n: i32) -> Result<SetList, 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_set_list_alloc(ctx, n) };
92        let isl_rs_result = SetList { 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    /// Wraps `isl_set_list_clear`.
104    pub fn clear(self) -> Result<SetList, 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_set_list_clear(list) };
111        let isl_rs_result = SetList { 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    /// Wraps `isl_set_list_concat`.
123    pub fn concat(self, list2: SetList) -> Result<SetList, LibISLError> {
124        let list1 = self;
125        let isl_rs_ctx = list1.get_ctx();
126        let mut list1 = list1;
127        list1.do_not_free_on_drop();
128        let list1 = list1.ptr;
129        let mut list2 = list2;
130        list2.do_not_free_on_drop();
131        let list2 = list2.ptr;
132        let isl_rs_result = unsafe { isl_set_list_concat(list1, list2) };
133        let isl_rs_result = SetList { ptr: isl_rs_result,
134                                      should_free_on_drop: true };
135        let err = isl_rs_ctx.last_error();
136        if err != Error::None_ {
137            let err_msg = isl_rs_ctx.last_error_msg();
138            isl_rs_ctx.reset_error();
139            return Err(LibISLError::new(err, err_msg));
140        }
141        Ok(isl_rs_result)
142    }
143
144    /// Wraps `isl_set_list_copy`.
145    pub fn copy(&self) -> Result<SetList, LibISLError> {
146        let list = self;
147        let isl_rs_ctx = list.get_ctx();
148        let list = list.ptr;
149        let isl_rs_result = unsafe { isl_set_list_copy(list) };
150        let isl_rs_result = SetList { ptr: isl_rs_result,
151                                      should_free_on_drop: true };
152        let err = isl_rs_ctx.last_error();
153        if err != Error::None_ {
154            let err_msg = isl_rs_ctx.last_error_msg();
155            isl_rs_ctx.reset_error();
156            return Err(LibISLError::new(err, err_msg));
157        }
158        Ok(isl_rs_result)
159    }
160
161    /// Wraps `isl_set_list_drop`.
162    pub fn drop(self, first: u32, n: u32) -> Result<SetList, LibISLError> {
163        let list = self;
164        let isl_rs_ctx = list.get_ctx();
165        let mut list = list;
166        list.do_not_free_on_drop();
167        let list = list.ptr;
168        let isl_rs_result = unsafe { isl_set_list_drop(list, first, n) };
169        let isl_rs_result = SetList { 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    /// Wraps `isl_set_list_dump`.
181    pub fn dump(&self) -> Result<(), LibISLError> {
182        let list = self;
183        let isl_rs_ctx = list.get_ctx();
184        let list = list.ptr;
185        let isl_rs_result = unsafe { isl_set_list_dump(list) };
186        let err = isl_rs_ctx.last_error();
187        if err != Error::None_ {
188            let err_msg = isl_rs_ctx.last_error_msg();
189            isl_rs_ctx.reset_error();
190            return Err(LibISLError::new(err, err_msg));
191        }
192        Ok(isl_rs_result)
193    }
194
195    /// Wraps `isl_set_list_free`.
196    pub fn free(self) -> Result<SetList, LibISLError> {
197        let list = self;
198        let isl_rs_ctx = list.get_ctx();
199        let mut list = list;
200        list.do_not_free_on_drop();
201        let list = list.ptr;
202        let isl_rs_result = unsafe { isl_set_list_free(list) };
203        let isl_rs_result = SetList { ptr: isl_rs_result,
204                                      should_free_on_drop: true };
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    /// Wraps `isl_set_list_from_set`.
215    pub fn from_set(el: Set) -> Result<SetList, LibISLError> {
216        let isl_rs_ctx = el.get_ctx();
217        let mut el = el;
218        el.do_not_free_on_drop();
219        let el = el.ptr;
220        let isl_rs_result = unsafe { isl_set_list_from_set(el) };
221        let isl_rs_result = SetList { ptr: isl_rs_result,
222                                      should_free_on_drop: true };
223        let err = isl_rs_ctx.last_error();
224        if err != Error::None_ {
225            let err_msg = isl_rs_ctx.last_error_msg();
226            isl_rs_ctx.reset_error();
227            return Err(LibISLError::new(err, err_msg));
228        }
229        Ok(isl_rs_result)
230    }
231
232    /// Wraps `isl_set_list_get_at`.
233    pub fn get_at(&self, index: i32) -> Result<Set, LibISLError> {
234        let list = self;
235        let isl_rs_ctx = list.get_ctx();
236        let list = list.ptr;
237        let isl_rs_result = unsafe { isl_set_list_get_at(list, index) };
238        let isl_rs_result = Set { ptr: isl_rs_result,
239                                  should_free_on_drop: true };
240        let err = isl_rs_ctx.last_error();
241        if err != Error::None_ {
242            let err_msg = isl_rs_ctx.last_error_msg();
243            isl_rs_ctx.reset_error();
244            return Err(LibISLError::new(err, err_msg));
245        }
246        Ok(isl_rs_result)
247    }
248
249    /// Wraps `isl_set_list_get_ctx`.
250    pub fn get_ctx(&self) -> Context {
251        let list = self;
252        let list = list.ptr;
253        let isl_rs_result = unsafe { isl_set_list_get_ctx(list) };
254        let isl_rs_result = Context { ptr: isl_rs_result,
255                                      should_free_on_drop: false };
256        isl_rs_result
257    }
258
259    /// Wraps `isl_set_list_get_set`.
260    pub fn get_set(&self, index: i32) -> Result<Set, LibISLError> {
261        let list = self;
262        let isl_rs_ctx = list.get_ctx();
263        let list = list.ptr;
264        let isl_rs_result = unsafe { isl_set_list_get_set(list, index) };
265        let isl_rs_result = Set { ptr: isl_rs_result,
266                                  should_free_on_drop: true };
267        let err = isl_rs_ctx.last_error();
268        if err != Error::None_ {
269            let err_msg = isl_rs_ctx.last_error_msg();
270            isl_rs_ctx.reset_error();
271            return Err(LibISLError::new(err, err_msg));
272        }
273        Ok(isl_rs_result)
274    }
275
276    /// Wraps `isl_set_list_insert`.
277    pub fn insert(self, pos: u32, el: Set) -> Result<SetList, LibISLError> {
278        let list = self;
279        let isl_rs_ctx = list.get_ctx();
280        let mut list = list;
281        list.do_not_free_on_drop();
282        let list = list.ptr;
283        let mut el = el;
284        el.do_not_free_on_drop();
285        let el = el.ptr;
286        let isl_rs_result = unsafe { isl_set_list_insert(list, pos, el) };
287        let isl_rs_result = SetList { ptr: isl_rs_result,
288                                      should_free_on_drop: true };
289        let err = isl_rs_ctx.last_error();
290        if err != Error::None_ {
291            let err_msg = isl_rs_ctx.last_error_msg();
292            isl_rs_ctx.reset_error();
293            return Err(LibISLError::new(err, err_msg));
294        }
295        Ok(isl_rs_result)
296    }
297
298    /// Wraps `isl_set_list_n_set`.
299    pub fn n_set(&self) -> Result<i32, LibISLError> {
300        let list = self;
301        let isl_rs_ctx = list.get_ctx();
302        let list = list.ptr;
303        let isl_rs_result = unsafe { isl_set_list_n_set(list) };
304        let err = isl_rs_ctx.last_error();
305        if err != Error::None_ {
306            let err_msg = isl_rs_ctx.last_error_msg();
307            isl_rs_ctx.reset_error();
308            return Err(LibISLError::new(err, err_msg));
309        }
310        Ok(isl_rs_result)
311    }
312
313    /// Wraps `isl_set_list_read_from_str`.
314    pub fn read_from_str(ctx: &Context, str_: &str) -> Result<SetList, LibISLError> {
315        let isl_rs_ctx = Context { ptr: ctx.ptr,
316                                   should_free_on_drop: false };
317        let ctx = ctx.ptr;
318        let str_ = CString::new(str_).unwrap();
319        let str_ = str_.as_ptr();
320        let isl_rs_result = unsafe { isl_set_list_read_from_str(ctx, str_) };
321        let isl_rs_result = SetList { ptr: isl_rs_result,
322                                      should_free_on_drop: true };
323        let err = isl_rs_ctx.last_error();
324        if err != Error::None_ {
325            let err_msg = isl_rs_ctx.last_error_msg();
326            isl_rs_ctx.reset_error();
327            return Err(LibISLError::new(err, err_msg));
328        }
329        Ok(isl_rs_result)
330    }
331
332    /// Wraps `isl_set_list_reverse`.
333    pub fn reverse(self) -> Result<SetList, LibISLError> {
334        let list = self;
335        let isl_rs_ctx = list.get_ctx();
336        let mut list = list;
337        list.do_not_free_on_drop();
338        let list = list.ptr;
339        let isl_rs_result = unsafe { isl_set_list_reverse(list) };
340        let isl_rs_result = SetList { ptr: isl_rs_result,
341                                      should_free_on_drop: true };
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    /// Wraps `isl_set_list_set_at`.
352    pub fn set_at(self, index: i32, el: Set) -> Result<SetList, 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 mut el = el;
359        el.do_not_free_on_drop();
360        let el = el.ptr;
361        let isl_rs_result = unsafe { isl_set_list_set_at(list, index, el) };
362        let isl_rs_result = SetList { ptr: isl_rs_result,
363                                      should_free_on_drop: true };
364        let err = isl_rs_ctx.last_error();
365        if err != Error::None_ {
366            let err_msg = isl_rs_ctx.last_error_msg();
367            isl_rs_ctx.reset_error();
368            return Err(LibISLError::new(err, err_msg));
369        }
370        Ok(isl_rs_result)
371    }
372
373    /// Wraps `isl_set_list_set_set`.
374    pub fn set_set(self, index: i32, el: Set) -> Result<SetList, LibISLError> {
375        let list = self;
376        let isl_rs_ctx = list.get_ctx();
377        let mut list = list;
378        list.do_not_free_on_drop();
379        let list = list.ptr;
380        let mut el = el;
381        el.do_not_free_on_drop();
382        let el = el.ptr;
383        let isl_rs_result = unsafe { isl_set_list_set_set(list, index, el) };
384        let isl_rs_result = SetList { ptr: isl_rs_result,
385                                      should_free_on_drop: true };
386        let err = isl_rs_ctx.last_error();
387        if err != Error::None_ {
388            let err_msg = isl_rs_ctx.last_error_msg();
389            isl_rs_ctx.reset_error();
390            return Err(LibISLError::new(err, err_msg));
391        }
392        Ok(isl_rs_result)
393    }
394
395    /// Wraps `isl_set_list_size`.
396    pub fn size(&self) -> Result<i32, LibISLError> {
397        let list = self;
398        let isl_rs_ctx = list.get_ctx();
399        let list = list.ptr;
400        let isl_rs_result = unsafe { isl_set_list_size(list) };
401        let err = isl_rs_ctx.last_error();
402        if err != Error::None_ {
403            let err_msg = isl_rs_ctx.last_error_msg();
404            isl_rs_ctx.reset_error();
405            return Err(LibISLError::new(err, err_msg));
406        }
407        Ok(isl_rs_result)
408    }
409
410    /// Wraps `isl_set_list_swap`.
411    pub fn swap(self, pos1: u32, pos2: u32) -> Result<SetList, LibISLError> {
412        let list = self;
413        let isl_rs_ctx = list.get_ctx();
414        let mut list = list;
415        list.do_not_free_on_drop();
416        let list = list.ptr;
417        let isl_rs_result = unsafe { isl_set_list_swap(list, pos1, pos2) };
418        let isl_rs_result = SetList { ptr: isl_rs_result,
419                                      should_free_on_drop: true };
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    /// Wraps `isl_set_list_to_str`.
430    pub fn to_str(&self) -> Result<&str, LibISLError> {
431        let list = self;
432        let isl_rs_ctx = list.get_ctx();
433        let list = list.ptr;
434        let isl_rs_result = unsafe { isl_set_list_to_str(list) };
435        let isl_rs_result = unsafe { CStr::from_ptr(isl_rs_result) };
436        let isl_rs_result = isl_rs_result.to_str().unwrap();
437        let err = isl_rs_ctx.last_error();
438        if err != Error::None_ {
439            let err_msg = isl_rs_ctx.last_error_msg();
440            isl_rs_ctx.reset_error();
441            return Err(LibISLError::new(err, err_msg));
442        }
443        Ok(isl_rs_result)
444    }
445
446    /// Wraps `isl_set_list_union`.
447    pub fn union(self) -> Result<Set, LibISLError> {
448        let list = self;
449        let isl_rs_ctx = list.get_ctx();
450        let mut list = list;
451        list.do_not_free_on_drop();
452        let list = list.ptr;
453        let isl_rs_result = unsafe { isl_set_list_union(list) };
454        let isl_rs_result = Set { ptr: isl_rs_result,
455                                  should_free_on_drop: true };
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    /// Does not call isl_set_list_free() on being dropped. (For internal use
466    /// only.)
467    pub fn do_not_free_on_drop(&mut self) {
468        self.should_free_on_drop = false;
469    }
470}
471
472impl Drop for SetList {
473    fn drop(&mut self) {
474        if self.should_free_on_drop {
475            unsafe {
476                isl_set_list_free(self.ptr);
477            }
478        }
479    }
480}