use dds_bridge_sys as sys;
use semver::Version;
use core::ffi::{CStr, c_char};
use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Platform {
Windows,
Cygwin,
Linux,
Apple,
Unknown(i32),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Compiler {
MSVC,
MinGW,
GCC,
Clang,
Unknown(i32),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Threading {
None,
Windows,
OpenMP,
GCD,
Boost,
STL,
TBB,
Unknown(i32),
}
#[derive(Debug, Clone, Copy)]
pub struct SystemInfo(pub(super) sys::DDSInfo);
impl SystemInfo {
#[must_use]
pub const fn version(&self) -> Version {
#[allow(clippy::cast_sign_loss)]
Version::new(
self.0.major as u64,
self.0.minor as u64,
self.0.patch as u64,
)
}
#[must_use]
pub const fn platform(&self) -> Platform {
match self.0.system {
1 => Platform::Windows,
2 => Platform::Cygwin,
3 => Platform::Linux,
4 => Platform::Apple,
n => Platform::Unknown(n),
}
}
#[must_use]
pub const fn num_bits(&self) -> u32 {
#[allow(clippy::cast_sign_loss)]
return self.0.numBits as u32;
}
#[must_use]
pub const fn compiler(&self) -> Compiler {
match self.0.compiler {
1 => Compiler::MSVC,
2 => Compiler::MinGW,
3 => Compiler::GCC,
4 => Compiler::Clang,
n => Compiler::Unknown(n),
}
}
#[must_use]
pub const fn threading(&self) -> Threading {
match self.0.threading {
0 => Threading::None,
1 => Threading::Windows,
2 => Threading::OpenMP,
3 => Threading::GCD,
4 => Threading::Boost,
5 => Threading::STL,
6 => Threading::TBB,
n => Threading::Unknown(n),
}
}
#[must_use]
pub const fn num_cores(&self) -> usize {
#[allow(clippy::cast_sign_loss)]
return self.0.numCores as usize;
}
#[must_use]
pub const fn num_threads(&self) -> usize {
#[allow(clippy::cast_sign_loss)]
return self.0.noOfThreads as usize;
}
#[must_use]
pub const fn thread_sizes(&self) -> &str {
unsafe { c_chars_to_str(&self.0.threadSizes) }
}
#[must_use]
pub const fn system_string(&self) -> &str {
unsafe { c_chars_to_str(&self.0.systemString) }
}
}
const unsafe fn c_chars_to_str(bytes: &[c_char]) -> &str {
unsafe { core::str::from_utf8_unchecked(CStr::from_ptr(bytes.as_ptr()).to_bytes()) }
}
impl fmt::Display for SystemInfo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.system_string())
}
}