From 99a27fbfef7aa4bae38ec35c5e8b0fcb3778fc76 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Mon, 13 Sep 2021 13:17:08 +0200 Subject: [PATCH] option to disable guid map and lazy loading --- src/ifcparse/IfcFile.h | 8 ++++++++ src/ifcparse/IfcParse.cpp | 20 ++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/ifcparse/IfcFile.h b/src/ifcparse/IfcFile.h index 15a61e8890..82c537b451 100644 --- a/src/ifcparse/IfcFile.h +++ b/src/ifcparse/IfcFile.h @@ -112,6 +112,14 @@ public: } }; + static bool lazy_load_; + static bool lazy_load() { return lazy_load_; } + static void lazy_load(bool b) { lazy_load_ = b; } + + static bool guid_map_; + static bool guid_map() { return guid_map_; } + static void guid_map(bool b) { guid_map_ = b; } + private: typedef std::map entity_entity_map_t; diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index 54eb97fc71..a0018836a6 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -1077,7 +1077,16 @@ void IfcEntityInstanceData::load() const { if (type_ != 0) { tmp_data = new Argument*[getArgumentCount()]{}; } - file->seek_to(*this); + + if (file->parsing_complete()) { + // only when parsing is fully complete we need to seek to the instance, otherwise + // we know the token cursor is currently at the keyword token + file->seek_to(*this); + } else { + // Apparently the load() function assumes one token later after the opening parenthesis + file->tokens->Next(); + } + size_t n = file->load(id(), type_ ? type_->as_entity() : nullptr, tmp_data, getArgumentCount()); if (n != getArgumentCount()) { Logger::Error("Wrong number of attributes on instance with id #" + boost::lexical_cast(id_)); @@ -1487,6 +1496,10 @@ void IfcFile::initialize_(IfcParse::IfcSpfStream* s) { Logger::Status(ss.str(), false); } + if (!lazy_load_) { + data->load(); + } + if (instance->declaration().is(*ifcroot_type_)) { try { const std::string guid = *instance->data().getArgument(0); @@ -2400,4 +2413,7 @@ void IfcParse::IfcFile::build_inverses() { } } -std::atomic_uint32_t IfcUtil::IfcBaseClass::counter_(0); \ No newline at end of file +std::atomic_uint32_t IfcUtil::IfcBaseClass::counter_(0); + +bool IfcParse::IfcFile::lazy_load_ = true; +bool IfcParse::IfcFile::guid_map_ = true;