1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2016 Yusuke Sasaki
//
// This software is released under the MIT License.
// See http://opensource.org/licenses/mit-license.php or <LICENSE>.

/// Defines the name of parameters
pub mod exports {
  pub use ffi::{IntParam, DoubleParam, StringParam};

  // re-exports
  pub use self::IntParam::*;
  pub use self::DoubleParam::*;
  pub use self::StringParam::*;
}
use self::exports::*;

use ffi;
use std::ffi::CString;
use util;


pub trait Param: Sized + Into<CString> {
  type Out;
  type Buf: util::Init + util::Into<Self::Out> + util::AsRawPtr<Self::RawFrom>;
  type RawFrom;
  type RawTo: util::FromRaw<Self::Out>;

  #[inline(always)]
  unsafe fn get_param(env: *mut ffi::GRBenv, paramname: ffi::c_str, value: Self::RawFrom) -> ffi::c_int;

  #[inline(always)]
  unsafe fn set_param(env: *mut ffi::GRBenv, paramname: ffi::c_str, value: Self::RawTo) -> ffi::c_int;
}



impl Param for IntParam {
  type Out = i32;
  type Buf = ffi::c_int;
  type RawFrom = *mut ffi::c_int;
  type RawTo = ffi::c_int;

  unsafe fn get_param(env: *mut ffi::GRBenv, paramname: ffi::c_str, value: *mut ffi::c_int) -> ffi::c_int {
    ffi::GRBgetintparam(env, paramname, value)
  }

  unsafe fn set_param(env: *mut ffi::GRBenv, paramname: ffi::c_str, value: ffi::c_int) -> ffi::c_int {
    ffi::GRBsetintparam(env, paramname, value)
  }
}

impl Param for DoubleParam {
  type Out = f64;
  type Buf = ffi::c_double;
  type RawFrom = *mut ffi::c_double;
  type RawTo = ffi::c_double;

  unsafe fn get_param(env: *mut ffi::GRBenv, paramname: ffi::c_str, value: *mut ffi::c_double) -> ffi::c_int {
    ffi::GRBgetdblparam(env, paramname, value)
  }

  unsafe fn set_param(env: *mut ffi::GRBenv, paramname: ffi::c_str, value: ffi::c_double) -> ffi::c_int {
    ffi::GRBsetdblparam(env, paramname, value)
  }
}

impl Param for StringParam {
  type Out = String;
  type Buf = Vec<ffi::c_char>;
  type RawFrom = *mut ffi::c_char;
  type RawTo = *const ffi::c_char;

  unsafe fn get_param(env: *mut ffi::GRBenv, paramname: ffi::c_str, value: *mut ffi::c_char) -> ffi::c_int {
    ffi::GRBgetstrparam(env, paramname, value)
  }

  unsafe fn set_param(env: *mut ffi::GRBenv, paramname: ffi::c_str, value: *const ffi::c_char) -> ffi::c_int {
    ffi::GRBsetstrparam(env, paramname, value)
  }
}