use crate::encoder::StagedStrings;
#[derive(Debug, Clone, PartialEq)]
pub struct StagedMValue {
pub(crate) name: String,
pub(crate) presence: Option<Vec<bool>>,
pub(crate) values: StagedValues,
}
#[derive(Debug, Clone, PartialEq, strum::EnumCount)]
pub enum StagedValues {
Bool(Vec<bool>),
I8(Vec<i8>),
U8(Vec<u8>),
I32(Vec<i32>),
U32(Vec<u32>),
I64(Vec<i64>),
U64(Vec<u64>),
F32(Vec<f32>),
F64(Vec<f64>),
Str(Vec<String>),
}
macro_rules! impl_staged_m_values {
(
scalar { $($sv:ident),* $(,)? }
string { $($gv:ident),* $(,)? }
) => {
impl StagedValues {
#[must_use]
pub fn count(&self) -> usize {
match self {
$(Self::$sv(v) => v.len(),)*
$(Self::$gv(v) => v.len(),)*
}
}
}
};
}
with_kinds!(impl_staged_m_values);
impl StagedMValue {
#[must_use]
pub fn new(name: impl Into<String>, presence: Option<Vec<bool>>, values: StagedValues) -> Self {
Self {
name: name.into(),
presence,
values,
}
}
#[must_use]
pub fn name(&self) -> &str {
&self.name
}
#[must_use]
pub fn values(&self) -> &StagedValues {
&self.values
}
#[must_use]
pub(crate) fn feature_count(&self) -> Option<usize> {
self.presence.as_ref().map(Vec::len)
}
pub(crate) fn strings(&self, values: &[String]) -> StagedStrings {
StagedStrings::from_strings(self.name.clone(), values)
}
}