1use ddss_sys as sys;
4use semver::Version;
5
6use core::ffi::{CStr, c_char};
7use core::fmt;
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
11pub enum Platform {
12 Windows,
14 Cygwin,
16 Linux,
18 Apple,
20 Unknown(i32),
22}
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
26pub enum Compiler {
27 MSVC,
29 MinGW,
31 GCC,
33 Clang,
35 Unknown(i32),
37}
38
39#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
41pub enum Threading {
42 None,
44 Windows,
46 OpenMP,
48 GCD,
50 Boost,
52 STL,
54 TBB,
56 Unknown(i32),
58}
59
60#[derive(Debug, Clone, Copy)]
66pub struct SystemInfo(pub(super) sys::DDSInfo);
67
68impl SystemInfo {
69 #[must_use]
71 pub const fn version(&self) -> Version {
72 #[allow(clippy::cast_sign_loss)]
73 Version::new(
74 self.0.major as u64,
75 self.0.minor as u64,
76 self.0.patch as u64,
77 )
78 }
79
80 #[must_use]
82 pub const fn platform(&self) -> Platform {
83 match self.0.system {
84 1 => Platform::Windows,
85 2 => Platform::Cygwin,
86 3 => Platform::Linux,
87 4 => Platform::Apple,
88 n => Platform::Unknown(n),
89 }
90 }
91
92 #[must_use]
94 pub const fn num_bits(&self) -> u32 {
95 #[allow(clippy::cast_sign_loss)]
96 return self.0.numBits as u32;
97 }
98
99 #[must_use]
101 pub const fn compiler(&self) -> Compiler {
102 match self.0.compiler {
103 1 => Compiler::MSVC,
104 2 => Compiler::MinGW,
105 3 => Compiler::GCC,
106 4 => Compiler::Clang,
107 n => Compiler::Unknown(n),
108 }
109 }
110
111 #[must_use]
115 pub const fn threading(&self) -> Threading {
116 match self.0.threading {
117 0 => Threading::None,
118 1 => Threading::Windows,
119 2 => Threading::OpenMP,
120 3 => Threading::GCD,
121 4 => Threading::Boost,
122 5 => Threading::STL,
123 6 => Threading::TBB,
124 n => Threading::Unknown(n),
125 }
126 }
127
128 #[must_use]
130 pub const fn num_cores(&self) -> usize {
131 #[allow(clippy::cast_sign_loss)]
132 return self.0.numCores as usize;
133 }
134
135 #[must_use]
137 pub const fn num_threads(&self) -> usize {
138 #[allow(clippy::cast_sign_loss)]
139 return self.0.noOfThreads as usize;
140 }
141
142 #[must_use]
147 pub const fn thread_sizes(&self) -> &str {
148 unsafe { c_chars_to_str(&self.0.threadSizes) }
150 }
151
152 #[must_use]
154 pub const fn system_string(&self) -> &str {
155 unsafe { c_chars_to_str(&self.0.systemString) }
157 }
158}
159
160const unsafe fn c_chars_to_str(bytes: &[c_char]) -> &str {
161 unsafe { core::str::from_utf8_unchecked(CStr::from_ptr(bytes.as_ptr()).to_bytes()) }
162}
163
164impl fmt::Display for SystemInfo {
165 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
166 f.write_str(self.system_string())
167 }
168}