isl_rs/bindings/
constraint_list.rs1use super::{Constraint, Context};
5use libc::uintptr_t;
6use std::ffi::{CStr, CString};
7use std::os::raw::c_char;
8
9pub struct ConstraintList {
11    pub ptr: uintptr_t,
12    pub should_free_on_drop: bool,
13}
14
15extern "C" {
16
17    fn isl_constraint_list_size(list: uintptr_t) -> i32;
18
19    fn isl_constraint_list_dump(list: uintptr_t) -> ();
20
21    fn isl_constraint_list_insert(list: uintptr_t, pos: u32, el: uintptr_t) -> uintptr_t;
22
23    fn isl_constraint_list_n_constraint(list: uintptr_t) -> i32;
24
25    fn isl_constraint_list_add(list: uintptr_t, el: uintptr_t) -> uintptr_t;
26
27    fn isl_constraint_list_from_constraint(el: uintptr_t) -> uintptr_t;
28
29    fn isl_constraint_list_set_at(list: uintptr_t, index: i32, el: uintptr_t) -> uintptr_t;
30
31    fn isl_constraint_list_set_constraint(list: uintptr_t, index: i32, el: uintptr_t) -> uintptr_t;
32
33    fn isl_constraint_list_reverse(list: uintptr_t) -> uintptr_t;
34
35    fn isl_constraint_list_get_ctx(list: uintptr_t) -> uintptr_t;
36
37    fn isl_constraint_list_clear(list: uintptr_t) -> uintptr_t;
38
39    fn isl_constraint_list_get_constraint(list: uintptr_t, index: i32) -> uintptr_t;
40
41    fn isl_constraint_list_swap(list: uintptr_t, pos1: u32, pos2: u32) -> uintptr_t;
42
43    fn isl_constraint_list_alloc(ctx: uintptr_t, n: i32) -> uintptr_t;
44
45    fn isl_constraint_list_concat(list1: uintptr_t, list2: uintptr_t) -> uintptr_t;
46
47    fn isl_constraint_list_get_at(list: uintptr_t, index: i32) -> uintptr_t;
48
49    fn isl_constraint_list_copy(list: uintptr_t) -> uintptr_t;
50
51    fn isl_constraint_list_drop(list: uintptr_t, first: u32, n: u32) -> uintptr_t;
52
53    fn isl_constraint_list_free(list: uintptr_t) -> uintptr_t;
54
55    fn isl_constraint_list_to_str(list: uintptr_t) -> *const c_char;
56
57}
58
59impl ConstraintList {
60    pub fn size(&self) -> i32 {
62        let list = self;
63        let list = list.ptr;
64        let isl_rs_result = unsafe { isl_constraint_list_size(list) };
65        isl_rs_result
66    }
67
68    pub fn dump(&self) -> () {
70        let list = self;
71        let list = list.ptr;
72        let isl_rs_result = unsafe { isl_constraint_list_dump(list) };
73        isl_rs_result
74    }
75
76    pub fn insert(self, pos: u32, el: Constraint) -> ConstraintList {
78        let list = self;
79        let mut list = list;
80        list.do_not_free_on_drop();
81        let list = list.ptr;
82        let mut el = el;
83        el.do_not_free_on_drop();
84        let el = el.ptr;
85        let isl_rs_result = unsafe { isl_constraint_list_insert(list, pos, el) };
86        let isl_rs_result = ConstraintList { ptr: isl_rs_result,
87                                             should_free_on_drop: true };
88        isl_rs_result
89    }
90
91    pub fn n_constraint(&self) -> i32 {
93        let list = self;
94        let list = list.ptr;
95        let isl_rs_result = unsafe { isl_constraint_list_n_constraint(list) };
96        isl_rs_result
97    }
98
99    pub fn add(self, el: Constraint) -> ConstraintList {
101        let list = self;
102        let mut list = list;
103        list.do_not_free_on_drop();
104        let list = list.ptr;
105        let mut el = el;
106        el.do_not_free_on_drop();
107        let el = el.ptr;
108        let isl_rs_result = unsafe { isl_constraint_list_add(list, el) };
109        let isl_rs_result = ConstraintList { ptr: isl_rs_result,
110                                             should_free_on_drop: true };
111        isl_rs_result
112    }
113
114    pub fn from_constraint(el: Constraint) -> ConstraintList {
116        let mut el = el;
117        el.do_not_free_on_drop();
118        let el = el.ptr;
119        let isl_rs_result = unsafe { isl_constraint_list_from_constraint(el) };
120        let isl_rs_result = ConstraintList { ptr: isl_rs_result,
121                                             should_free_on_drop: true };
122        isl_rs_result
123    }
124
125    pub fn set_at(self, index: i32, el: Constraint) -> ConstraintList {
127        let list = self;
128        let mut list = list;
129        list.do_not_free_on_drop();
130        let list = list.ptr;
131        let mut el = el;
132        el.do_not_free_on_drop();
133        let el = el.ptr;
134        let isl_rs_result = unsafe { isl_constraint_list_set_at(list, index, el) };
135        let isl_rs_result = ConstraintList { ptr: isl_rs_result,
136                                             should_free_on_drop: true };
137        isl_rs_result
138    }
139
140    pub fn set_constraint(self, index: i32, el: Constraint) -> ConstraintList {
142        let list = self;
143        let mut list = list;
144        list.do_not_free_on_drop();
145        let list = list.ptr;
146        let mut el = el;
147        el.do_not_free_on_drop();
148        let el = el.ptr;
149        let isl_rs_result = unsafe { isl_constraint_list_set_constraint(list, index, el) };
150        let isl_rs_result = ConstraintList { ptr: isl_rs_result,
151                                             should_free_on_drop: true };
152        isl_rs_result
153    }
154
155    pub fn reverse(self) -> ConstraintList {
157        let list = self;
158        let mut list = list;
159        list.do_not_free_on_drop();
160        let list = list.ptr;
161        let isl_rs_result = unsafe { isl_constraint_list_reverse(list) };
162        let isl_rs_result = ConstraintList { ptr: isl_rs_result,
163                                             should_free_on_drop: true };
164        isl_rs_result
165    }
166
167    pub fn get_ctx(&self) -> Context {
169        let list = self;
170        let list = list.ptr;
171        let isl_rs_result = unsafe { isl_constraint_list_get_ctx(list) };
172        let isl_rs_result = Context { ptr: isl_rs_result,
173                                      should_free_on_drop: false };
174        isl_rs_result
175    }
176
177    pub fn clear(self) -> ConstraintList {
179        let list = self;
180        let mut list = list;
181        list.do_not_free_on_drop();
182        let list = list.ptr;
183        let isl_rs_result = unsafe { isl_constraint_list_clear(list) };
184        let isl_rs_result = ConstraintList { ptr: isl_rs_result,
185                                             should_free_on_drop: true };
186        isl_rs_result
187    }
188
189    pub fn get_constraint(&self, index: i32) -> Constraint {
191        let list = self;
192        let list = list.ptr;
193        let isl_rs_result = unsafe { isl_constraint_list_get_constraint(list, index) };
194        let isl_rs_result = Constraint { ptr: isl_rs_result,
195                                         should_free_on_drop: true };
196        isl_rs_result
197    }
198
199    pub fn swap(self, pos1: u32, pos2: u32) -> ConstraintList {
201        let list = self;
202        let mut list = list;
203        list.do_not_free_on_drop();
204        let list = list.ptr;
205        let isl_rs_result = unsafe { isl_constraint_list_swap(list, pos1, pos2) };
206        let isl_rs_result = ConstraintList { ptr: isl_rs_result,
207                                             should_free_on_drop: true };
208        isl_rs_result
209    }
210
211    pub fn alloc(ctx: &Context, n: i32) -> ConstraintList {
213        let ctx = ctx.ptr;
214        let isl_rs_result = unsafe { isl_constraint_list_alloc(ctx, n) };
215        let isl_rs_result = ConstraintList { ptr: isl_rs_result,
216                                             should_free_on_drop: true };
217        isl_rs_result
218    }
219
220    pub fn concat(self, list2: ConstraintList) -> ConstraintList {
222        let list1 = self;
223        let mut list1 = list1;
224        list1.do_not_free_on_drop();
225        let list1 = list1.ptr;
226        let mut list2 = list2;
227        list2.do_not_free_on_drop();
228        let list2 = list2.ptr;
229        let isl_rs_result = unsafe { isl_constraint_list_concat(list1, list2) };
230        let isl_rs_result = ConstraintList { ptr: isl_rs_result,
231                                             should_free_on_drop: true };
232        isl_rs_result
233    }
234
235    pub fn get_at(&self, index: i32) -> Constraint {
237        let list = self;
238        let list = list.ptr;
239        let isl_rs_result = unsafe { isl_constraint_list_get_at(list, index) };
240        let isl_rs_result = Constraint { ptr: isl_rs_result,
241                                         should_free_on_drop: true };
242        isl_rs_result
243    }
244
245    pub fn copy(&self) -> ConstraintList {
247        let list = self;
248        let list = list.ptr;
249        let isl_rs_result = unsafe { isl_constraint_list_copy(list) };
250        let isl_rs_result = ConstraintList { ptr: isl_rs_result,
251                                             should_free_on_drop: true };
252        isl_rs_result
253    }
254
255    pub fn drop(self, first: u32, n: u32) -> ConstraintList {
257        let list = self;
258        let mut list = list;
259        list.do_not_free_on_drop();
260        let list = list.ptr;
261        let isl_rs_result = unsafe { isl_constraint_list_drop(list, first, n) };
262        let isl_rs_result = ConstraintList { ptr: isl_rs_result,
263                                             should_free_on_drop: true };
264        isl_rs_result
265    }
266
267    pub fn free(self) -> ConstraintList {
269        let list = self;
270        let mut list = list;
271        list.do_not_free_on_drop();
272        let list = list.ptr;
273        let isl_rs_result = unsafe { isl_constraint_list_free(list) };
274        let isl_rs_result = ConstraintList { ptr: isl_rs_result,
275                                             should_free_on_drop: true };
276        isl_rs_result
277    }
278
279    pub fn to_str(&self) -> &str {
281        let list = self;
282        let list = list.ptr;
283        let isl_rs_result = unsafe { isl_constraint_list_to_str(list) };
284        let isl_rs_result = unsafe { CStr::from_ptr(isl_rs_result) };
285        let isl_rs_result = isl_rs_result.to_str().unwrap();
286        isl_rs_result
287    }
288
289    pub fn do_not_free_on_drop(&mut self) {
292        self.should_free_on_drop = false;
293    }
294}
295
296impl Drop for ConstraintList {
297    fn drop(&mut self) {
298        if self.should_free_on_drop {
299            unsafe {
300                isl_constraint_list_free(self.ptr);
301            }
302        }
303    }
304}