isl_rs/bindings/
fixed_box.rs

1// Automatically generated by isl_bindings_generator.
2// LICENSE: MIT
3
4use crate::bindings::{Context, Space};
5use libc::uintptr_t;
6use std::ffi::{CStr, CString};
7use std::os::raw::c_char;
8
9/// Wraps `isl_fixed_box`.
10pub struct FixedBox {
11    pub ptr: uintptr_t,
12    pub should_free_on_drop: bool,
13}
14
15extern "C" {
16
17    fn isl_fixed_box_get_ctx(box_: uintptr_t) -> uintptr_t;
18
19    fn isl_fixed_box_get_space(box_: uintptr_t) -> uintptr_t;
20
21    fn isl_fixed_box_is_valid(box_: uintptr_t) -> i32;
22
23    fn isl_fixed_box_copy(box_: uintptr_t) -> uintptr_t;
24
25    fn isl_fixed_box_free(box_: uintptr_t) -> uintptr_t;
26
27    fn isl_fixed_box_to_str(box_: uintptr_t) -> *const c_char;
28
29    fn isl_fixed_box_dump(box_: uintptr_t);
30
31}
32
33impl FixedBox {
34    /// Wraps `isl_fixed_box_get_ctx`.
35    pub fn get_ctx(&self) -> Context {
36        let box_ = self;
37        let box_ = box_.ptr;
38        let isl_rs_result = unsafe { isl_fixed_box_get_ctx(box_) };
39        let isl_rs_result = Context { ptr: isl_rs_result,
40                                      should_free_on_drop: true };
41        let mut isl_rs_result = isl_rs_result;
42        isl_rs_result.do_not_free_on_drop();
43        isl_rs_result
44    }
45
46    /// Wraps `isl_fixed_box_get_space`.
47    pub fn get_space(&self) -> Space {
48        let box_ = self;
49        let box_ = box_.ptr;
50        let isl_rs_result = unsafe { isl_fixed_box_get_space(box_) };
51        let isl_rs_result = Space { ptr: isl_rs_result,
52                                    should_free_on_drop: true };
53        isl_rs_result
54    }
55
56    /// Wraps `isl_fixed_box_is_valid`.
57    pub fn is_valid(&self) -> bool {
58        let box_ = self;
59        let box_ = box_.ptr;
60        let isl_rs_result = unsafe { isl_fixed_box_is_valid(box_) };
61        let isl_rs_result = match isl_rs_result {
62            0 => false,
63            1 => true,
64            _ => panic!("Got isl_bool = -1"),
65        };
66        isl_rs_result
67    }
68
69    /// Wraps `isl_fixed_box_copy`.
70    pub fn copy(&self) -> FixedBox {
71        let box_ = self;
72        let box_ = box_.ptr;
73        let isl_rs_result = unsafe { isl_fixed_box_copy(box_) };
74        let isl_rs_result = FixedBox { ptr: isl_rs_result,
75                                       should_free_on_drop: true };
76        isl_rs_result
77    }
78
79    /// Wraps `isl_fixed_box_free`.
80    pub fn free(self) -> FixedBox {
81        let box_ = self;
82        let mut box_ = box_;
83        box_.do_not_free_on_drop();
84        let box_ = box_.ptr;
85        let isl_rs_result = unsafe { isl_fixed_box_free(box_) };
86        let isl_rs_result = FixedBox { ptr: isl_rs_result,
87                                       should_free_on_drop: true };
88        isl_rs_result
89    }
90
91    /// Wraps `isl_fixed_box_to_str`.
92    pub fn to_str(&self) -> &str {
93        let box_ = self;
94        let box_ = box_.ptr;
95        let isl_rs_result = unsafe { isl_fixed_box_to_str(box_) };
96        let isl_rs_result = unsafe { CStr::from_ptr(isl_rs_result) };
97        let isl_rs_result = isl_rs_result.to_str().unwrap();
98        isl_rs_result
99    }
100
101    /// Wraps `isl_fixed_box_dump`.
102    pub fn dump(&self) {
103        let box_ = self;
104        let box_ = box_.ptr;
105        let isl_rs_result = unsafe { isl_fixed_box_dump(box_) };
106        isl_rs_result
107    }
108
109    /// Does not call isl_xxx_free() on being dropped. (For internal use only.)
110    pub fn do_not_free_on_drop(&mut self) {
111        self.should_free_on_drop = false;
112    }
113}
114
115impl Drop for FixedBox {
116    fn drop(&mut self) {
117        if self.should_free_on_drop {
118            unsafe {
119                isl_fixed_box_free(self.ptr);
120            }
121        }
122    }
123}