#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SchemaVersion {
Ifc2x3,
Ifc4,
Ifc4x3,
}
impl SchemaVersion {
#[must_use]
pub const fn release_id(self) -> &'static str {
match self {
Self::Ifc2x3 => "IFC2X3_TC1",
Self::Ifc4 => "IFC4_ADD2_TC1",
Self::Ifc4x3 => "IFC4X3_ADD2",
}
}
#[must_use]
pub const fn expected_entity_count(self) -> usize {
match self {
Self::Ifc2x3 => 653,
Self::Ifc4 => 776,
Self::Ifc4x3 => 876,
}
}
#[must_use]
pub const fn expected_type_count(self) -> usize {
match self {
Self::Ifc2x3 => 327,
Self::Ifc4 => 397,
Self::Ifc4x3 => 436,
}
}
#[must_use]
pub const fn header_tokens(self) -> &'static [&'static str] {
match self {
Self::Ifc2x3 => &["IFC2X3"],
Self::Ifc4 => &["IFC4"],
Self::Ifc4x3 => &["IFC4X3", "IFC4X3_ADD2"],
}
}
pub fn from_header_token(token: &str) -> Option<Self> {
match token.trim().to_ascii_uppercase().as_str() {
"IFC2X3" => Some(Self::Ifc2x3),
"IFC4" => Some(Self::Ifc4),
"IFC4X3" | "IFC4X3_ADD2" => Some(Self::Ifc4x3),
_ => None,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn recognizes_the_schema_tokens_our_fixtures_carry() {
assert_eq!(
SchemaVersion::from_header_token("IFC4"),
Some(SchemaVersion::Ifc4)
);
assert_eq!(
SchemaVersion::from_header_token("ifc2x3"),
Some(SchemaVersion::Ifc2x3)
);
assert_eq!(SchemaVersion::from_header_token("STEP"), None);
}
}