diff --git a/src/ifcparse/IfcFile.h b/src/ifcparse/IfcFile.h index 649c09bfea..6559805faa 100644 --- a/src/ifcparse/IfcFile.h +++ b/src/ifcparse/IfcFile.h @@ -137,18 +137,20 @@ public: , progress_(0) { good_ = file_open_status::NO_HEADER; - header_ = new IfcParse::IfcSpfHeader(lexer_); - if (header_->tryRead() && header_->file_schema()->schema_identifiers().size() == 1) { - try { - schema_ = IfcParse::schema_by_name(header_->file_schema()->schema_identifiers().front()); - good_ = file_open_status::SUCCESS; - } catch (const IfcParse::IfcException&) { + if (*stream_) { + header_ = new IfcParse::IfcSpfHeader(lexer_); + if (header_->tryRead() && header_->file_schema()->schema_identifiers().size() == 1) { + try { + schema_ = IfcParse::schema_by_name(header_->file_schema()->schema_identifiers().front()); + good_ = file_open_status::SUCCESS; + } catch (const IfcParse::IfcException&) { + } } + storage_.file = nullptr; + storage_.schema = schema_; + storage_.tokens = lexer_; + storage_.references_to_resolve = &references_to_resolve_; } - storage_.file = nullptr; - storage_.schema = schema_; - storage_.tokens = lexer_; - storage_.references_to_resolve = &references_to_resolve_; } InstanceStreamer(const IfcParse::schema_definition* schema, IfcParse::IfcSpfLexer* lexer) diff --git a/src/ifcparse/IfcSpfStream.h b/src/ifcparse/IfcSpfStream.h index dda8742d5c..7d42a9cd52 100644 --- a/src/ifcparse/IfcSpfStream.h +++ b/src/ifcparse/IfcSpfStream.h @@ -76,6 +76,8 @@ class IFC_PARSE_API IfcSpfStream { bool is_eof_at(unsigned int) const; void increment_at(unsigned int&); char peek_at(unsigned int); + + operator bool() const { return valid && !eof; } }; } // namespace IfcParse