diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index 8cd70c42cc..a6f485552e 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -1352,9 +1352,7 @@ IfcFile::IfcFile(const std::string& path, filetype ty) } if (ty == FT_IFCSPF) { IfcSpfStream s(path); - storage_.emplace<1>(); // impl::in_memory_file_storage{}; - // @todo assign in constructor - std::get(storage_).file = this; + storage_.emplace<1>(this); std::get(storage_).read_from_stream(&s, schema_, max_id_); if (std::get(storage_).good_) { @@ -1376,9 +1374,7 @@ IfcFile::IfcFile(const std::string& path, filetype ty) } else { throw std::runtime_error("Unsupported file format"); } - if (schema_) { - ifcroot_type_ = schema_->declaration_by_name("IfcRoot"); - } + ifcroot_type_ = schema_ ? schema_->declaration_by_name("IfcRoot") : nullptr; } #endif @@ -1386,26 +1382,38 @@ IfcFile::IfcFile(std::istream& stream, int length) : schema_(nullptr) { IfcSpfStream s(stream, length); - storage_.emplace<1>(); + storage_.emplace<1>(this); std::get(storage_).read_from_stream(&s, schema_, max_id_); - ifcroot_type_ = schema_->declaration_by_name("IfcRoot"); + ifcroot_type_ = schema_ ? schema_->declaration_by_name("IfcRoot") : nullptr; + + byid_ = decltype(byid_)(&std::get(storage_).instance_by_name_); + byref_excl_ = decltype(byref_excl_)(&std::get(storage_).byref_excl_); + byguid_ = decltype(byguid_)(&std::get(storage_).byguid_); } IfcFile::IfcFile(void* data, int length) : schema_(nullptr) { IfcSpfStream s(data, length); - storage_.emplace<1>(); + storage_.emplace<1>(this); std::get(storage_).read_from_stream(&s, schema_, max_id_); - ifcroot_type_ = schema_->declaration_by_name("IfcRoot"); + ifcroot_type_ = schema_ ? schema_->declaration_by_name("IfcRoot") : nullptr; + + byid_ = decltype(byid_)(&std::get(storage_).instance_by_name_); + byref_excl_ = decltype(byref_excl_)(&std::get(storage_).byref_excl_); + byguid_ = decltype(byguid_)(&std::get(storage_).byguid_); } IfcFile::IfcFile(IfcParse::IfcSpfStream* s) : schema_(nullptr) { - storage_.emplace<1>(); + storage_.emplace<1>(this); std::get(storage_).read_from_stream(s, schema_, max_id_); - ifcroot_type_ = schema_->declaration_by_name("IfcRoot"); + ifcroot_type_ = schema_ ? schema_->declaration_by_name("IfcRoot") : nullptr; + + byid_ = decltype(byid_)(&std::get(storage_).instance_by_name_); + byref_excl_ = decltype(byref_excl_)(&std::get(storage_).byref_excl_); + byguid_ = decltype(byguid_)(&std::get(storage_).byguid_); } IfcFile::IfcFile(const IfcParse::schema_definition* schema, filetype ty, const std::string& path) @@ -1418,8 +1426,7 @@ IfcFile::IfcFile(const IfcParse::schema_definition* schema, filetype ty, const s ty = guess_file_type(path); } if (ty == FT_IFCSPF) { - storage_.emplace<1>(); - std::get(storage_).file = this; + storage_.emplace<1>(this); byid_ = decltype(byid_)(&std::get(storage_).byid_); byref_excl_ = decltype(byref_excl_)(&std::get(storage_).byref_excl_); diff --git a/src/ifcparse/storage.h b/src/ifcparse/storage.h index 2a1e2778c4..ab1b5faa20 100644 --- a/src/ifcparse/storage.h +++ b/src/ifcparse/storage.h @@ -211,7 +211,7 @@ namespace IfcParse { typedef std::map> entities_by_ref_t; typedef entity_instance_by_name_t::iterator iterator; - in_memory_file_storage() : tokens(nullptr), file(nullptr), schema(nullptr) {} + in_memory_file_storage(IfcParse::IfcFile* f = nullptr) : tokens(nullptr), file(f), schema(nullptr) {} in_memory_file_storage(const in_memory_file_storage&) = delete; in_memory_file_storage(const in_memory_file_storage&&) = delete;