1use super::{Context, Error, LibISLError, PwQPolynomialFold};
5use libc::uintptr_t;
6use std::ffi::CStr;
7use std::os::raw::c_char;
8
9pub struct PwQPolynomialFoldList {
11 pub ptr: uintptr_t,
12 pub should_free_on_drop: bool,
13}
14
15extern "C" {
16
17 fn isl_pw_qpolynomial_fold_list_add(list: uintptr_t, el: uintptr_t) -> uintptr_t;
18
19 fn isl_pw_qpolynomial_fold_list_alloc(ctx: uintptr_t, n: i32) -> uintptr_t;
20
21 fn isl_pw_qpolynomial_fold_list_clear(list: uintptr_t) -> uintptr_t;
22
23 fn isl_pw_qpolynomial_fold_list_concat(list1: uintptr_t, list2: uintptr_t) -> uintptr_t;
24
25 fn isl_pw_qpolynomial_fold_list_copy(list: uintptr_t) -> uintptr_t;
26
27 fn isl_pw_qpolynomial_fold_list_drop(list: uintptr_t, first: u32, n: u32) -> uintptr_t;
28
29 fn isl_pw_qpolynomial_fold_list_dump(list: uintptr_t) -> ();
30
31 fn isl_pw_qpolynomial_fold_list_free(list: uintptr_t) -> uintptr_t;
32
33 fn isl_pw_qpolynomial_fold_list_from_pw_qpolynomial_fold(el: uintptr_t) -> uintptr_t;
34
35 fn isl_pw_qpolynomial_fold_list_get_at(list: uintptr_t, index: i32) -> uintptr_t;
36
37 fn isl_pw_qpolynomial_fold_list_get_ctx(list: uintptr_t) -> uintptr_t;
38
39 fn isl_pw_qpolynomial_fold_list_get_pw_qpolynomial_fold(list: uintptr_t, index: i32)
40 -> uintptr_t;
41
42 fn isl_pw_qpolynomial_fold_list_insert(list: uintptr_t, pos: u32, el: uintptr_t) -> uintptr_t;
43
44 fn isl_pw_qpolynomial_fold_list_n_pw_qpolynomial_fold(list: uintptr_t) -> i32;
45
46 fn isl_pw_qpolynomial_fold_list_reverse(list: uintptr_t) -> uintptr_t;
47
48 fn isl_pw_qpolynomial_fold_list_set_at(list: uintptr_t, index: i32, el: uintptr_t)
49 -> uintptr_t;
50
51 fn isl_pw_qpolynomial_fold_list_set_pw_qpolynomial_fold(list: uintptr_t, index: i32,
52 el: uintptr_t)
53 -> uintptr_t;
54
55 fn isl_pw_qpolynomial_fold_list_size(list: uintptr_t) -> i32;
56
57 fn isl_pw_qpolynomial_fold_list_swap(list: uintptr_t, pos1: u32, pos2: u32) -> uintptr_t;
58
59 fn isl_pw_qpolynomial_fold_list_to_str(list: uintptr_t) -> *const c_char;
60
61}
62
63impl PwQPolynomialFoldList {
64 pub fn add(self, el: PwQPolynomialFold) -> Result<PwQPolynomialFoldList, 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_pw_qpolynomial_fold_list_add(list, el) };
75 let isl_rs_result = PwQPolynomialFoldList { 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<PwQPolynomialFoldList, 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_pw_qpolynomial_fold_list_alloc(ctx, n) };
90 let isl_rs_result = PwQPolynomialFoldList { 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<PwQPolynomialFoldList, 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_pw_qpolynomial_fold_list_clear(list) };
107 let isl_rs_result = PwQPolynomialFoldList { 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 concat(self, list2: PwQPolynomialFoldList)
118 -> Result<PwQPolynomialFoldList, LibISLError> {
119 let list1 = self;
120 let isl_rs_ctx = list1.get_ctx();
121 let mut list1 = list1;
122 list1.do_not_free_on_drop();
123 let list1 = list1.ptr;
124 let mut list2 = list2;
125 list2.do_not_free_on_drop();
126 let list2 = list2.ptr;
127 let isl_rs_result = unsafe { isl_pw_qpolynomial_fold_list_concat(list1, list2) };
128 let isl_rs_result = PwQPolynomialFoldList { ptr: isl_rs_result,
129 should_free_on_drop: true };
130 let err = isl_rs_ctx.last_error();
131 if err != Error::None_ {
132 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
133 }
134 Ok(isl_rs_result)
135 }
136
137 pub fn copy(&self) -> Result<PwQPolynomialFoldList, LibISLError> {
139 let list = self;
140 let isl_rs_ctx = list.get_ctx();
141 let list = list.ptr;
142 let isl_rs_result = unsafe { isl_pw_qpolynomial_fold_list_copy(list) };
143 let isl_rs_result = PwQPolynomialFoldList { ptr: isl_rs_result,
144 should_free_on_drop: true };
145 let err = isl_rs_ctx.last_error();
146 if err != Error::None_ {
147 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
148 }
149 Ok(isl_rs_result)
150 }
151
152 pub fn drop(self, first: u32, n: u32) -> Result<PwQPolynomialFoldList, LibISLError> {
154 let list = self;
155 let isl_rs_ctx = list.get_ctx();
156 let mut list = list;
157 list.do_not_free_on_drop();
158 let list = list.ptr;
159 let isl_rs_result = unsafe { isl_pw_qpolynomial_fold_list_drop(list, first, n) };
160 let isl_rs_result = PwQPolynomialFoldList { ptr: isl_rs_result,
161 should_free_on_drop: true };
162 let err = isl_rs_ctx.last_error();
163 if err != Error::None_ {
164 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
165 }
166 Ok(isl_rs_result)
167 }
168
169 pub fn dump(&self) -> Result<(), LibISLError> {
171 let list = self;
172 let isl_rs_ctx = list.get_ctx();
173 let list = list.ptr;
174 let isl_rs_result = unsafe { isl_pw_qpolynomial_fold_list_dump(list) };
175 let err = isl_rs_ctx.last_error();
176 if err != Error::None_ {
177 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
178 }
179 Ok(isl_rs_result)
180 }
181
182 pub fn free(self) -> Result<PwQPolynomialFoldList, LibISLError> {
184 let list = self;
185 let isl_rs_ctx = list.get_ctx();
186 let mut list = list;
187 list.do_not_free_on_drop();
188 let list = list.ptr;
189 let isl_rs_result = unsafe { isl_pw_qpolynomial_fold_list_free(list) };
190 let isl_rs_result = PwQPolynomialFoldList { ptr: isl_rs_result,
191 should_free_on_drop: true };
192 let err = isl_rs_ctx.last_error();
193 if err != Error::None_ {
194 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
195 }
196 Ok(isl_rs_result)
197 }
198
199 pub fn from_pw_qpolynomial_fold(el: PwQPolynomialFold)
201 -> Result<PwQPolynomialFoldList, LibISLError> {
202 let isl_rs_ctx = el.get_ctx();
203 let mut el = el;
204 el.do_not_free_on_drop();
205 let el = el.ptr;
206 let isl_rs_result = unsafe { isl_pw_qpolynomial_fold_list_from_pw_qpolynomial_fold(el) };
207 let isl_rs_result = PwQPolynomialFoldList { ptr: isl_rs_result,
208 should_free_on_drop: true };
209 let err = isl_rs_ctx.last_error();
210 if err != Error::None_ {
211 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
212 }
213 Ok(isl_rs_result)
214 }
215
216 pub fn get_at(&self, index: i32) -> Result<PwQPolynomialFold, LibISLError> {
218 let list = self;
219 let isl_rs_ctx = list.get_ctx();
220 let list = list.ptr;
221 let isl_rs_result = unsafe { isl_pw_qpolynomial_fold_list_get_at(list, index) };
222 let isl_rs_result = PwQPolynomialFold { 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_ctx(&self) -> Context {
233 let list = self;
234 let list = list.ptr;
235 let isl_rs_result = unsafe { isl_pw_qpolynomial_fold_list_get_ctx(list) };
236 let isl_rs_result = Context { ptr: isl_rs_result,
237 should_free_on_drop: false };
238 isl_rs_result
239 }
240
241 pub fn get_pw_qpolynomial_fold(&self, index: i32) -> Result<PwQPolynomialFold, LibISLError> {
243 let list = self;
244 let isl_rs_ctx = list.get_ctx();
245 let list = list.ptr;
246 let isl_rs_result =
247 unsafe { isl_pw_qpolynomial_fold_list_get_pw_qpolynomial_fold(list, index) };
248 let isl_rs_result = PwQPolynomialFold { ptr: isl_rs_result,
249 should_free_on_drop: true };
250 let err = isl_rs_ctx.last_error();
251 if err != Error::None_ {
252 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
253 }
254 Ok(isl_rs_result)
255 }
256
257 pub fn insert(self, pos: u32, el: PwQPolynomialFold)
259 -> Result<PwQPolynomialFoldList, LibISLError> {
260 let list = self;
261 let isl_rs_ctx = list.get_ctx();
262 let mut list = list;
263 list.do_not_free_on_drop();
264 let list = list.ptr;
265 let mut el = el;
266 el.do_not_free_on_drop();
267 let el = el.ptr;
268 let isl_rs_result = unsafe { isl_pw_qpolynomial_fold_list_insert(list, pos, el) };
269 let isl_rs_result = PwQPolynomialFoldList { ptr: isl_rs_result,
270 should_free_on_drop: true };
271 let err = isl_rs_ctx.last_error();
272 if err != Error::None_ {
273 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
274 }
275 Ok(isl_rs_result)
276 }
277
278 pub fn n_pw_qpolynomial_fold(&self) -> Result<i32, LibISLError> {
280 let list = self;
281 let isl_rs_ctx = list.get_ctx();
282 let list = list.ptr;
283 let isl_rs_result = unsafe { isl_pw_qpolynomial_fold_list_n_pw_qpolynomial_fold(list) };
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 reverse(self) -> Result<PwQPolynomialFoldList, 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_pw_qpolynomial_fold_list_reverse(list) };
299 let isl_rs_result = PwQPolynomialFoldList { 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 set_at(self, index: i32, el: PwQPolynomialFold)
310 -> Result<PwQPolynomialFoldList, LibISLError> {
311 let list = self;
312 let isl_rs_ctx = list.get_ctx();
313 let mut list = list;
314 list.do_not_free_on_drop();
315 let list = list.ptr;
316 let mut el = el;
317 el.do_not_free_on_drop();
318 let el = el.ptr;
319 let isl_rs_result = unsafe { isl_pw_qpolynomial_fold_list_set_at(list, index, el) };
320 let isl_rs_result = PwQPolynomialFoldList { ptr: isl_rs_result,
321 should_free_on_drop: true };
322 let err = isl_rs_ctx.last_error();
323 if err != Error::None_ {
324 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
325 }
326 Ok(isl_rs_result)
327 }
328
329 pub fn set_pw_qpolynomial_fold(self, index: i32, el: PwQPolynomialFold)
331 -> Result<PwQPolynomialFoldList, LibISLError> {
332 let list = self;
333 let isl_rs_ctx = list.get_ctx();
334 let mut list = list;
335 list.do_not_free_on_drop();
336 let list = list.ptr;
337 let mut el = el;
338 el.do_not_free_on_drop();
339 let el = el.ptr;
340 let isl_rs_result =
341 unsafe { isl_pw_qpolynomial_fold_list_set_pw_qpolynomial_fold(list, index, el) };
342 let isl_rs_result = PwQPolynomialFoldList { ptr: isl_rs_result,
343 should_free_on_drop: true };
344 let err = isl_rs_ctx.last_error();
345 if err != Error::None_ {
346 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
347 }
348 Ok(isl_rs_result)
349 }
350
351 pub fn size(&self) -> Result<i32, LibISLError> {
353 let list = self;
354 let isl_rs_ctx = list.get_ctx();
355 let list = list.ptr;
356 let isl_rs_result = unsafe { isl_pw_qpolynomial_fold_list_size(list) };
357 let err = isl_rs_ctx.last_error();
358 if err != Error::None_ {
359 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
360 }
361 Ok(isl_rs_result)
362 }
363
364 pub fn swap(self, pos1: u32, pos2: u32) -> Result<PwQPolynomialFoldList, LibISLError> {
366 let list = self;
367 let isl_rs_ctx = list.get_ctx();
368 let mut list = list;
369 list.do_not_free_on_drop();
370 let list = list.ptr;
371 let isl_rs_result = unsafe { isl_pw_qpolynomial_fold_list_swap(list, pos1, pos2) };
372 let isl_rs_result = PwQPolynomialFoldList { ptr: isl_rs_result,
373 should_free_on_drop: true };
374 let err = isl_rs_ctx.last_error();
375 if err != Error::None_ {
376 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
377 }
378 Ok(isl_rs_result)
379 }
380
381 pub fn to_str(&self) -> Result<&str, LibISLError> {
383 let list = self;
384 let isl_rs_ctx = list.get_ctx();
385 let list = list.ptr;
386 let isl_rs_result = unsafe { isl_pw_qpolynomial_fold_list_to_str(list) };
387 let isl_rs_result = unsafe { CStr::from_ptr(isl_rs_result) };
388 let isl_rs_result = isl_rs_result.to_str().unwrap();
389 let err = isl_rs_ctx.last_error();
390 if err != Error::None_ {
391 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
392 }
393 Ok(isl_rs_result)
394 }
395
396 pub fn do_not_free_on_drop(&mut self) {
399 self.should_free_on_drop = false;
400 }
401}
402
403impl Drop for PwQPolynomialFoldList {
404 fn drop(&mut self) {
405 if self.should_free_on_drop {
406 unsafe {
407 isl_pw_qpolynomial_fold_list_free(self.ptr);
408 }
409 }
410 }
411}