1use super::{Context, Error, LibISLError, QPolynomial};
5use libc::uintptr_t;
6use std::ffi::CStr;
7use std::os::raw::c_char;
8
9pub struct QPolynomialList {
11 pub ptr: uintptr_t,
12 pub should_free_on_drop: bool,
13}
14
15extern "C" {
16
17 fn isl_qpolynomial_list_add(list: uintptr_t, el: uintptr_t) -> uintptr_t;
18
19 fn isl_qpolynomial_list_alloc(ctx: uintptr_t, n: i32) -> uintptr_t;
20
21 fn isl_qpolynomial_list_clear(list: uintptr_t) -> uintptr_t;
22
23 fn isl_qpolynomial_list_concat(list1: uintptr_t, list2: uintptr_t) -> uintptr_t;
24
25 fn isl_qpolynomial_list_copy(list: uintptr_t) -> uintptr_t;
26
27 fn isl_qpolynomial_list_drop(list: uintptr_t, first: u32, n: u32) -> uintptr_t;
28
29 fn isl_qpolynomial_list_dump(list: uintptr_t) -> ();
30
31 fn isl_qpolynomial_list_free(list: uintptr_t) -> uintptr_t;
32
33 fn isl_qpolynomial_list_from_qpolynomial(el: uintptr_t) -> uintptr_t;
34
35 fn isl_qpolynomial_list_get_at(list: uintptr_t, index: i32) -> uintptr_t;
36
37 fn isl_qpolynomial_list_get_ctx(list: uintptr_t) -> uintptr_t;
38
39 fn isl_qpolynomial_list_get_qpolynomial(list: uintptr_t, index: i32) -> uintptr_t;
40
41 fn isl_qpolynomial_list_insert(list: uintptr_t, pos: u32, el: uintptr_t) -> uintptr_t;
42
43 fn isl_qpolynomial_list_n_qpolynomial(list: uintptr_t) -> i32;
44
45 fn isl_qpolynomial_list_reverse(list: uintptr_t) -> uintptr_t;
46
47 fn isl_qpolynomial_list_set_at(list: uintptr_t, index: i32, el: uintptr_t) -> uintptr_t;
48
49 fn isl_qpolynomial_list_set_qpolynomial(list: uintptr_t, index: i32, el: uintptr_t)
50 -> uintptr_t;
51
52 fn isl_qpolynomial_list_size(list: uintptr_t) -> i32;
53
54 fn isl_qpolynomial_list_swap(list: uintptr_t, pos1: u32, pos2: u32) -> uintptr_t;
55
56 fn isl_qpolynomial_list_to_str(list: uintptr_t) -> *const c_char;
57
58}
59
60impl QPolynomialList {
61 pub fn add(self, el: QPolynomial) -> Result<QPolynomialList, LibISLError> {
63 let list = self;
64 let isl_rs_ctx = list.get_ctx();
65 let mut list = list;
66 list.do_not_free_on_drop();
67 let list = list.ptr;
68 let mut el = el;
69 el.do_not_free_on_drop();
70 let el = el.ptr;
71 let isl_rs_result = unsafe { isl_qpolynomial_list_add(list, el) };
72 let isl_rs_result = QPolynomialList { ptr: isl_rs_result,
73 should_free_on_drop: true };
74 let err = isl_rs_ctx.last_error();
75 if err != Error::None_ {
76 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
77 }
78 Ok(isl_rs_result)
79 }
80
81 pub fn alloc(ctx: &Context, n: i32) -> Result<QPolynomialList, LibISLError> {
83 let isl_rs_ctx = Context { ptr: ctx.ptr,
84 should_free_on_drop: false };
85 let ctx = ctx.ptr;
86 let isl_rs_result = unsafe { isl_qpolynomial_list_alloc(ctx, n) };
87 let isl_rs_result = QPolynomialList { ptr: isl_rs_result,
88 should_free_on_drop: true };
89 let err = isl_rs_ctx.last_error();
90 if err != Error::None_ {
91 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
92 }
93 Ok(isl_rs_result)
94 }
95
96 pub fn clear(self) -> Result<QPolynomialList, LibISLError> {
98 let list = self;
99 let isl_rs_ctx = list.get_ctx();
100 let mut list = list;
101 list.do_not_free_on_drop();
102 let list = list.ptr;
103 let isl_rs_result = unsafe { isl_qpolynomial_list_clear(list) };
104 let isl_rs_result = QPolynomialList { ptr: isl_rs_result,
105 should_free_on_drop: true };
106 let err = isl_rs_ctx.last_error();
107 if err != Error::None_ {
108 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
109 }
110 Ok(isl_rs_result)
111 }
112
113 pub fn concat(self, list2: QPolynomialList) -> Result<QPolynomialList, LibISLError> {
115 let list1 = self;
116 let isl_rs_ctx = list1.get_ctx();
117 let mut list1 = list1;
118 list1.do_not_free_on_drop();
119 let list1 = list1.ptr;
120 let mut list2 = list2;
121 list2.do_not_free_on_drop();
122 let list2 = list2.ptr;
123 let isl_rs_result = unsafe { isl_qpolynomial_list_concat(list1, list2) };
124 let isl_rs_result = QPolynomialList { 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 copy(&self) -> Result<QPolynomialList, LibISLError> {
135 let list = self;
136 let isl_rs_ctx = list.get_ctx();
137 let list = list.ptr;
138 let isl_rs_result = unsafe { isl_qpolynomial_list_copy(list) };
139 let isl_rs_result = QPolynomialList { ptr: isl_rs_result,
140 should_free_on_drop: true };
141 let err = isl_rs_ctx.last_error();
142 if err != Error::None_ {
143 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
144 }
145 Ok(isl_rs_result)
146 }
147
148 pub fn drop(self, first: u32, n: u32) -> Result<QPolynomialList, LibISLError> {
150 let list = self;
151 let isl_rs_ctx = list.get_ctx();
152 let mut list = list;
153 list.do_not_free_on_drop();
154 let list = list.ptr;
155 let isl_rs_result = unsafe { isl_qpolynomial_list_drop(list, first, n) };
156 let isl_rs_result = QPolynomialList { ptr: isl_rs_result,
157 should_free_on_drop: true };
158 let err = isl_rs_ctx.last_error();
159 if err != Error::None_ {
160 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
161 }
162 Ok(isl_rs_result)
163 }
164
165 pub fn dump(&self) -> Result<(), LibISLError> {
167 let list = self;
168 let isl_rs_ctx = list.get_ctx();
169 let list = list.ptr;
170 let isl_rs_result = unsafe { isl_qpolynomial_list_dump(list) };
171 let err = isl_rs_ctx.last_error();
172 if err != Error::None_ {
173 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
174 }
175 Ok(isl_rs_result)
176 }
177
178 pub fn free(self) -> Result<QPolynomialList, LibISLError> {
180 let list = self;
181 let isl_rs_ctx = list.get_ctx();
182 let mut list = list;
183 list.do_not_free_on_drop();
184 let list = list.ptr;
185 let isl_rs_result = unsafe { isl_qpolynomial_list_free(list) };
186 let isl_rs_result = QPolynomialList { ptr: isl_rs_result,
187 should_free_on_drop: true };
188 let err = isl_rs_ctx.last_error();
189 if err != Error::None_ {
190 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
191 }
192 Ok(isl_rs_result)
193 }
194
195 pub fn from_qpolynomial(el: QPolynomial) -> Result<QPolynomialList, LibISLError> {
197 let isl_rs_ctx = el.get_ctx();
198 let mut el = el;
199 el.do_not_free_on_drop();
200 let el = el.ptr;
201 let isl_rs_result = unsafe { isl_qpolynomial_list_from_qpolynomial(el) };
202 let isl_rs_result = QPolynomialList { ptr: isl_rs_result,
203 should_free_on_drop: true };
204 let err = isl_rs_ctx.last_error();
205 if err != Error::None_ {
206 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
207 }
208 Ok(isl_rs_result)
209 }
210
211 pub fn get_at(&self, index: i32) -> Result<QPolynomial, LibISLError> {
213 let list = self;
214 let isl_rs_ctx = list.get_ctx();
215 let list = list.ptr;
216 let isl_rs_result = unsafe { isl_qpolynomial_list_get_at(list, index) };
217 let isl_rs_result = QPolynomial { ptr: isl_rs_result,
218 should_free_on_drop: true };
219 let err = isl_rs_ctx.last_error();
220 if err != Error::None_ {
221 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
222 }
223 Ok(isl_rs_result)
224 }
225
226 pub fn get_ctx(&self) -> Context {
228 let list = self;
229 let list = list.ptr;
230 let isl_rs_result = unsafe { isl_qpolynomial_list_get_ctx(list) };
231 let isl_rs_result = Context { ptr: isl_rs_result,
232 should_free_on_drop: false };
233 isl_rs_result
234 }
235
236 pub fn get_qpolynomial(&self, index: i32) -> Result<QPolynomial, LibISLError> {
238 let list = self;
239 let isl_rs_ctx = list.get_ctx();
240 let list = list.ptr;
241 let isl_rs_result = unsafe { isl_qpolynomial_list_get_qpolynomial(list, index) };
242 let isl_rs_result = QPolynomial { ptr: isl_rs_result,
243 should_free_on_drop: true };
244 let err = isl_rs_ctx.last_error();
245 if err != Error::None_ {
246 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
247 }
248 Ok(isl_rs_result)
249 }
250
251 pub fn insert(self, pos: u32, el: QPolynomial) -> Result<QPolynomialList, LibISLError> {
253 let list = self;
254 let isl_rs_ctx = list.get_ctx();
255 let mut list = list;
256 list.do_not_free_on_drop();
257 let list = list.ptr;
258 let mut el = el;
259 el.do_not_free_on_drop();
260 let el = el.ptr;
261 let isl_rs_result = unsafe { isl_qpolynomial_list_insert(list, pos, el) };
262 let isl_rs_result = QPolynomialList { ptr: isl_rs_result,
263 should_free_on_drop: true };
264 let err = isl_rs_ctx.last_error();
265 if err != Error::None_ {
266 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
267 }
268 Ok(isl_rs_result)
269 }
270
271 pub fn n_qpolynomial(&self) -> Result<i32, LibISLError> {
273 let list = self;
274 let isl_rs_ctx = list.get_ctx();
275 let list = list.ptr;
276 let isl_rs_result = unsafe { isl_qpolynomial_list_n_qpolynomial(list) };
277 let err = isl_rs_ctx.last_error();
278 if err != Error::None_ {
279 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
280 }
281 Ok(isl_rs_result)
282 }
283
284 pub fn reverse(self) -> Result<QPolynomialList, LibISLError> {
286 let list = self;
287 let isl_rs_ctx = list.get_ctx();
288 let mut list = list;
289 list.do_not_free_on_drop();
290 let list = list.ptr;
291 let isl_rs_result = unsafe { isl_qpolynomial_list_reverse(list) };
292 let isl_rs_result = QPolynomialList { ptr: isl_rs_result,
293 should_free_on_drop: true };
294 let err = isl_rs_ctx.last_error();
295 if err != Error::None_ {
296 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
297 }
298 Ok(isl_rs_result)
299 }
300
301 pub fn set_at(self, index: i32, el: QPolynomial) -> Result<QPolynomialList, LibISLError> {
303 let list = self;
304 let isl_rs_ctx = list.get_ctx();
305 let mut list = list;
306 list.do_not_free_on_drop();
307 let list = list.ptr;
308 let mut el = el;
309 el.do_not_free_on_drop();
310 let el = el.ptr;
311 let isl_rs_result = unsafe { isl_qpolynomial_list_set_at(list, index, el) };
312 let isl_rs_result = QPolynomialList { ptr: isl_rs_result,
313 should_free_on_drop: true };
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 set_qpolynomial(self, index: i32, el: QPolynomial)
323 -> Result<QPolynomialList, LibISLError> {
324 let list = self;
325 let isl_rs_ctx = list.get_ctx();
326 let mut list = list;
327 list.do_not_free_on_drop();
328 let list = list.ptr;
329 let mut el = el;
330 el.do_not_free_on_drop();
331 let el = el.ptr;
332 let isl_rs_result = unsafe { isl_qpolynomial_list_set_qpolynomial(list, index, el) };
333 let isl_rs_result = QPolynomialList { ptr: isl_rs_result,
334 should_free_on_drop: true };
335 let err = isl_rs_ctx.last_error();
336 if err != Error::None_ {
337 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
338 }
339 Ok(isl_rs_result)
340 }
341
342 pub fn size(&self) -> Result<i32, LibISLError> {
344 let list = self;
345 let isl_rs_ctx = list.get_ctx();
346 let list = list.ptr;
347 let isl_rs_result = unsafe { isl_qpolynomial_list_size(list) };
348 let err = isl_rs_ctx.last_error();
349 if err != Error::None_ {
350 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
351 }
352 Ok(isl_rs_result)
353 }
354
355 pub fn swap(self, pos1: u32, pos2: u32) -> Result<QPolynomialList, LibISLError> {
357 let list = self;
358 let isl_rs_ctx = list.get_ctx();
359 let mut list = list;
360 list.do_not_free_on_drop();
361 let list = list.ptr;
362 let isl_rs_result = unsafe { isl_qpolynomial_list_swap(list, pos1, pos2) };
363 let isl_rs_result = QPolynomialList { ptr: isl_rs_result,
364 should_free_on_drop: true };
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 pub fn to_str(&self) -> Result<&str, LibISLError> {
374 let list = self;
375 let isl_rs_ctx = list.get_ctx();
376 let list = list.ptr;
377 let isl_rs_result = unsafe { isl_qpolynomial_list_to_str(list) };
378 let isl_rs_result = unsafe { CStr::from_ptr(isl_rs_result) };
379 let isl_rs_result = isl_rs_result.to_str().unwrap();
380 let err = isl_rs_ctx.last_error();
381 if err != Error::None_ {
382 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
383 }
384 Ok(isl_rs_result)
385 }
386
387 pub fn do_not_free_on_drop(&mut self) {
390 self.should_free_on_drop = false;
391 }
392}
393
394impl Drop for QPolynomialList {
395 fn drop(&mut self) {
396 if self.should_free_on_drop {
397 unsafe {
398 isl_qpolynomial_list_free(self.ptr);
399 }
400 }
401 }
402}