use std::collections::HashMap;
#[derive(Debug, Clone)]
pub(crate) enum CimVal {
Text(String),
Ref(String),
}
impl CimVal {
pub(crate) fn as_text(&self) -> Option<&str> {
if let CimVal::Text(s) = self {
Some(s)
} else {
None
}
}
pub(crate) fn as_ref(&self) -> Option<&str> {
if let CimVal::Ref(s) = self {
Some(s)
} else {
None
}
}
}
#[derive(Debug, Clone)]
pub(crate) struct CimObj {
pub(crate) class: String,
pub(crate) attrs: HashMap<String, CimVal>,
}
impl CimObj {
pub(crate) fn new(class: &str) -> Self {
CimObj {
class: class.to_string(),
attrs: HashMap::new(),
}
}
pub(crate) fn get_text(&self, key: &str) -> Option<&str> {
self.attrs.get(key)?.as_text()
}
pub(crate) fn get_ref(&self, key: &str) -> Option<&str> {
self.attrs.get(key)?.as_ref()
}
pub(crate) fn parse_f64(&self, key: &str) -> Option<f64> {
self.get_text(key)?.parse().ok()
}
}
pub(crate) type ObjMap = HashMap<String, CimObj>;
pub(crate) const MAX_CIM_OBJECTS: usize = 5_000_000;
pub(crate) type SmBusMap = HashMap<String, (u32, String)>;