From b6712602e27e0378e120ef44f0575d56c76d855a Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Thu, 28 Aug 2025 11:15:05 +0200 Subject: [PATCH] Retain exact attribute counts in rdb as parsed --- src/ifcparse/IfcFile.cpp | 10 ++++++---- src/ifcparse/IfcFile.h | 2 ++ src/ifcparse/storage.h | 2 +- src/serializers/RocksDbSerializer.cpp | 4 ++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ifcparse/IfcFile.cpp b/src/ifcparse/IfcFile.cpp index 819582f931..7ffcf82a28 100644 --- a/src/ifcparse/IfcFile.cpp +++ b/src/ifcparse/IfcFile.cpp @@ -225,7 +225,7 @@ namespace { } } -IfcEntityInstanceData IfcParse::parse_context::construct(int name, unresolved_references& references_to_resolve, const IfcParse::declaration* decl, boost::optional expected_size, int resolve_reference_index) { +IfcEntityInstanceData IfcParse::parse_context::construct(int name, unresolved_references& references_to_resolve, const IfcParse::declaration* decl, boost::optional expected_size, int resolve_reference_index, bool coerce_attribute_count) { std::vector parameter_types; std::unique_ptr transient_named_type; @@ -257,9 +257,11 @@ IfcEntityInstanceData IfcParse::parse_context::construct(int name, unresolved_re return IfcEntityInstanceData(in_memory_attribute_storage(0)); } - in_memory_attribute_storage storage(decl != nullptr + in_memory_attribute_storage storage(coerce_attribute_count + ? (decl != nullptr ? (std::min)(parameter_types.size(), tokens_.size()) - : tokens_.size() + : tokens_.size()) + : tokens_.size() ); auto it = tokens_.begin(); @@ -635,7 +637,7 @@ std::optionalstream->eof; } diff --git a/src/ifcparse/storage.h b/src/ifcparse/storage.h index 9a26039e1f..2a1e2778c4 100644 --- a/src/ifcparse/storage.h +++ b/src/ifcparse/storage.h @@ -184,7 +184,7 @@ namespace IfcParse { void push(IfcUtil::IfcBaseClass* inst); - IfcEntityInstanceData construct(int name, unresolved_references& references_to_resolve, const IfcParse::declaration* decl, boost::optional expected_size, int resolve_reference_index); + IfcEntityInstanceData construct(int name, unresolved_references& references_to_resolve, const IfcParse::declaration* decl, boost::optional expected_size, int resolve_reference_index, bool coerce_attribute_count=true); }; namespace impl { diff --git a/src/serializers/RocksDbSerializer.cpp b/src/serializers/RocksDbSerializer.cpp index a9273017c1..d749d5f31c 100644 --- a/src/serializers/RocksDbSerializer.cpp +++ b/src/serializers/RocksDbSerializer.cpp @@ -96,6 +96,10 @@ void RocksDbSerializer::write_streaming_() { IfcParse::InstanceStreamer streamer(input_filename); + // We do not want to coerce attribute counts here, because we want + // to store exactly what is in the file for validation purposes + streamer.coerce_attribute_count = false; + while (streamer) { auto inst = streamer.read_instance(); if (inst) {