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
use ffi;
use std::mem;

use Result;

/// A type of temperature analysis.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AnalysisType {
    /// The steady-state analysis.
    Steady,
    /// The transient analysis.
    Transient,
    /// An undefined analysis.
    None,
}

/// Temperature analysis.
pub struct Analysis {
    raw: ffi::Analysis_t,
}

impl Analysis {
    /// Return the type.
    pub fn kind(&self) -> AnalysisType {
        match self.raw.AnalysisType {
            ffi::TDICE_ANALYSIS_TYPE_STEADY => AnalysisType::Steady,
            ffi::TDICE_ANALYSIS_TYPE_TRANSIENT => AnalysisType::Transient,
            ffi::TDICE_ANALYSIS_TYPE_NONE => AnalysisType::None,
        }
    }
}

impl Drop for Analysis {
    fn drop(&mut self) {
        unsafe { ffi::analysis_destroy(&mut self.raw) };
    }
}

implement_raw!(Analysis, ffi::Analysis_t);

pub unsafe fn new() -> Result<Analysis> {
    let mut raw = mem::uninitialized();
    ffi::analysis_init(&mut raw);
    Ok(Analysis { raw: raw })
}