diff --git a/src/ifcparse/IfcEntityInstanceData.cpp b/src/ifcparse/IfcEntityInstanceData.cpp index 1fd064114e..6da3f5fd11 100644 --- a/src/ifcparse/IfcEntityInstanceData.cpp +++ b/src/ifcparse/IfcEntityInstanceData.cpp @@ -45,6 +45,9 @@ AttributeValue::operator double() const AttributeValue::operator boost::logic::tribool() const { + if (array_->has(index_)) { + return array_->get(index_); + } return array_->get(index_); } diff --git a/src/ifcparse/IfcFile.cpp b/src/ifcparse/IfcFile.cpp index 27179defc0..f7b256586d 100644 --- a/src/ifcparse/IfcFile.cpp +++ b/src/ifcparse/IfcFile.cpp @@ -1,4 +1,5 @@ #include "IfcFile.h" +#include "IfcLogger.h" IfcParse::parse_context::~parse_context() { for (auto& t : tokens_) { @@ -25,19 +26,15 @@ void IfcParse::parse_context::push(IfcUtil::IfcBaseClass* inst) { } namespace { - // Define a template to check if a type is in a boost::variant template struct is_type_in_variant; - // Specialization for boost::variant template struct is_type_in_variant, T> { - // Recursive template to check if T is one of Types static constexpr bool value = (std::is_same::value || ...); }; - // Helper variable template (C++14 and beyond) template constexpr bool is_type_in_variant_v = is_type_in_variant::value; @@ -118,16 +115,41 @@ namespace { if (aggregate_storage.which() == 0) { aggregate_storage = std::vector>{ v }; } else { - auto* vec_ptr = boost::get< std::vector>>(&aggregate_storage); + auto* vec_ptr = boost::get>>(&aggregate_storage); if (vec_ptr) { vec_ptr->push_back(v); } else { - // inconsistent aggregate valuation + // @todo would be cool if we can trace this back to file offset + auto current = boost::apply_visitor([](auto v) { + if constexpr (!std::is_same_v) { + return std::string(typeid(typename decltype(v)::value_type).name()); + } else { + // Cannot occur as aggregate_storage.which() == 0 + // is another branch several statements up. But is + // needed for consistency of return type. + return std::string{}; + } + }, aggregate_storage); + Logger::Error("Inconsistent aggregate valuation while attempting to append " + std::string(typeid(decltype(v)).name()) + " to an aggregate of " + current); + // @todo boolean -> logical upgrade + // wait a second... there are no aggregate of bool / logical in the schema.. + // + // if constexpr (std::is_same_v, bool>) { + // auto* vec_ptr = boost::get(&aggregate_storage); + // vec_ptr->push_back(v); + // } + // if constexpr (std::is_same_v, boost::tribool>) { + // auto* vec_ptr = boost::get(&aggregate_storage); + // std::vector ps(vec_ptr->begin(), vec_ptr->end()); + // ps.push_back(v); + // aggregate_storage = ps; + // } } } } else { - // unsupported aggregate type + // @todo would be cool if we can trace this back to file offset + Logger::Error(std::string("Aggregates of ") + typeid(decltype(v)).name() + " are not supported in the IfcOpenShell parser"); } };