Class file

Inheritance Relationships

Derived Type

Class Documentation

class file

This class provides access to the entity instances in an IFC file The file takes ownership of instances added to this file and deletes them when the file is deleted.

Subclassed by hierarchy_helper< Schema >

Public Types

using const_iterator = variant_iterator<impl::in_memory_file_storage::iterator, impl::rocks_db_file_storage::const_iterator>
using type_iterator = variant_iterator<impl::in_memory_file_storage::type_iterator, impl::rocks_db_file_storage::rocksdb_types_iterator>
using storage_type = std::variant<std::monostate, impl::in_memory_file_storage, impl::rocks_db_file_storage>
typedef variant_map<impl::in_memory_file_storage::entity_instance_by_guid, impl::rocks_db_file_storage::entity_instance_by_guid> entity_instance_by_guid
typedef variant_map<impl::in_memory_file_storage::entity_instance_by_name, impl::rocks_db_file_storage::entity_instance_by_name> entity_by_id
typedef variant_map<impl::in_memory_file_storage::entities_by_ref, impl::rocks_db_file_storage::entities_by_ref> entities_by_ref

Public Functions

file(const std::string &path, filetype type = FT_AUTODETECT, bool read_only = false, ifcopenshell::logger &logger = ifcopenshell::logger::root())

Constructs an file object from a file path, supports IFC-SPF and the IfcOpenShell-specific RocksDB format.

Parameters:
  • path – UTF-8 file path to an IFC-SPF file or RocksDB database directory

  • type – File type of the path

  • read_only – Whether to open in read-only mode, only supported on RocksDB databases

  • logger – Logger used while opening the file

file(std::istream &stream, int data_size, ifcopenshell::logger &logger = ifcopenshell::logger::root())

Constructs an file object from a stream containing IFC-SPF data.

file(void *data, int data_size, ifcopenshell::logger &logger = ifcopenshell::logger::root())

Constructs an file object from a memory buffer containing IFC-SPF data.

file(const ifcopenshell::schema_definition *schema = ifcopenshell::schema_by_name("IFC4"), filetype type = FT_AUTODETECT, const std::string &path = "", ifcopenshell::logger &logger = ifcopenshell::logger::root())

Constructs an file object with the specified schema, file type, and file path.

Note

path is only used in RocksDB mode; an SPF file is in memory only until write() is called.

Parameters:
  • schema – Pointer to the schema definition to use. Defaults to the IFC4 schema if not specified.

  • type – The file type to use for the file. Defaults to FT_AUTODETECT.

  • path – The file system path to the IFC file. Defaults to an empty string.

  • logger – Logger used while creating the file.

file(const uninitialized_tag &tag, ifcopenshell::logger &logger = ifcopenshell::logger::root())

Constructs an unitialized file object. Call initialize() later on. Allows to specify which types to bypass during load.

bool initialize(const std::string &path, filetype type = FT_AUTODETECT, bool read_only = false)
inline void lazy_loading(bool value)
inline bool lazy_loading() const
inline void paged_reading(bool value)
inline bool paged_reading() const
void bypass_type(const std::string &type_name)

Bypass loading of all instances of the specified type name. Only applies to parsed IFC-SPF files.

Parameters:

type_name – case insensitive name of the type to bypass

~file()
inline ifcopenshell::file_open_status good() const
inline ifcopenshell::logger &logger() const
inline entity_by_id::iterator begin() const

Returns the first entity in the range of instances contained in the model, in arbitrary order

inline entity_by_id::iterator end() const

Returns the first entity in the range of instances contained in the model, in arbitrary order

type_iterator types_begin() const
type_iterator types_end() const
template<class T>
inline std::vector<T> instances_by_type()

Returns all entities in the file that match the template argument. NOTE: This also returns subtypes of the requested type, for example: IfcWall will also return IfcWallStandardCase entities

template<class T>
inline std::vector<T> instances_by_type_excl_subtypes()
std::vector<express::base> instances_by_type(const ifcopenshell::declaration *declaration)

Returns all entities in the file that match the positional argument. NOTE: This also returns subtypes of the requested type, for example: IfcWall will also return IfcWallStandardCase entities

std::vector<express::base> instances_by_type_excl_subtypes(const ifcopenshell::declaration *declaration)

Returns all entities in the file that match the positional argument.

std::vector<express::base> instances_by_type(const std::string &type_name)

Returns all entities in the file that match the positional argument. NOTE: This also returns subtypes of the requested type, for example: IfcWall will also return IfcWallStandardCase entities

std::vector<express::base> instances_by_type_excl_subtypes(const std::string &type_name)

Returns all entities in the file that match the positional argument.

std::vector<express::base> instances_by_reference(int reference_id)

Returns all entities in the file that reference the id.

bool all_referencing_instances(int instance_id, const std::function<bool(uint32_t)> &pred)

Returns whether pred accepts the id of every instance that references instance_id, stopping at the first one it rejects. Used by the Python wrapper’s helpers; a std::function can’t be exposed to Python itself.

express::base instance_by_id(int instance_id)

Returns the entity with the specified id.

express::base instance_by_guid(const std::string &global_id)

Returns the entity with the specified GlobalId.

std::vector<int> get_inverse_indices_by_id(int instance_id)

Get the attribute indices corresponding to the list of entity instances returned by get_inverse().

template<typename T>
inline T::list::ptr get_inverse(int instance_id, int attribute_index)
std::vector<express::entity> get_inverse(int instance_id, const ifcopenshell::declaration *declaration, int attribute_index)
size_t get_total_inverses(int instance_id)
inline unsigned int fresh_id()
inline unsigned int get_max_id() const
inline const ifcopenshell::declaration *ifcroot_type() const
void recalculate_id_counter()
express::base add_entity(const express::base &entity, int instance_id = -1)
void remove_entity(const express::base &entity)

Removes entity instance from file and unsets references.

Attention when running remove_entity inside a loop over a list of entities to be removed. This invalidates the iterator. A workaround is to reverse the loop: std::shared_ptr<aggregate_of_instance> entities = …; for (auto it = entities->end() - 1; it >= entities->begin(); –it) { ifcopenshell::IfcBaseClass *const inst = *it; model->remove_entity(inst); }

inline const spf_header &header() const
inline spf_header &header()
const ifcopenshell::schema_definition *schema() const
std::pair<express::base, double> get_unit(const std::string &unit_type)
void build_inverses()
void register_inverse(unsigned referenced_id, const ifcopenshell::entity *from_entity, int instance_id, int attribute_index)
void unregister_inverse(unsigned referenced_id, const ifcopenshell::entity *from_entity, const express::base &entity, int attribute_index)
inline entity_instance_by_guid internal_guid_map()
void add_type_ref(const express::base &new_entity)
void remove_type_ref(const express::base &new_entity)
void process_deletion_inverse(const express::base &entity)
void build_inverses_(const express::base &entity)
template<typename T>
inline T create(int instance_id = -1)
express::base create(const ifcopenshell::declaration *declaration, int instance_id = -1)
inline void batch()
void unbatch()
void reset_identity_cache()

Public Members

entity_instance_by_guid byguid_
entity_by_id byid_
entities_by_ref byref_excl_
bool check_existance_before_adding = true
bool calculate_unit_factors = true
storage_type storage_
std::set<std::string> types_to_bypass_loading_

Public Static Functions

static std::vector<express::base> traverse(const express::base &instance, int max_depth = -1)

Performs a depth-first traversal, returning all entity instance attributes as a flat list. NB: includes the root instance specified in the first function argument.

static std::vector<express::base> traverse_breadth_first(const express::base &instance, int max_depth = -1)

Same as traverse() but maintains topological order by using a breadth-first search

static std::string create_timestamp()