use crate::{EntryValue, IfdKind};
use std::collections::HashMap;
#[derive(Clone, Debug, PartialEq)]
pub(crate) struct ParsedImageFileDirectory {
entries: HashMap<(IfdKind, u16), ParsedIdfEntry>,
}
impl ParsedImageFileDirectory {
pub fn new() -> Self {
Self {
entries: HashMap::new(),
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub(crate) struct ParsedIdfEntry {
pub value: EntryValue,
}
impl ParsedImageFileDirectory {
pub(crate) fn get(&self, kind: IfdKind, tag: u16) -> Option<&EntryValue> {
self.entries.get(&(kind, tag)).map(|x| &x.value)
}
pub(crate) fn get_any(&self, tag: u16) -> Option<&EntryValue> {
Self::KINDS.iter().find_map(|&k| self.get(k, tag))
}
pub(crate) fn put(&mut self, kind: IfdKind, code: u16, v: EntryValue) {
self.entries
.insert((kind, code), ParsedIdfEntry { value: v });
}
pub(crate) fn iter(&self) -> impl Iterator<Item = (IfdKind, u16, &EntryValue)> {
self.entries
.iter()
.map(|(&(kind, code), e)| (kind, code, &e.value))
}
pub(crate) const KINDS: [IfdKind; 4] =
[IfdKind::Tiff, IfdKind::Exif, IfdKind::Gps, IfdKind::Interop];
}