isl-rs 0.3.1

Rust bindings for Integer Set Library
Documentation
// Automatically generated by isl_bindings_generator.
// LICENSE: MIT

use super::{Context, DimType, Error, LibISLError, MultiVal, Set, Space, Val};
use libc::uintptr_t;
use std::ffi::CStr;
use std::os::raw::c_char;

/// Wraps `isl_point`.
pub struct Point {
    pub ptr: uintptr_t,
    pub should_free_on_drop: bool,
}

extern "C" {

    fn isl_point_add_ui(pnt: uintptr_t, type_: i32, pos: i32, val: u32) -> uintptr_t;

    fn isl_point_copy(pnt: uintptr_t) -> uintptr_t;

    fn isl_point_dump(pnt: uintptr_t) -> ();

    fn isl_point_free(pnt: uintptr_t) -> uintptr_t;

    fn isl_point_get_coordinate_val(pnt: uintptr_t, type_: i32, pos: i32) -> uintptr_t;

    fn isl_point_get_ctx(pnt: uintptr_t) -> uintptr_t;

    fn isl_point_get_multi_val(pnt: uintptr_t) -> uintptr_t;

    fn isl_point_get_space(pnt: uintptr_t) -> uintptr_t;

    fn isl_point_is_void(pnt: uintptr_t) -> i32;

    fn isl_point_set_coordinate_val(pnt: uintptr_t, type_: i32, pos: i32, v: uintptr_t)
                                    -> uintptr_t;

    fn isl_point_sub_ui(pnt: uintptr_t, type_: i32, pos: i32, val: u32) -> uintptr_t;

    fn isl_point_to_set(pnt: uintptr_t) -> uintptr_t;

    fn isl_point_to_str(pnt: uintptr_t) -> *const c_char;

    fn isl_point_void(space: uintptr_t) -> uintptr_t;

    fn isl_point_zero(space: uintptr_t) -> uintptr_t;

}

impl Point {
    /// Wraps `isl_point_add_ui`.
    pub fn add_ui(self, type_: DimType, pos: i32, val: u32) -> Result<Point, LibISLError> {
        let pnt = self;
        let isl_rs_ctx = pnt.get_ctx();
        let mut pnt = pnt;
        pnt.do_not_free_on_drop();
        let pnt = pnt.ptr;
        let type_ = type_.to_i32();
        let isl_rs_result = unsafe { isl_point_add_ui(pnt, type_, pos, val) };
        let isl_rs_result = Point { ptr: isl_rs_result,
                                    should_free_on_drop: true };
        let err = isl_rs_ctx.last_error();
        if err != Error::None_ {
            let err_msg = isl_rs_ctx.last_error_msg();
            isl_rs_ctx.reset_error();
            return Err(LibISLError::new(err, err_msg));
        }
        Ok(isl_rs_result)
    }

    /// Wraps `isl_point_copy`.
    pub fn copy(&self) -> Result<Point, LibISLError> {
        let pnt = self;
        let isl_rs_ctx = pnt.get_ctx();
        let pnt = pnt.ptr;
        let isl_rs_result = unsafe { isl_point_copy(pnt) };
        let isl_rs_result = Point { ptr: isl_rs_result,
                                    should_free_on_drop: true };
        let err = isl_rs_ctx.last_error();
        if err != Error::None_ {
            let err_msg = isl_rs_ctx.last_error_msg();
            isl_rs_ctx.reset_error();
            return Err(LibISLError::new(err, err_msg));
        }
        Ok(isl_rs_result)
    }

    /// Wraps `isl_point_dump`.
    pub fn dump(&self) -> Result<(), LibISLError> {
        let pnt = self;
        let isl_rs_ctx = pnt.get_ctx();
        let pnt = pnt.ptr;
        let isl_rs_result = unsafe { isl_point_dump(pnt) };
        let err = isl_rs_ctx.last_error();
        if err != Error::None_ {
            let err_msg = isl_rs_ctx.last_error_msg();
            isl_rs_ctx.reset_error();
            return Err(LibISLError::new(err, err_msg));
        }
        Ok(isl_rs_result)
    }

    /// Wraps `isl_point_free`.
    pub fn free(self) -> Result<Point, LibISLError> {
        let pnt = self;
        let isl_rs_ctx = pnt.get_ctx();
        let mut pnt = pnt;
        pnt.do_not_free_on_drop();
        let pnt = pnt.ptr;
        let isl_rs_result = unsafe { isl_point_free(pnt) };
        let isl_rs_result = Point { ptr: isl_rs_result,
                                    should_free_on_drop: true };
        let err = isl_rs_ctx.last_error();
        if err != Error::None_ {
            let err_msg = isl_rs_ctx.last_error_msg();
            isl_rs_ctx.reset_error();
            return Err(LibISLError::new(err, err_msg));
        }
        Ok(isl_rs_result)
    }

    /// Wraps `isl_point_get_coordinate_val`.
    pub fn get_coordinate_val(&self, type_: DimType, pos: i32) -> Result<Val, LibISLError> {
        let pnt = self;
        let isl_rs_ctx = pnt.get_ctx();
        let pnt = pnt.ptr;
        let type_ = type_.to_i32();
        let isl_rs_result = unsafe { isl_point_get_coordinate_val(pnt, type_, pos) };
        let isl_rs_result = Val { ptr: isl_rs_result,
                                  should_free_on_drop: true };
        let err = isl_rs_ctx.last_error();
        if err != Error::None_ {
            let err_msg = isl_rs_ctx.last_error_msg();
            isl_rs_ctx.reset_error();
            return Err(LibISLError::new(err, err_msg));
        }
        Ok(isl_rs_result)
    }

    /// Wraps `isl_point_get_ctx`.
    pub fn get_ctx(&self) -> Context {
        let pnt = self;
        let pnt = pnt.ptr;
        let isl_rs_result = unsafe { isl_point_get_ctx(pnt) };
        let isl_rs_result = Context { ptr: isl_rs_result,
                                      should_free_on_drop: false };
        isl_rs_result
    }

    /// Wraps `isl_point_get_multi_val`.
    pub fn get_multi_val(&self) -> Result<MultiVal, LibISLError> {
        let pnt = self;
        let isl_rs_ctx = pnt.get_ctx();
        let pnt = pnt.ptr;
        let isl_rs_result = unsafe { isl_point_get_multi_val(pnt) };
        let isl_rs_result = MultiVal { ptr: isl_rs_result,
                                       should_free_on_drop: true };
        let err = isl_rs_ctx.last_error();
        if err != Error::None_ {
            let err_msg = isl_rs_ctx.last_error_msg();
            isl_rs_ctx.reset_error();
            return Err(LibISLError::new(err, err_msg));
        }
        Ok(isl_rs_result)
    }

    /// Wraps `isl_point_get_space`.
    pub fn get_space(&self) -> Result<Space, LibISLError> {
        let pnt = self;
        let isl_rs_ctx = pnt.get_ctx();
        let pnt = pnt.ptr;
        let isl_rs_result = unsafe { isl_point_get_space(pnt) };
        let isl_rs_result = Space { ptr: isl_rs_result,
                                    should_free_on_drop: true };
        let err = isl_rs_ctx.last_error();
        if err != Error::None_ {
            let err_msg = isl_rs_ctx.last_error_msg();
            isl_rs_ctx.reset_error();
            return Err(LibISLError::new(err, err_msg));
        }
        Ok(isl_rs_result)
    }

    /// Wraps `isl_point_is_void`.
    pub fn is_void(&self) -> Result<bool, LibISLError> {
        let pnt = self;
        let isl_rs_ctx = pnt.get_ctx();
        let pnt = pnt.ptr;
        let isl_rs_result = unsafe { isl_point_is_void(pnt) };
        let isl_rs_result = match isl_rs_result {
            0 => false,
            1 => true,
            _ => {
                return Err(LibISLError::new(Error::Unknown, "Got isl_bool = -1"));
            }
        };
        let err = isl_rs_ctx.last_error();
        if err != Error::None_ {
            let err_msg = isl_rs_ctx.last_error_msg();
            isl_rs_ctx.reset_error();
            return Err(LibISLError::new(err, err_msg));
        }
        Ok(isl_rs_result)
    }

    /// Wraps `isl_point_set_coordinate_val`.
    pub fn set_coordinate_val(self, type_: DimType, pos: i32, v: Val)
                              -> Result<Point, LibISLError> {
        let pnt = self;
        let isl_rs_ctx = pnt.get_ctx();
        let mut pnt = pnt;
        pnt.do_not_free_on_drop();
        let pnt = pnt.ptr;
        let type_ = type_.to_i32();
        let mut v = v;
        v.do_not_free_on_drop();
        let v = v.ptr;
        let isl_rs_result = unsafe { isl_point_set_coordinate_val(pnt, type_, pos, v) };
        let isl_rs_result = Point { ptr: isl_rs_result,
                                    should_free_on_drop: true };
        let err = isl_rs_ctx.last_error();
        if err != Error::None_ {
            let err_msg = isl_rs_ctx.last_error_msg();
            isl_rs_ctx.reset_error();
            return Err(LibISLError::new(err, err_msg));
        }
        Ok(isl_rs_result)
    }

    /// Wraps `isl_point_sub_ui`.
    pub fn sub_ui(self, type_: DimType, pos: i32, val: u32) -> Result<Point, LibISLError> {
        let pnt = self;
        let isl_rs_ctx = pnt.get_ctx();
        let mut pnt = pnt;
        pnt.do_not_free_on_drop();
        let pnt = pnt.ptr;
        let type_ = type_.to_i32();
        let isl_rs_result = unsafe { isl_point_sub_ui(pnt, type_, pos, val) };
        let isl_rs_result = Point { ptr: isl_rs_result,
                                    should_free_on_drop: true };
        let err = isl_rs_ctx.last_error();
        if err != Error::None_ {
            let err_msg = isl_rs_ctx.last_error_msg();
            isl_rs_ctx.reset_error();
            return Err(LibISLError::new(err, err_msg));
        }
        Ok(isl_rs_result)
    }

    /// Wraps `isl_point_to_set`.
    pub fn to_set(self) -> Result<Set, LibISLError> {
        let pnt = self;
        let isl_rs_ctx = pnt.get_ctx();
        let mut pnt = pnt;
        pnt.do_not_free_on_drop();
        let pnt = pnt.ptr;
        let isl_rs_result = unsafe { isl_point_to_set(pnt) };
        let isl_rs_result = Set { ptr: isl_rs_result,
                                  should_free_on_drop: true };
        let err = isl_rs_ctx.last_error();
        if err != Error::None_ {
            let err_msg = isl_rs_ctx.last_error_msg();
            isl_rs_ctx.reset_error();
            return Err(LibISLError::new(err, err_msg));
        }
        Ok(isl_rs_result)
    }

    /// Wraps `isl_point_to_str`.
    pub fn to_str(&self) -> Result<&str, LibISLError> {
        let pnt = self;
        let isl_rs_ctx = pnt.get_ctx();
        let pnt = pnt.ptr;
        let isl_rs_result = unsafe { isl_point_to_str(pnt) };
        let isl_rs_result = unsafe { CStr::from_ptr(isl_rs_result) };
        let isl_rs_result = isl_rs_result.to_str().unwrap();
        let err = isl_rs_ctx.last_error();
        if err != Error::None_ {
            let err_msg = isl_rs_ctx.last_error_msg();
            isl_rs_ctx.reset_error();
            return Err(LibISLError::new(err, err_msg));
        }
        Ok(isl_rs_result)
    }

    /// Wraps `isl_point_void`.
    pub fn void(space: Space) -> Result<Point, LibISLError> {
        let isl_rs_ctx = space.get_ctx();
        let mut space = space;
        space.do_not_free_on_drop();
        let space = space.ptr;
        let isl_rs_result = unsafe { isl_point_void(space) };
        let isl_rs_result = Point { ptr: isl_rs_result,
                                    should_free_on_drop: true };
        let err = isl_rs_ctx.last_error();
        if err != Error::None_ {
            let err_msg = isl_rs_ctx.last_error_msg();
            isl_rs_ctx.reset_error();
            return Err(LibISLError::new(err, err_msg));
        }
        Ok(isl_rs_result)
    }

    /// Wraps `isl_point_zero`.
    pub fn zero(space: Space) -> Result<Point, LibISLError> {
        let isl_rs_ctx = space.get_ctx();
        let mut space = space;
        space.do_not_free_on_drop();
        let space = space.ptr;
        let isl_rs_result = unsafe { isl_point_zero(space) };
        let isl_rs_result = Point { ptr: isl_rs_result,
                                    should_free_on_drop: true };
        let err = isl_rs_ctx.last_error();
        if err != Error::None_ {
            let err_msg = isl_rs_ctx.last_error_msg();
            isl_rs_ctx.reset_error();
            return Err(LibISLError::new(err, err_msg));
        }
        Ok(isl_rs_result)
    }

    /// Does not call isl_point_free() on being dropped. (For internal use
    /// only.)
    pub fn do_not_free_on_drop(&mut self) {
        self.should_free_on_drop = false;
    }
}

impl Drop for Point {
    fn drop(&mut self) {
        if self.should_free_on_drop {
            unsafe {
                isl_point_free(self.ptr);
            }
        }
    }
}