use ifc_model::{EntityId, Model, ReverseIndex};
use super::link;
use super::slots;
use super::{Relationship, RelationshipKind};
#[derive(Debug)]
pub struct RelationshipIndex<'m> {
model: &'m Model,
reverse: ReverseIndex,
}
impl<'m> RelationshipIndex<'m> {
#[must_use]
pub fn build(model: &'m Model) -> Self {
Self {
model,
reverse: ReverseIndex::build(model),
}
}
#[must_use]
pub fn naming(&self, target: EntityId) -> Vec<Relationship> {
let mut out = Vec::new();
for (rel_slots, kind) in [
(slots::AGGREGATES, RelationshipKind::Aggregates),
(slots::CONTAINED_IN, RelationshipKind::ContainedIn),
(slots::NESTS, RelationshipKind::Nests),
] {
for id in self.reverse.referrers_in_slot(target, rel_slots.related) {
if let Some(relationship) = link::read(self.model, id, rel_slots, kind) {
out.push(relationship);
}
}
}
out
}
}