isl_rs/bindings/
constraint_list.rs

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