mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-20 04:04:00 +00:00
Manually write out if-statements instead of visit with if-constexpr #5444
This commit is contained in:
+45
-43
@@ -1388,58 +1388,60 @@ void IfcFile::initialize_(IfcParse::IfcSpfStream* s) {
|
|||||||
|
|
||||||
delete tokens;
|
delete tokens;
|
||||||
|
|
||||||
auto resolve_instance = [this](auto inst, int ref, int refattr) {
|
for (const auto& p : references_to_resolve) {
|
||||||
IfcUtil::IfcBaseClass* ptr;
|
const auto& ref = p.first.name_;
|
||||||
if constexpr (std::is_same_v<decltype(inst), int>) {
|
const auto& refattr = p.first.index_;
|
||||||
entity_by_id_t::const_iterator it = byid_.find(inst);
|
if (auto* v = boost::get<reference_or_simple_type>(&p.second)) {
|
||||||
if (it == byid_.end()) {
|
if (auto* name = boost::get<int>(v)) {
|
||||||
Logger::Error("Instance reference #" + std::to_string(inst) + " used by instance #" + std::to_string(ref) + " at attribute index " + std::to_string(refattr) + " not found");
|
entity_by_id_t::const_iterator it = byid_.find(*name);
|
||||||
ptr = nullptr;
|
if (it == byid_.end()) {
|
||||||
} else {
|
Logger::Error("Instance reference #" + std::to_string(*name) + " used by instance #" + std::to_string(ref) + " at attribute index " + std::to_string(refattr) + " not found");
|
||||||
ptr = it->second;
|
} else {
|
||||||
|
byid_[p.first.name_]->data().storage_.set(p.first.index_, it->second);
|
||||||
|
}
|
||||||
|
} else if (auto* inst = boost::get<IfcUtil::IfcBaseClass*>(v)) {
|
||||||
|
byid_[p.first.name_]->data().storage_.set(p.first.index_, *inst);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (auto* v = boost::get<std::vector<reference_or_simple_type>>(&p.second)) {
|
||||||
ptr = inst;
|
aggregate_of_instance::ptr instances(new aggregate_of_instance);
|
||||||
}
|
instances->reserve(v->size());
|
||||||
return ptr;
|
for (const auto& vi : *v) {
|
||||||
};
|
if (auto* name = boost::get<int>(&vi)) {
|
||||||
|
entity_by_id_t::const_iterator it = byid_.find(*name);
|
||||||
for (auto& p : references_to_resolve) {
|
if (it == byid_.end()) {
|
||||||
boost::apply_visitor([this, &resolve_instance, &p](auto& v) {
|
Logger::Error("Instance reference #" + std::to_string(*name) + " used by instance #" + std::to_string(ref) + " at attribute index " + std::to_string(refattr) + " not found");
|
||||||
if constexpr (std::is_same_v<std::decay_t<decltype(v)>, reference_or_simple_type>) {
|
} else {
|
||||||
auto inst = boost::apply_visitor([p, &resolve_instance](auto x) { return resolve_instance(x, p.first.name_, p.first.index_); }, v);
|
instances->push(it->second);
|
||||||
if (inst) {
|
|
||||||
byid_[p.first.name_]->data().storage_.set(p.first.index_, inst);
|
|
||||||
}
|
|
||||||
} else if constexpr (std::is_same_v<std::decay_t<decltype(v)>, std::vector<reference_or_simple_type>>) {
|
|
||||||
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* inst = boost::get<IfcUtil::IfcBaseClass*>(&vi)) {
|
||||||
|
instances->push(*inst);
|
||||||
}
|
}
|
||||||
byid_[p.first.name_]->data().storage_.set(p.first.index_, instances);
|
}
|
||||||
} else if constexpr (std::is_same_v<std::decay_t<decltype(v)>, std::vector<std::vector<reference_or_simple_type>>>) {
|
byid_[p.first.name_]->data().storage_.set(p.first.index_, instances);
|
||||||
aggregate_of_aggregate_of_instance::ptr instances(new aggregate_of_aggregate_of_instance);
|
} else if (auto* v = boost::get<std::vector<std::vector<reference_or_simple_type>>>(&p.second)) {
|
||||||
for (auto& vi : v) {
|
aggregate_of_aggregate_of_instance::ptr instances(new aggregate_of_aggregate_of_instance);
|
||||||
std::vector<IfcUtil::IfcBaseClass*> inner;
|
for (const auto& vi : *v) {
|
||||||
for (auto& vii : vi) {
|
std::vector<IfcUtil::IfcBaseClass*> inner;
|
||||||
auto inst = boost::apply_visitor([p, &resolve_instance](auto x) { return resolve_instance(x, p.first.name_, p.first.index_); }, vii);
|
for (const auto& vii : vi) {
|
||||||
if (inst) {
|
if (auto* name = boost::get<int>(&vii)) {
|
||||||
inner.push_back(inst);
|
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<IfcUtil::IfcBaseClass*>(&vii)) {
|
||||||
|
inner.push_back(*inst);
|
||||||
}
|
}
|
||||||
instances->push(inner);
|
|
||||||
}
|
}
|
||||||
byid_[p.first.name_]->data().storage_.set(p.first.index_, instances);
|
instances->push(inner);
|
||||||
} else {
|
|
||||||
// static_assert(false, "Inconsistent type");
|
|
||||||
}
|
}
|
||||||
}, p.second);
|
byid_[p.first.name_]->data().storage_.set(p.first.index_, instances);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger::Status("Done resolving references");
|
||||||
|
|
||||||
references_to_resolve.clear();
|
references_to_resolve.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user