From e4d1118124620dfd8a5997abed3472efd1007faa Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Mon, 23 Sep 2024 15:10:37 +0200 Subject: [PATCH] Manually write out if-statements instead of visit with if-constexpr #5444 --- src/ifcparse/IfcParse.cpp | 88 ++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index a922775977..091106abe3 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -1388,58 +1388,60 @@ void IfcFile::initialize_(IfcParse::IfcSpfStream* s) { delete tokens; - auto resolve_instance = [this](auto inst, int ref, int refattr) { - IfcUtil::IfcBaseClass* ptr; - if constexpr (std::is_same_v) { - entity_by_id_t::const_iterator it = byid_.find(inst); - if (it == byid_.end()) { - Logger::Error("Instance reference #" + std::to_string(inst) + " used by instance #" + std::to_string(ref) + " at attribute index " + std::to_string(refattr) + " not found"); - ptr = nullptr; - } else { - ptr = it->second; + for (const auto& p : references_to_resolve) { + const auto& ref = p.first.name_; + const auto& refattr = p.first.index_; + if (auto* v = boost::get(&p.second)) { + if (auto* name = boost::get(v)) { + entity_by_id_t::const_iterator it = byid_.find(*name); + if (it == byid_.end()) { + Logger::Error("Instance reference #" + std::to_string(*name) + " used by instance #" + std::to_string(ref) + " at attribute index " + std::to_string(refattr) + " not found"); + } else { + byid_[p.first.name_]->data().storage_.set(p.first.index_, it->second); + } + } else if (auto* inst = boost::get(v)) { + byid_[p.first.name_]->data().storage_.set(p.first.index_, *inst); } - } else { - ptr = inst; - } - return ptr; - }; - - for (auto& p : references_to_resolve) { - boost::apply_visitor([this, &resolve_instance, &p](auto& v) { - if constexpr (std::is_same_v, reference_or_simple_type>) { - auto inst = boost::apply_visitor([p, &resolve_instance](auto x) { return resolve_instance(x, p.first.name_, p.first.index_); }, v); - if (inst) { - byid_[p.first.name_]->data().storage_.set(p.first.index_, inst); - } - } else if constexpr (std::is_same_v, std::vector>) { - aggregate_of_instance::ptr instances(new aggregate_of_instance); - instances->reserve(v.size()); - for (auto& vi : v) { - auto inst = boost::apply_visitor([p, &resolve_instance](auto x) { return resolve_instance(x, p.first.name_, p.first.index_); }, vi); - if (inst) { - instances->push(inst); + } else if (auto* v = boost::get>(&p.second)) { + aggregate_of_instance::ptr instances(new aggregate_of_instance); + instances->reserve(v->size()); + for (const auto& vi : *v) { + if (auto* name = boost::get(&vi)) { + entity_by_id_t::const_iterator it = byid_.find(*name); + if (it == byid_.end()) { + Logger::Error("Instance reference #" + std::to_string(*name) + " used by instance #" + std::to_string(ref) + " at attribute index " + std::to_string(refattr) + " not found"); + } else { + instances->push(it->second); } + } else if (auto* inst = boost::get(&vi)) { + instances->push(*inst); } - byid_[p.first.name_]->data().storage_.set(p.first.index_, instances); - } else if constexpr (std::is_same_v, std::vector>>) { - aggregate_of_aggregate_of_instance::ptr instances(new aggregate_of_aggregate_of_instance); - for (auto& vi : v) { - std::vector inner; - for (auto& vii : vi) { - auto inst = boost::apply_visitor([p, &resolve_instance](auto x) { return resolve_instance(x, p.first.name_, p.first.index_); }, vii); - if (inst) { - inner.push_back(inst); + } + byid_[p.first.name_]->data().storage_.set(p.first.index_, instances); + } else if (auto* v = boost::get>>(&p.second)) { + aggregate_of_aggregate_of_instance::ptr instances(new aggregate_of_aggregate_of_instance); + for (const auto& vi : *v) { + std::vector inner; + for (const auto& vii : vi) { + if (auto* name = boost::get(&vii)) { + entity_by_id_t::const_iterator it = byid_.find(*name); + if (it == byid_.end()) { + Logger::Error("Instance reference #" + std::to_string(*name) + " used by instance #" + std::to_string(ref) + " at attribute index " + std::to_string(refattr) + " not found"); + } else { + inner.push_back(it->second); } + } else if (auto* inst = boost::get(&vii)) { + inner.push_back(*inst); } - instances->push(inner); } - byid_[p.first.name_]->data().storage_.set(p.first.index_, instances); - } else { - // static_assert(false, "Inconsistent type"); + instances->push(inner); } - }, p.second); + byid_[p.first.name_]->data().storage_.set(p.first.index_, instances); + } } + Logger::Status("Done resolving references"); + references_to_resolve.clear(); }