1use crate::bindings::{Context, DimType, Space, Val};
5use libc::uintptr_t;
6use std::ffi::{CStr, CString};
7use std::os::raw::c_char;
8
9pub struct Point {
11 pub ptr: uintptr_t,
12 pub should_free_on_drop: bool,
13}
14
15extern "C" {
16
17 fn isl_point_get_ctx(pnt: uintptr_t) -> uintptr_t;
18
19 fn isl_point_get_space(pnt: uintptr_t) -> uintptr_t;
20
21 fn isl_point_zero(space: uintptr_t) -> uintptr_t;
22
23 fn isl_point_copy(pnt: uintptr_t) -> uintptr_t;
24
25 fn isl_point_free(pnt: uintptr_t) -> uintptr_t;
26
27 fn isl_point_get_coordinate_val(pnt: uintptr_t, type_: DimType, pos: i32) -> uintptr_t;
28
29 fn isl_point_set_coordinate_val(pnt: uintptr_t, type_: DimType, pos: i32, v: uintptr_t)
30 -> uintptr_t;
31
32 fn isl_point_add_ui(pnt: uintptr_t, type_: DimType, pos: i32, val: u32) -> uintptr_t;
33
34 fn isl_point_sub_ui(pnt: uintptr_t, type_: DimType, pos: i32, val: u32) -> uintptr_t;
35
36 fn isl_point_void(space: uintptr_t) -> uintptr_t;
37
38 fn isl_point_is_void(pnt: uintptr_t) -> i32;
39
40 fn isl_point_to_str(pnt: uintptr_t) -> *const c_char;
41
42 fn isl_point_dump(pnt: uintptr_t);
43
44}
45
46impl Point {
47 pub fn get_ctx(&self) -> Context {
49 let pnt = self;
50 let pnt = pnt.ptr;
51 let isl_rs_result = unsafe { isl_point_get_ctx(pnt) };
52 let isl_rs_result = Context { ptr: isl_rs_result,
53 should_free_on_drop: true };
54 let mut isl_rs_result = isl_rs_result;
55 isl_rs_result.do_not_free_on_drop();
56 isl_rs_result
57 }
58
59 pub fn get_space(&self) -> Space {
61 let pnt = self;
62 let pnt = pnt.ptr;
63 let isl_rs_result = unsafe { isl_point_get_space(pnt) };
64 let isl_rs_result = Space { ptr: isl_rs_result,
65 should_free_on_drop: true };
66 isl_rs_result
67 }
68
69 pub fn zero(space: Space) -> Point {
71 let mut space = space;
72 space.do_not_free_on_drop();
73 let space = space.ptr;
74 let isl_rs_result = unsafe { isl_point_zero(space) };
75 let isl_rs_result = Point { ptr: isl_rs_result,
76 should_free_on_drop: true };
77 isl_rs_result
78 }
79
80 pub fn copy(&self) -> Point {
82 let pnt = self;
83 let pnt = pnt.ptr;
84 let isl_rs_result = unsafe { isl_point_copy(pnt) };
85 let isl_rs_result = Point { ptr: isl_rs_result,
86 should_free_on_drop: true };
87 isl_rs_result
88 }
89
90 pub fn free(self) -> Point {
92 let pnt = self;
93 let mut pnt = pnt;
94 pnt.do_not_free_on_drop();
95 let pnt = pnt.ptr;
96 let isl_rs_result = unsafe { isl_point_free(pnt) };
97 let isl_rs_result = Point { ptr: isl_rs_result,
98 should_free_on_drop: true };
99 isl_rs_result
100 }
101
102 pub fn get_coordinate_val(&self, type_: DimType, pos: i32) -> Val {
104 let pnt = self;
105 let pnt = pnt.ptr;
106 let isl_rs_result = unsafe { isl_point_get_coordinate_val(pnt, type_, pos) };
107 let isl_rs_result = Val { ptr: isl_rs_result,
108 should_free_on_drop: true };
109 isl_rs_result
110 }
111
112 pub fn set_coordinate_val(self, type_: DimType, pos: i32, v: Val) -> Point {
114 let pnt = self;
115 let mut pnt = pnt;
116 pnt.do_not_free_on_drop();
117 let pnt = pnt.ptr;
118 let mut v = v;
119 v.do_not_free_on_drop();
120 let v = v.ptr;
121 let isl_rs_result = unsafe { isl_point_set_coordinate_val(pnt, type_, pos, v) };
122 let isl_rs_result = Point { ptr: isl_rs_result,
123 should_free_on_drop: true };
124 isl_rs_result
125 }
126
127 pub fn add_ui(self, type_: DimType, pos: i32, val: u32) -> Point {
129 let pnt = self;
130 let mut pnt = pnt;
131 pnt.do_not_free_on_drop();
132 let pnt = pnt.ptr;
133 let isl_rs_result = unsafe { isl_point_add_ui(pnt, type_, pos, val) };
134 let isl_rs_result = Point { ptr: isl_rs_result,
135 should_free_on_drop: true };
136 isl_rs_result
137 }
138
139 pub fn sub_ui(self, type_: DimType, pos: i32, val: u32) -> Point {
141 let pnt = self;
142 let mut pnt = pnt;
143 pnt.do_not_free_on_drop();
144 let pnt = pnt.ptr;
145 let isl_rs_result = unsafe { isl_point_sub_ui(pnt, type_, pos, val) };
146 let isl_rs_result = Point { ptr: isl_rs_result,
147 should_free_on_drop: true };
148 isl_rs_result
149 }
150
151 pub fn void(space: Space) -> Point {
153 let mut space = space;
154 space.do_not_free_on_drop();
155 let space = space.ptr;
156 let isl_rs_result = unsafe { isl_point_void(space) };
157 let isl_rs_result = Point { ptr: isl_rs_result,
158 should_free_on_drop: true };
159 isl_rs_result
160 }
161
162 pub fn is_void(&self) -> bool {
164 let pnt = self;
165 let pnt = pnt.ptr;
166 let isl_rs_result = unsafe { isl_point_is_void(pnt) };
167 let isl_rs_result = match isl_rs_result {
168 0 => false,
169 1 => true,
170 _ => panic!("Got isl_bool = -1"),
171 };
172 isl_rs_result
173 }
174
175 pub fn to_str(&self) -> &str {
177 let pnt = self;
178 let pnt = pnt.ptr;
179 let isl_rs_result = unsafe { isl_point_to_str(pnt) };
180 let isl_rs_result = unsafe { CStr::from_ptr(isl_rs_result) };
181 let isl_rs_result = isl_rs_result.to_str().unwrap();
182 isl_rs_result
183 }
184
185 pub fn dump(&self) {
187 let pnt = self;
188 let pnt = pnt.ptr;
189 let isl_rs_result = unsafe { isl_point_dump(pnt) };
190 isl_rs_result
191 }
192
193 pub fn do_not_free_on_drop(&mut self) {
195 self.should_free_on_drop = false;
196 }
197}
198
199impl Drop for Point {
200 fn drop(&mut self) {
201 if self.should_free_on_drop {
202 unsafe {
203 isl_point_free(self.ptr);
204 }
205 }
206 }
207}