isl_rs/bindings/
id_list.rs

1// Automatically generated by isl_bindings_generator.
2// LICENSE: MIT
3
4use super::{Context, Error, Id, LibISLError};
5use libc::uintptr_t;
6use std::ffi::{CStr, CString};
7use std::os::raw::c_char;
8
9/// Wraps `isl_id_list`.
10pub struct IdList {
11    pub ptr: uintptr_t,
12    pub should_free_on_drop: bool,
13}
14
15extern "C" {
16
17    fn isl_id_list_add(list: uintptr_t, el: uintptr_t) -> uintptr_t;
18
19    fn isl_id_list_alloc(ctx: uintptr_t, n: i32) -> uintptr_t;
20
21    fn isl_id_list_clear(list: uintptr_t) -> uintptr_t;
22
23    fn isl_id_list_concat(list1: uintptr_t, list2: uintptr_t) -> uintptr_t;
24
25    fn isl_id_list_copy(list: uintptr_t) -> uintptr_t;
26
27    fn isl_id_list_drop(list: uintptr_t, first: u32, n: u32) -> uintptr_t;
28
29    fn isl_id_list_dump(list: uintptr_t) -> ();
30
31    fn isl_id_list_free(list: uintptr_t) -> uintptr_t;
32
33    fn isl_id_list_from_id(el: uintptr_t) -> uintptr_t;
34
35    fn isl_id_list_get_at(list: uintptr_t, index: i32) -> uintptr_t;
36
37    fn isl_id_list_get_ctx(list: uintptr_t) -> uintptr_t;
38
39    fn isl_id_list_get_id(list: uintptr_t, index: i32) -> uintptr_t;
40
41    fn isl_id_list_insert(list: uintptr_t, pos: u32, el: uintptr_t) -> uintptr_t;
42
43    fn isl_id_list_n_id(list: uintptr_t) -> i32;
44
45    fn isl_id_list_read_from_str(ctx: uintptr_t, str_: *const c_char) -> uintptr_t;
46
47    fn isl_id_list_reverse(list: uintptr_t) -> uintptr_t;
48
49    fn isl_id_list_set_at(list: uintptr_t, index: i32, el: uintptr_t) -> uintptr_t;
50
51    fn isl_id_list_set_id(list: uintptr_t, index: i32, el: uintptr_t) -> uintptr_t;
52
53    fn isl_id_list_size(list: uintptr_t) -> i32;
54
55    fn isl_id_list_swap(list: uintptr_t, pos1: u32, pos2: u32) -> uintptr_t;
56
57    fn isl_id_list_to_str(list: uintptr_t) -> *const c_char;
58
59}
60
61impl IdList {
62    /// Wraps `isl_id_list_add`.
63    pub fn add(self, el: Id) -> Result<IdList, LibISLError> {
64        let list = self;
65        let isl_rs_ctx = list.get_ctx();
66        let mut list = list;
67        list.do_not_free_on_drop();
68        let list = list.ptr;
69        let mut el = el;
70        el.do_not_free_on_drop();
71        let el = el.ptr;
72        let isl_rs_result = unsafe { isl_id_list_add(list, el) };
73        let isl_rs_result = IdList { ptr: isl_rs_result,
74                                     should_free_on_drop: true };
75        let err = isl_rs_ctx.last_error();
76        if err != Error::None_ {
77            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
78        }
79        Ok(isl_rs_result)
80    }
81
82    /// Wraps `isl_id_list_alloc`.
83    pub fn alloc(ctx: &Context, n: i32) -> Result<IdList, LibISLError> {
84        let isl_rs_ctx = Context { ptr: ctx.ptr,
85                                   should_free_on_drop: false };
86        let ctx = ctx.ptr;
87        let isl_rs_result = unsafe { isl_id_list_alloc(ctx, n) };
88        let isl_rs_result = IdList { ptr: isl_rs_result,
89                                     should_free_on_drop: true };
90        let err = isl_rs_ctx.last_error();
91        if err != Error::None_ {
92            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
93        }
94        Ok(isl_rs_result)
95    }
96
97    /// Wraps `isl_id_list_clear`.
98    pub fn clear(self) -> Result<IdList, LibISLError> {
99        let list = self;
100        let isl_rs_ctx = list.get_ctx();
101        let mut list = list;
102        list.do_not_free_on_drop();
103        let list = list.ptr;
104        let isl_rs_result = unsafe { isl_id_list_clear(list) };
105        let isl_rs_result = IdList { ptr: isl_rs_result,
106                                     should_free_on_drop: true };
107        let err = isl_rs_ctx.last_error();
108        if err != Error::None_ {
109            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
110        }
111        Ok(isl_rs_result)
112    }
113
114    /// Wraps `isl_id_list_concat`.
115    pub fn concat(self, list2: IdList) -> Result<IdList, LibISLError> {
116        let list1 = self;
117        let isl_rs_ctx = list1.get_ctx();
118        let mut list1 = list1;
119        list1.do_not_free_on_drop();
120        let list1 = list1.ptr;
121        let mut list2 = list2;
122        list2.do_not_free_on_drop();
123        let list2 = list2.ptr;
124        let isl_rs_result = unsafe { isl_id_list_concat(list1, list2) };
125        let isl_rs_result = IdList { ptr: isl_rs_result,
126                                     should_free_on_drop: true };
127        let err = isl_rs_ctx.last_error();
128        if err != Error::None_ {
129            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
130        }
131        Ok(isl_rs_result)
132    }
133
134    /// Wraps `isl_id_list_copy`.
135    pub fn copy(&self) -> Result<IdList, LibISLError> {
136        let list = self;
137        let isl_rs_ctx = list.get_ctx();
138        let list = list.ptr;
139        let isl_rs_result = unsafe { isl_id_list_copy(list) };
140        let isl_rs_result = IdList { ptr: isl_rs_result,
141                                     should_free_on_drop: true };
142        let err = isl_rs_ctx.last_error();
143        if err != Error::None_ {
144            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
145        }
146        Ok(isl_rs_result)
147    }
148
149    /// Wraps `isl_id_list_drop`.
150    pub fn drop(self, first: u32, n: u32) -> Result<IdList, LibISLError> {
151        let list = self;
152        let isl_rs_ctx = list.get_ctx();
153        let mut list = list;
154        list.do_not_free_on_drop();
155        let list = list.ptr;
156        let isl_rs_result = unsafe { isl_id_list_drop(list, first, n) };
157        let isl_rs_result = IdList { ptr: isl_rs_result,
158                                     should_free_on_drop: true };
159        let err = isl_rs_ctx.last_error();
160        if err != Error::None_ {
161            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
162        }
163        Ok(isl_rs_result)
164    }
165
166    /// Wraps `isl_id_list_dump`.
167    pub fn dump(&self) -> Result<(), LibISLError> {
168        let list = self;
169        let isl_rs_ctx = list.get_ctx();
170        let list = list.ptr;
171        let isl_rs_result = unsafe { isl_id_list_dump(list) };
172        let err = isl_rs_ctx.last_error();
173        if err != Error::None_ {
174            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
175        }
176        Ok(isl_rs_result)
177    }
178
179    /// Wraps `isl_id_list_free`.
180    pub fn free(self) -> Result<IdList, LibISLError> {
181        let list = self;
182        let isl_rs_ctx = list.get_ctx();
183        let mut list = list;
184        list.do_not_free_on_drop();
185        let list = list.ptr;
186        let isl_rs_result = unsafe { isl_id_list_free(list) };
187        let isl_rs_result = IdList { ptr: isl_rs_result,
188                                     should_free_on_drop: true };
189        let err = isl_rs_ctx.last_error();
190        if err != Error::None_ {
191            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
192        }
193        Ok(isl_rs_result)
194    }
195
196    /// Wraps `isl_id_list_from_id`.
197    pub fn from_id(el: Id) -> Result<IdList, LibISLError> {
198        let isl_rs_ctx = el.get_ctx();
199        let mut el = el;
200        el.do_not_free_on_drop();
201        let el = el.ptr;
202        let isl_rs_result = unsafe { isl_id_list_from_id(el) };
203        let isl_rs_result = IdList { ptr: isl_rs_result,
204                                     should_free_on_drop: true };
205        let err = isl_rs_ctx.last_error();
206        if err != Error::None_ {
207            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
208        }
209        Ok(isl_rs_result)
210    }
211
212    /// Wraps `isl_id_list_get_at`.
213    pub fn get_at(&self, index: i32) -> Result<Id, LibISLError> {
214        let list = self;
215        let isl_rs_ctx = list.get_ctx();
216        let list = list.ptr;
217        let isl_rs_result = unsafe { isl_id_list_get_at(list, index) };
218        let isl_rs_result = Id { ptr: isl_rs_result,
219                                 should_free_on_drop: true };
220        let err = isl_rs_ctx.last_error();
221        if err != Error::None_ {
222            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
223        }
224        Ok(isl_rs_result)
225    }
226
227    /// Wraps `isl_id_list_get_ctx`.
228    pub fn get_ctx(&self) -> Context {
229        let list = self;
230        let list = list.ptr;
231        let isl_rs_result = unsafe { isl_id_list_get_ctx(list) };
232        let isl_rs_result = Context { ptr: isl_rs_result,
233                                      should_free_on_drop: false };
234        isl_rs_result
235    }
236
237    /// Wraps `isl_id_list_get_id`.
238    pub fn get_id(&self, index: i32) -> Result<Id, LibISLError> {
239        let list = self;
240        let isl_rs_ctx = list.get_ctx();
241        let list = list.ptr;
242        let isl_rs_result = unsafe { isl_id_list_get_id(list, index) };
243        let isl_rs_result = Id { ptr: isl_rs_result,
244                                 should_free_on_drop: true };
245        let err = isl_rs_ctx.last_error();
246        if err != Error::None_ {
247            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
248        }
249        Ok(isl_rs_result)
250    }
251
252    /// Wraps `isl_id_list_insert`.
253    pub fn insert(self, pos: u32, el: Id) -> Result<IdList, LibISLError> {
254        let list = self;
255        let isl_rs_ctx = list.get_ctx();
256        let mut list = list;
257        list.do_not_free_on_drop();
258        let list = list.ptr;
259        let mut el = el;
260        el.do_not_free_on_drop();
261        let el = el.ptr;
262        let isl_rs_result = unsafe { isl_id_list_insert(list, pos, el) };
263        let isl_rs_result = IdList { ptr: isl_rs_result,
264                                     should_free_on_drop: true };
265        let err = isl_rs_ctx.last_error();
266        if err != Error::None_ {
267            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
268        }
269        Ok(isl_rs_result)
270    }
271
272    /// Wraps `isl_id_list_n_id`.
273    pub fn n_id(&self) -> Result<i32, LibISLError> {
274        let list = self;
275        let isl_rs_ctx = list.get_ctx();
276        let list = list.ptr;
277        let isl_rs_result = unsafe { isl_id_list_n_id(list) };
278        let err = isl_rs_ctx.last_error();
279        if err != Error::None_ {
280            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
281        }
282        Ok(isl_rs_result)
283    }
284
285    /// Wraps `isl_id_list_read_from_str`.
286    pub fn read_from_str(ctx: &Context, str_: &str) -> Result<IdList, LibISLError> {
287        let isl_rs_ctx = Context { ptr: ctx.ptr,
288                                   should_free_on_drop: false };
289        let ctx = ctx.ptr;
290        let str_ = CString::new(str_).unwrap();
291        let str_ = str_.as_ptr();
292        let isl_rs_result = unsafe { isl_id_list_read_from_str(ctx, str_) };
293        let isl_rs_result = IdList { ptr: isl_rs_result,
294                                     should_free_on_drop: true };
295        let err = isl_rs_ctx.last_error();
296        if err != Error::None_ {
297            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
298        }
299        Ok(isl_rs_result)
300    }
301
302    /// Wraps `isl_id_list_reverse`.
303    pub fn reverse(self) -> Result<IdList, LibISLError> {
304        let list = self;
305        let isl_rs_ctx = list.get_ctx();
306        let mut list = list;
307        list.do_not_free_on_drop();
308        let list = list.ptr;
309        let isl_rs_result = unsafe { isl_id_list_reverse(list) };
310        let isl_rs_result = IdList { ptr: isl_rs_result,
311                                     should_free_on_drop: true };
312        let err = isl_rs_ctx.last_error();
313        if err != Error::None_ {
314            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
315        }
316        Ok(isl_rs_result)
317    }
318
319    /// Wraps `isl_id_list_set_at`.
320    pub fn set_at(self, index: i32, el: Id) -> Result<IdList, LibISLError> {
321        let list = self;
322        let isl_rs_ctx = list.get_ctx();
323        let mut list = list;
324        list.do_not_free_on_drop();
325        let list = list.ptr;
326        let mut el = el;
327        el.do_not_free_on_drop();
328        let el = el.ptr;
329        let isl_rs_result = unsafe { isl_id_list_set_at(list, index, el) };
330        let isl_rs_result = IdList { ptr: isl_rs_result,
331                                     should_free_on_drop: true };
332        let err = isl_rs_ctx.last_error();
333        if err != Error::None_ {
334            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
335        }
336        Ok(isl_rs_result)
337    }
338
339    /// Wraps `isl_id_list_set_id`.
340    pub fn set_id(self, index: i32, el: Id) -> Result<IdList, LibISLError> {
341        let list = self;
342        let isl_rs_ctx = list.get_ctx();
343        let mut list = list;
344        list.do_not_free_on_drop();
345        let list = list.ptr;
346        let mut el = el;
347        el.do_not_free_on_drop();
348        let el = el.ptr;
349        let isl_rs_result = unsafe { isl_id_list_set_id(list, index, el) };
350        let isl_rs_result = IdList { ptr: isl_rs_result,
351                                     should_free_on_drop: true };
352        let err = isl_rs_ctx.last_error();
353        if err != Error::None_ {
354            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
355        }
356        Ok(isl_rs_result)
357    }
358
359    /// Wraps `isl_id_list_size`.
360    pub fn size(&self) -> Result<i32, LibISLError> {
361        let list = self;
362        let isl_rs_ctx = list.get_ctx();
363        let list = list.ptr;
364        let isl_rs_result = unsafe { isl_id_list_size(list) };
365        let err = isl_rs_ctx.last_error();
366        if err != Error::None_ {
367            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
368        }
369        Ok(isl_rs_result)
370    }
371
372    /// Wraps `isl_id_list_swap`.
373    pub fn swap(self, pos1: u32, pos2: u32) -> Result<IdList, LibISLError> {
374        let list = self;
375        let isl_rs_ctx = list.get_ctx();
376        let mut list = list;
377        list.do_not_free_on_drop();
378        let list = list.ptr;
379        let isl_rs_result = unsafe { isl_id_list_swap(list, pos1, pos2) };
380        let isl_rs_result = IdList { ptr: isl_rs_result,
381                                     should_free_on_drop: true };
382        let err = isl_rs_ctx.last_error();
383        if err != Error::None_ {
384            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
385        }
386        Ok(isl_rs_result)
387    }
388
389    /// Wraps `isl_id_list_to_str`.
390    pub fn to_str(&self) -> Result<&str, LibISLError> {
391        let list = self;
392        let isl_rs_ctx = list.get_ctx();
393        let list = list.ptr;
394        let isl_rs_result = unsafe { isl_id_list_to_str(list) };
395        let isl_rs_result = unsafe { CStr::from_ptr(isl_rs_result) };
396        let isl_rs_result = isl_rs_result.to_str().unwrap();
397        let err = isl_rs_ctx.last_error();
398        if err != Error::None_ {
399            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
400        }
401        Ok(isl_rs_result)
402    }
403
404    /// Does not call isl_id_list_free() on being dropped. (For internal use
405    /// only.)
406    pub fn do_not_free_on_drop(&mut self) {
407        self.should_free_on_drop = false;
408    }
409}
410
411impl Drop for IdList {
412    fn drop(&mut self) {
413        if self.should_free_on_drop {
414            unsafe {
415                isl_id_list_free(self.ptr);
416            }
417        }
418    }
419}