use ifc_model::{Entity, EntityId, Value};
#[derive(Debug, Clone, Copy)]
pub struct CostItem<'m> {
id: EntityId,
entity: &'m Entity,
}
pub(crate) mod slot {
pub const GLOBAL_ID: usize = 0;
pub const NAME: usize = 2;
pub const DESCRIPTION: usize = 3;
pub const IDENTIFICATION: usize = 5;
pub const PREDEFINED_TYPE: usize = 6;
pub const COST_VALUES: usize = 7;
pub const COST_QUANTITIES: usize = 8;
}
impl<'m> CostItem<'m> {
pub fn new(id: EntityId, entity: &'m Entity) -> Self {
Self { id, entity }
}
pub fn id(&self) -> EntityId {
self.id
}
pub fn global_id(&self) -> Option<&'m str> {
self.entity.text(slot::GLOBAL_ID)
}
pub fn name(&self) -> Option<&'m str> {
self.entity.text(slot::NAME)
}
pub fn identification(&self) -> Option<&'m str> {
self.entity.text(slot::IDENTIFICATION)
}
pub fn description(&self) -> Option<&'m str> {
self.entity.text(slot::DESCRIPTION)
}
pub fn predefined_type(&self) -> Option<&'m str> {
match self.entity.attribute(slot::PREDEFINED_TYPE)? {
Value::Enum(e) => Some(e),
_ => None,
}
}
pub fn value_refs(&self) -> Vec<EntityId> {
refs_in(self.entity.attribute(slot::COST_VALUES))
}
pub fn quantity_refs(&self) -> Vec<EntityId> {
refs_in(self.entity.attribute(slot::COST_QUANTITIES))
}
}
fn refs_in(value: Option<&Value>) -> Vec<EntityId> {
let mut out = Vec::new();
if let Some(v) = value {
v.for_each_ref(&mut |id| out.push(id));
}
out
}