isl_rs/bindings/
vertices.rs

1// Automatically generated by isl_bindings_generator.
2// LICENSE: MIT
3
4use super::{Context, Error, LibISLError};
5use libc::uintptr_t;
6
7/// Wraps `isl_vertices`.
8pub struct Vertices {
9    pub ptr: uintptr_t,
10    pub should_free_on_drop: bool,
11}
12
13extern "C" {
14
15    fn isl_vertices_free(vertices: uintptr_t) -> uintptr_t;
16
17    fn isl_vertices_get_ctx(vertices: uintptr_t) -> uintptr_t;
18
19    fn isl_vertices_get_n_vertices(vertices: uintptr_t) -> i32;
20
21}
22
23impl Vertices {
24    /// Wraps `isl_vertices_free`.
25    pub fn free(self) -> Result<Vertices, LibISLError> {
26        let vertices = self;
27        let isl_rs_ctx = vertices.get_ctx();
28        let mut vertices = vertices;
29        vertices.do_not_free_on_drop();
30        let vertices = vertices.ptr;
31        let isl_rs_result = unsafe { isl_vertices_free(vertices) };
32        let isl_rs_result = Vertices { ptr: isl_rs_result,
33                                       should_free_on_drop: true };
34        let err = isl_rs_ctx.last_error();
35        if err != Error::None_ {
36            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
37        }
38        Ok(isl_rs_result)
39    }
40
41    /// Wraps `isl_vertices_get_ctx`.
42    pub fn get_ctx(&self) -> Context {
43        let vertices = self;
44        let vertices = vertices.ptr;
45        let isl_rs_result = unsafe { isl_vertices_get_ctx(vertices) };
46        let isl_rs_result = Context { ptr: isl_rs_result,
47                                      should_free_on_drop: false };
48        isl_rs_result
49    }
50
51    /// Wraps `isl_vertices_get_n_vertices`.
52    pub fn get_n_vertices(&self) -> Result<i32, LibISLError> {
53        let vertices = self;
54        let isl_rs_ctx = vertices.get_ctx();
55        let vertices = vertices.ptr;
56        let isl_rs_result = unsafe { isl_vertices_get_n_vertices(vertices) };
57        let err = isl_rs_ctx.last_error();
58        if err != Error::None_ {
59            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
60        }
61        Ok(isl_rs_result)
62    }
63
64    /// Does not call isl_vertices_free() on being dropped. (For internal use
65    /// only.)
66    pub fn do_not_free_on_drop(&mut self) {
67        self.should_free_on_drop = false;
68    }
69}
70
71impl Drop for Vertices {
72    fn drop(&mut self) {
73        if self.should_free_on_drop {
74            unsafe {
75                isl_vertices_free(self.ptr);
76            }
77        }
78    }
79}