use crate::{Tag, Vr};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum VrDef {
Fixed(Vr),
Ambiguous(&'static [Vr]),
}
impl VrDef {
pub fn contains(self, vr: Vr) -> bool {
match self {
Self::Fixed(fixed) => fixed == vr,
Self::Ambiguous(set) => set.contains(&vr),
}
}
pub fn fixed(self) -> Option<Vr> {
match self {
Self::Fixed(vr) => Some(vr),
Self::Ambiguous(_) => None,
}
}
pub fn is_ambiguous(self) -> bool {
matches!(self, Self::Ambiguous(_))
}
}
#[derive(Clone, Copy, Debug)]
pub struct Entry {
pub tag: Tag,
pub keyword: &'static str,
pub name: &'static str,
pub vr: VrDef,
pub vm: &'static str,
pub retired: bool,
}
#[derive(Clone, Copy, Debug)]
pub struct Repeater {
pub mask: u32,
pub value: u32,
pub entry: Entry,
}
mod generated;
pub use generated::tags;
pub fn entries() -> &'static [Entry] {
generated::ENTRIES
}
pub fn repeaters() -> &'static [Repeater] {
generated::REPEATERS
}
pub fn lookup(tag: Tag) -> Option<&'static Entry> {
if let Ok(index) = generated::ENTRIES.binary_search_by(|entry| entry.tag.cmp(&tag)) {
return Some(&generated::ENTRIES[index]);
}
let raw = tag.as_u32();
generated::REPEATERS
.iter()
.find(|repeater| raw & repeater.mask == repeater.value)
.map(|repeater| &repeater.entry)
}
pub fn vr(tag: Tag) -> Option<VrDef> {
lookup(tag).map(|entry| entry.vr)
}
pub fn lookup_keyword(keyword: &str) -> Option<&'static Entry> {
generated::ENTRIES
.iter()
.find(|entry| entry.keyword.eq_ignore_ascii_case(keyword))
}