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 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
80 }
81 Ok(isl_rs_result)
82 }
83
84 pub fn alloc(ctx: &Context, n: i32) -> Result<BasicSetList, LibISLError> {
86 let isl_rs_ctx = Context { ptr: ctx.ptr,
87 should_free_on_drop: false };
88 let ctx = ctx.ptr;
89 let isl_rs_result = unsafe { isl_basic_set_list_alloc(ctx, n) };
90 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
91 should_free_on_drop: true };
92 let err = isl_rs_ctx.last_error();
93 if err != Error::None_ {
94 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
95 }
96 Ok(isl_rs_result)
97 }
98
99 pub fn clear(self) -> Result<BasicSetList, LibISLError> {
101 let list = self;
102 let isl_rs_ctx = list.get_ctx();
103 let mut list = list;
104 list.do_not_free_on_drop();
105 let list = list.ptr;
106 let isl_rs_result = unsafe { isl_basic_set_list_clear(list) };
107 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
108 should_free_on_drop: true };
109 let err = isl_rs_ctx.last_error();
110 if err != Error::None_ {
111 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
112 }
113 Ok(isl_rs_result)
114 }
115
116 pub fn coefficients(self) -> Result<BasicSetList, LibISLError> {
118 let list = self;
119 let isl_rs_ctx = list.get_ctx();
120 let mut list = list;
121 list.do_not_free_on_drop();
122 let list = list.ptr;
123 let isl_rs_result = unsafe { isl_basic_set_list_coefficients(list) };
124 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
125 should_free_on_drop: true };
126 let err = isl_rs_ctx.last_error();
127 if err != Error::None_ {
128 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
129 }
130 Ok(isl_rs_result)
131 }
132
133 pub fn concat(self, list2: BasicSetList) -> Result<BasicSetList, LibISLError> {
135 let list1 = self;
136 let isl_rs_ctx = list1.get_ctx();
137 let mut list1 = list1;
138 list1.do_not_free_on_drop();
139 let list1 = list1.ptr;
140 let mut list2 = list2;
141 list2.do_not_free_on_drop();
142 let list2 = list2.ptr;
143 let isl_rs_result = unsafe { isl_basic_set_list_concat(list1, list2) };
144 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
145 should_free_on_drop: true };
146 let err = isl_rs_ctx.last_error();
147 if err != Error::None_ {
148 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
149 }
150 Ok(isl_rs_result)
151 }
152
153 pub fn copy(&self) -> Result<BasicSetList, LibISLError> {
155 let list = self;
156 let isl_rs_ctx = list.get_ctx();
157 let list = list.ptr;
158 let isl_rs_result = unsafe { isl_basic_set_list_copy(list) };
159 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
160 should_free_on_drop: true };
161 let err = isl_rs_ctx.last_error();
162 if err != Error::None_ {
163 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
164 }
165 Ok(isl_rs_result)
166 }
167
168 pub fn drop(self, first: u32, n: u32) -> Result<BasicSetList, LibISLError> {
170 let list = self;
171 let isl_rs_ctx = list.get_ctx();
172 let mut list = list;
173 list.do_not_free_on_drop();
174 let list = list.ptr;
175 let isl_rs_result = unsafe { isl_basic_set_list_drop(list, first, n) };
176 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
177 should_free_on_drop: true };
178 let err = isl_rs_ctx.last_error();
179 if err != Error::None_ {
180 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
181 }
182 Ok(isl_rs_result)
183 }
184
185 pub fn dump(&self) -> Result<(), LibISLError> {
187 let list = self;
188 let isl_rs_ctx = list.get_ctx();
189 let list = list.ptr;
190 let isl_rs_result = unsafe { isl_basic_set_list_dump(list) };
191 let err = isl_rs_ctx.last_error();
192 if err != Error::None_ {
193 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
194 }
195 Ok(isl_rs_result)
196 }
197
198 pub fn free(self) -> Result<BasicSetList, LibISLError> {
200 let list = self;
201 let isl_rs_ctx = list.get_ctx();
202 let mut list = list;
203 list.do_not_free_on_drop();
204 let list = list.ptr;
205 let isl_rs_result = unsafe { isl_basic_set_list_free(list) };
206 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
207 should_free_on_drop: true };
208 let err = isl_rs_ctx.last_error();
209 if err != Error::None_ {
210 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
211 }
212 Ok(isl_rs_result)
213 }
214
215 pub fn from_basic_set(el: BasicSet) -> Result<BasicSetList, LibISLError> {
217 let isl_rs_ctx = el.get_ctx();
218 let mut el = el;
219 el.do_not_free_on_drop();
220 let el = el.ptr;
221 let isl_rs_result = unsafe { isl_basic_set_list_from_basic_set(el) };
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 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
227 }
228 Ok(isl_rs_result)
229 }
230
231 pub fn get_at(&self, index: i32) -> Result<BasicSet, LibISLError> {
233 let list = self;
234 let isl_rs_ctx = list.get_ctx();
235 let list = list.ptr;
236 let isl_rs_result = unsafe { isl_basic_set_list_get_at(list, index) };
237 let isl_rs_result = BasicSet { ptr: isl_rs_result,
238 should_free_on_drop: true };
239 let err = isl_rs_ctx.last_error();
240 if err != Error::None_ {
241 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
242 }
243 Ok(isl_rs_result)
244 }
245
246 pub fn get_basic_set(&self, index: i32) -> Result<BasicSet, LibISLError> {
248 let list = self;
249 let isl_rs_ctx = list.get_ctx();
250 let list = list.ptr;
251 let isl_rs_result = unsafe { isl_basic_set_list_get_basic_set(list, index) };
252 let isl_rs_result = BasicSet { ptr: isl_rs_result,
253 should_free_on_drop: true };
254 let err = isl_rs_ctx.last_error();
255 if err != Error::None_ {
256 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
257 }
258 Ok(isl_rs_result)
259 }
260
261 pub fn get_ctx(&self) -> Context {
263 let list = self;
264 let list = list.ptr;
265 let isl_rs_result = unsafe { isl_basic_set_list_get_ctx(list) };
266 let isl_rs_result = Context { ptr: isl_rs_result,
267 should_free_on_drop: false };
268 isl_rs_result
269 }
270
271 pub fn insert(self, pos: u32, el: BasicSet) -> Result<BasicSetList, LibISLError> {
273 let list = self;
274 let isl_rs_ctx = list.get_ctx();
275 let mut list = list;
276 list.do_not_free_on_drop();
277 let list = list.ptr;
278 let mut el = el;
279 el.do_not_free_on_drop();
280 let el = el.ptr;
281 let isl_rs_result = unsafe { isl_basic_set_list_insert(list, pos, el) };
282 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
283 should_free_on_drop: true };
284 let err = isl_rs_ctx.last_error();
285 if err != Error::None_ {
286 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
287 }
288 Ok(isl_rs_result)
289 }
290
291 pub fn intersect(self) -> Result<BasicSet, LibISLError> {
293 let list = self;
294 let isl_rs_ctx = list.get_ctx();
295 let mut list = list;
296 list.do_not_free_on_drop();
297 let list = list.ptr;
298 let isl_rs_result = unsafe { isl_basic_set_list_intersect(list) };
299 let isl_rs_result = BasicSet { ptr: isl_rs_result,
300 should_free_on_drop: true };
301 let err = isl_rs_ctx.last_error();
302 if err != Error::None_ {
303 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
304 }
305 Ok(isl_rs_result)
306 }
307
308 pub fn n_basic_set(&self) -> Result<i32, LibISLError> {
310 let list = self;
311 let isl_rs_ctx = list.get_ctx();
312 let list = list.ptr;
313 let isl_rs_result = unsafe { isl_basic_set_list_n_basic_set(list) };
314 let err = isl_rs_ctx.last_error();
315 if err != Error::None_ {
316 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
317 }
318 Ok(isl_rs_result)
319 }
320
321 pub fn reverse(self) -> Result<BasicSetList, LibISLError> {
323 let list = self;
324 let isl_rs_ctx = list.get_ctx();
325 let mut list = list;
326 list.do_not_free_on_drop();
327 let list = list.ptr;
328 let isl_rs_result = unsafe { isl_basic_set_list_reverse(list) };
329 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
330 should_free_on_drop: true };
331 let err = isl_rs_ctx.last_error();
332 if err != Error::None_ {
333 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
334 }
335 Ok(isl_rs_result)
336 }
337
338 pub fn set_at(self, index: i32, el: BasicSet) -> Result<BasicSetList, LibISLError> {
340 let list = self;
341 let isl_rs_ctx = list.get_ctx();
342 let mut list = list;
343 list.do_not_free_on_drop();
344 let list = list.ptr;
345 let mut el = el;
346 el.do_not_free_on_drop();
347 let el = el.ptr;
348 let isl_rs_result = unsafe { isl_basic_set_list_set_at(list, index, el) };
349 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
350 should_free_on_drop: true };
351 let err = isl_rs_ctx.last_error();
352 if err != Error::None_ {
353 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
354 }
355 Ok(isl_rs_result)
356 }
357
358 pub fn set_basic_set(self, index: i32, el: BasicSet) -> Result<BasicSetList, LibISLError> {
360 let list = self;
361 let isl_rs_ctx = list.get_ctx();
362 let mut list = list;
363 list.do_not_free_on_drop();
364 let list = list.ptr;
365 let mut el = el;
366 el.do_not_free_on_drop();
367 let el = el.ptr;
368 let isl_rs_result = unsafe { isl_basic_set_list_set_basic_set(list, index, el) };
369 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
370 should_free_on_drop: true };
371 let err = isl_rs_ctx.last_error();
372 if err != Error::None_ {
373 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
374 }
375 Ok(isl_rs_result)
376 }
377
378 pub fn size(&self) -> Result<i32, LibISLError> {
380 let list = self;
381 let isl_rs_ctx = list.get_ctx();
382 let list = list.ptr;
383 let isl_rs_result = unsafe { isl_basic_set_list_size(list) };
384 let err = isl_rs_ctx.last_error();
385 if err != Error::None_ {
386 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
387 }
388 Ok(isl_rs_result)
389 }
390
391 pub fn swap(self, pos1: u32, pos2: u32) -> Result<BasicSetList, LibISLError> {
393 let list = self;
394 let isl_rs_ctx = list.get_ctx();
395 let mut list = list;
396 list.do_not_free_on_drop();
397 let list = list.ptr;
398 let isl_rs_result = unsafe { isl_basic_set_list_swap(list, pos1, pos2) };
399 let isl_rs_result = BasicSetList { ptr: isl_rs_result,
400 should_free_on_drop: true };
401 let err = isl_rs_ctx.last_error();
402 if err != Error::None_ {
403 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
404 }
405 Ok(isl_rs_result)
406 }
407
408 pub fn to_str(&self) -> Result<&str, LibISLError> {
410 let list = self;
411 let isl_rs_ctx = list.get_ctx();
412 let list = list.ptr;
413 let isl_rs_result = unsafe { isl_basic_set_list_to_str(list) };
414 let isl_rs_result = unsafe { CStr::from_ptr(isl_rs_result) };
415 let isl_rs_result = isl_rs_result.to_str().unwrap();
416 let err = isl_rs_ctx.last_error();
417 if err != Error::None_ {
418 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
419 }
420 Ok(isl_rs_result)
421 }
422
423 pub fn do_not_free_on_drop(&mut self) {
426 self.should_free_on_drop = false;
427 }
428}
429
430impl Drop for BasicSetList {
431 fn drop(&mut self) {
432 if self.should_free_on_drop {
433 unsafe {
434 isl_basic_set_list_free(self.ptr);
435 }
436 }
437 }
438}