isl-rs 0.3.1

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

use super::{Context, Error, LibISLError, Map, Set};
use libc::uintptr_t;

/// Wraps `isl_restriction`.
pub struct Restriction {
    pub ptr: uintptr_t,
    pub should_free_on_drop: bool,
}

extern "C" {

    fn isl_restriction_empty(source_map: uintptr_t) -> uintptr_t;

    fn isl_restriction_free(restr: uintptr_t) -> uintptr_t;

    fn isl_restriction_get_ctx(restr: uintptr_t) -> uintptr_t;

    fn isl_restriction_input(source_restr: uintptr_t, sink_restr: uintptr_t) -> uintptr_t;

    fn isl_restriction_none(source_map: uintptr_t) -> uintptr_t;

    fn isl_restriction_output(source_restr: uintptr_t) -> uintptr_t;

}

impl Restriction {
    /// Wraps `isl_restriction_empty`.
    pub fn empty(source_map: Map) -> Result<Restriction, LibISLError> {
        let isl_rs_ctx = source_map.get_ctx();
        let mut source_map = source_map;
        source_map.do_not_free_on_drop();
        let source_map = source_map.ptr;
        let isl_rs_result = unsafe { isl_restriction_empty(source_map) };
        let isl_rs_result = Restriction { 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_restriction_free`.
    pub fn free(self) -> Result<Restriction, LibISLError> {
        let restr = self;
        let isl_rs_ctx = restr.get_ctx();
        let mut restr = restr;
        restr.do_not_free_on_drop();
        let restr = restr.ptr;
        let isl_rs_result = unsafe { isl_restriction_free(restr) };
        let isl_rs_result = Restriction { 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_restriction_get_ctx`.
    pub fn get_ctx(&self) -> Context {
        let restr = self;
        let restr = restr.ptr;
        let isl_rs_result = unsafe { isl_restriction_get_ctx(restr) };
        let isl_rs_result = Context { ptr: isl_rs_result,
                                      should_free_on_drop: false };
        isl_rs_result
    }

    /// Wraps `isl_restriction_input`.
    pub fn input(source_restr: Set, sink_restr: Set) -> Result<Restriction, LibISLError> {
        let isl_rs_ctx = source_restr.get_ctx();
        let mut source_restr = source_restr;
        source_restr.do_not_free_on_drop();
        let source_restr = source_restr.ptr;
        let mut sink_restr = sink_restr;
        sink_restr.do_not_free_on_drop();
        let sink_restr = sink_restr.ptr;
        let isl_rs_result = unsafe { isl_restriction_input(source_restr, sink_restr) };
        let isl_rs_result = Restriction { 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_restriction_none`.
    pub fn none(source_map: Map) -> Result<Restriction, LibISLError> {
        let isl_rs_ctx = source_map.get_ctx();
        let mut source_map = source_map;
        source_map.do_not_free_on_drop();
        let source_map = source_map.ptr;
        let isl_rs_result = unsafe { isl_restriction_none(source_map) };
        let isl_rs_result = Restriction { 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_restriction_output`.
    pub fn output(source_restr: Set) -> Result<Restriction, LibISLError> {
        let isl_rs_ctx = source_restr.get_ctx();
        let mut source_restr = source_restr;
        source_restr.do_not_free_on_drop();
        let source_restr = source_restr.ptr;
        let isl_rs_result = unsafe { isl_restriction_output(source_restr) };
        let isl_rs_result = Restriction { 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_restriction_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 Restriction {
    fn drop(&mut self) {
        if self.should_free_on_drop {
            unsafe {
                isl_restriction_free(self.ptr);
            }
        }
    }
}