Skip to main content

EntityResolver

Trait EntityResolver 

Source
pub trait EntityResolver: Send + Sync {
    // Required methods
    fn get(&self, id: EntityId) -> Option<Arc<DecodedEntity>>;
    fn entities_by_type(&self, ifc_type: &IfcType) -> Vec<Arc<DecodedEntity>>;
    fn find_by_type_name(&self, type_name: &str) -> Vec<Arc<DecodedEntity>>;
    fn count_by_type(&self, ifc_type: &IfcType) -> usize;
    fn all_ids(&self) -> Vec<EntityId>;
    fn raw_bytes(&self, id: EntityId) -> Option<&[u8]>;

    // Provided methods
    fn resolve_ref(&self, attr: &AttributeValue) -> Option<Arc<DecodedEntity>> { ... }
    fn resolve_ref_list(&self, attr: &AttributeValue) -> Vec<Arc<DecodedEntity>> { ... }
    fn entity_count(&self) -> usize { ... }
}
Expand description

Entity lookup and reference resolution

This trait provides the core functionality for accessing IFC entities and resolving entity references. Implementations should provide O(1) lookup by entity ID.

§Example

use bimifc_model::{EntityResolver, EntityId, AttributeValue};

fn process_wall(resolver: &dyn EntityResolver, wall_id: EntityId) {
    if let Some(wall) = resolver.get(wall_id) {
        println!("Wall type: {:?}", wall.ifc_type);

        // Resolve a reference attribute
        if let Some(ref_attr) = wall.get(5) {
            if let Some(related) = resolver.resolve_ref(ref_attr) {
                println!("Related entity: {:?}", related.ifc_type);
            }
        }
    }
}

Required Methods§

Source

fn get(&self, id: EntityId) -> Option<Arc<DecodedEntity>>

Get entity by ID

Returns the decoded entity if it exists, wrapped in an Arc for efficient sharing.

§Arguments
  • id - The entity ID to look up
§Returns

Some(Arc<DecodedEntity>) if found, None otherwise

Source

fn entities_by_type(&self, ifc_type: &IfcType) -> Vec<Arc<DecodedEntity>>

Get all entities of a specific type

§Arguments
  • ifc_type - The IFC type to filter by
§Returns

A vector of all entities matching the specified type

Source

fn find_by_type_name(&self, type_name: &str) -> Vec<Arc<DecodedEntity>>

Find entities by type name string

This is useful for dynamic lookups where the type is not known at compile time.

§Arguments
  • type_name - The type name to search for (case-insensitive)
§Returns

A vector of entities matching the type name

Source

fn count_by_type(&self, ifc_type: &IfcType) -> usize

Count entities of a specific type

§Arguments
  • ifc_type - The IFC type to count
§Returns

The number of entities of the specified type

Source

fn all_ids(&self) -> Vec<EntityId>

Get all entity IDs in the model

§Returns

A vector of all entity IDs

Source

fn raw_bytes(&self, id: EntityId) -> Option<&[u8]>

Fast raw bytes access for optimized parsing

Returns the raw bytes of an entity’s definition for parsers that want to do direct parsing without going through the attribute system. This is useful for performance-critical paths like coordinate parsing.

§Arguments
  • id - The entity ID to get raw bytes for
§Returns

The raw bytes of the entity definition, or None if not available

Provided Methods§

Source

fn resolve_ref(&self, attr: &AttributeValue) -> Option<Arc<DecodedEntity>>

Resolve an entity reference from an attribute value

If the attribute value is an EntityRef, this looks up and returns the referenced entity.

§Arguments
  • attr - The attribute value that may contain an entity reference
§Returns

Some(Arc<DecodedEntity>) if the attribute is a valid reference, None otherwise

Source

fn resolve_ref_list(&self, attr: &AttributeValue) -> Vec<Arc<DecodedEntity>>

Resolve a list of entity references

If the attribute value is a List containing EntityRefs, this resolves all of them and returns the entities.

§Arguments
  • attr - The attribute value that may contain a list of entity references
§Returns

A vector of resolved entities (empty if the attribute is not a list or contains no refs)

Source

fn entity_count(&self) -> usize

Get total entity count

Implementors§