2015-01-05 17:46:23 +00:00
|
|
|
/********************************************************************************
|
|
|
|
|
* *
|
|
|
|
|
* This file is part of IfcOpenShell. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the Lesser GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation, either version 3.0 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* Lesser GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the Lesser GNU General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "IfcSpfHeader.h"
|
|
|
|
|
|
2023-09-17 12:30:17 +02:00
|
|
|
#include "IfcFile.h"
|
2023-10-24 11:47:44 +02:00
|
|
|
#include "IfcLogger.h"
|
2023-09-17 12:30:17 +02:00
|
|
|
|
|
|
|
|
static const char* const ISO_10303_21 = "ISO-10303-21";
|
|
|
|
|
static const char* const HEADER = "HEADER";
|
|
|
|
|
static const char* const ENDSEC = "ENDSEC";
|
|
|
|
|
static const char* const DATA = "DATA";
|
2015-01-05 17:46:23 +00:00
|
|
|
|
|
|
|
|
using namespace IfcParse;
|
|
|
|
|
|
2024-08-23 20:29:07 +02:00
|
|
|
namespace {
|
2025-08-25 12:45:10 +02:00
|
|
|
IfcEntityInstanceData read_from_spf_file(IfcParse::impl::in_memory_file_storage* storage, size_t s) {
|
|
|
|
|
if (storage != nullptr) {
|
|
|
|
|
parse_context pc;
|
|
|
|
|
storage->tokens->Next();
|
|
|
|
|
storage->load(-1, nullptr, pc, -1);
|
2025-08-26 10:20:08 +02:00
|
|
|
return pc.construct(-1, *storage->references_to_resolve, nullptr, s, -1);
|
2025-08-25 12:45:10 +02:00
|
|
|
} else {
|
|
|
|
|
// std::unreachable();
|
|
|
|
|
return IfcEntityInstanceData(in_memory_attribute_storage(10));
|
|
|
|
|
}
|
2023-09-17 12:30:17 +02:00
|
|
|
}
|
2025-08-25 12:45:10 +02:00
|
|
|
} // namespace
|
2017-06-05 17:26:58 +02:00
|
|
|
|
2015-01-05 17:46:23 +00:00
|
|
|
void IfcSpfHeader::readSemicolon() {
|
2025-08-25 12:45:10 +02:00
|
|
|
if (storage_ != nullptr) {
|
|
|
|
|
if (!TokenFunc::isOperator(storage_->tokens->Next(), ';')) {
|
|
|
|
|
throw IfcException(std::string("Expected ;"));
|
2025-02-21 16:12:16 +01:00
|
|
|
}
|
2025-08-25 12:45:10 +02:00
|
|
|
} else {
|
|
|
|
|
// std::unreachable();
|
|
|
|
|
}
|
2015-01-05 17:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IfcSpfHeader::readTerminal(const std::string& term, Trail trail) {
|
2025-08-25 12:45:10 +02:00
|
|
|
if (storage_ != nullptr) {
|
|
|
|
|
if (TokenFunc::asStringRef(storage_->tokens->Next()) != term) {
|
|
|
|
|
throw IfcException(std::string("Expected " + term));
|
|
|
|
|
}
|
|
|
|
|
if (trail == TRAILING_SEMICOLON) {
|
|
|
|
|
readSemicolon();
|
2025-02-21 16:12:16 +01:00
|
|
|
}
|
2025-08-25 12:45:10 +02:00
|
|
|
} else {
|
|
|
|
|
// std::unreachable();
|
|
|
|
|
}
|
2015-01-05 17:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-27 22:07:31 +01:00
|
|
|
IfcParse::IfcSpfHeader::IfcSpfHeader(IfcParse::IfcFile* file)
|
|
|
|
|
: file_(file),
|
|
|
|
|
file_description_(nullptr),
|
|
|
|
|
file_name_(nullptr),
|
|
|
|
|
file_schema_(nullptr)
|
|
|
|
|
{
|
|
|
|
|
if (file == nullptr) {
|
|
|
|
|
// overwritten later in IfcFile::setDefaultHeaderValues() when we know the schema identifier
|
|
|
|
|
file_description_ = new Header_section_schema::file_description({}, "");
|
|
|
|
|
file_description_->file_ = file_;
|
|
|
|
|
file_name_ = new Header_section_schema::file_name("", "", {}, {}, "", "", "");
|
|
|
|
|
file_name_->file_ = file_;
|
|
|
|
|
file_schema_ = new Header_section_schema::file_schema({});
|
|
|
|
|
file_schema_->file_ = file_;
|
2025-08-25 12:45:10 +02:00
|
|
|
} else {
|
|
|
|
|
storage_ = std::visit([this](auto& m) -> decltype(storage_) {
|
|
|
|
|
if constexpr (std::is_same_v<std::decay_t<decltype(m)>, impl::in_memory_file_storage>) {
|
|
|
|
|
return &m;
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}, file_->storage_);
|
2025-09-10 09:10:59 +02:00
|
|
|
|
|
|
|
|
if (storage_ == nullptr) {
|
|
|
|
|
file_description_ = Header_section_schema::get_schema().instantiate(&Header_section_schema::file_description::Class(), IfcEntityInstanceData(rocks_db_attribute_storage{}))->as<Header_section_schema::file_description>();
|
|
|
|
|
file_description_->file_ = file_;
|
|
|
|
|
file_name_ = Header_section_schema::get_schema().instantiate(&Header_section_schema::file_name::Class(), IfcEntityInstanceData(rocks_db_attribute_storage{}))->as<Header_section_schema::file_name>();
|
|
|
|
|
file_name_->file_ = file_;
|
|
|
|
|
file_schema_ = Header_section_schema::get_schema().instantiate(&Header_section_schema::file_schema::Class(), IfcEntityInstanceData(rocks_db_attribute_storage{}))->as<Header_section_schema::file_schema>();
|
|
|
|
|
file_schema_->file_ = file_;
|
|
|
|
|
}
|
2025-02-27 22:07:31 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-25 12:45:10 +02:00
|
|
|
IfcParse::IfcSpfHeader::IfcSpfHeader(IfcParse::IfcSpfLexer* lexer)
|
|
|
|
|
{
|
|
|
|
|
storage_ = new impl::in_memory_file_storage;
|
|
|
|
|
storage_->tokens = lexer;
|
|
|
|
|
file_ = nullptr;
|
|
|
|
|
|
|
|
|
|
// overwritten later in IfcFile::setDefaultHeaderValues() when we know the schema identifier
|
|
|
|
|
file_description_ = new Header_section_schema::file_description({}, "");
|
|
|
|
|
file_description_->file_ = file_;
|
|
|
|
|
file_name_ = new Header_section_schema::file_name("", "", {}, {}, "", "", "");
|
|
|
|
|
file_name_->file_ = file_;
|
|
|
|
|
file_schema_ = new Header_section_schema::file_schema({});
|
|
|
|
|
file_schema_->file_ = file_;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-27 22:07:31 +01:00
|
|
|
IfcParse::IfcSpfHeader::~IfcSpfHeader() {
|
|
|
|
|
delete file_schema_;
|
|
|
|
|
delete file_name_;
|
|
|
|
|
delete file_description_;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-25 12:45:10 +02:00
|
|
|
void IfcParse::IfcSpfHeader::file(IfcParse::IfcFile* file)
|
|
|
|
|
{
|
|
|
|
|
this->file_ = file;
|
|
|
|
|
if (file != nullptr) {
|
|
|
|
|
storage_ = std::visit([this](auto& m) -> decltype(storage_) {
|
|
|
|
|
if constexpr (std::is_same_v<std::decay_t<decltype(m)>, impl::in_memory_file_storage>) {
|
|
|
|
|
return &m;
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}, file_->storage_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-05 17:46:23 +00:00
|
|
|
void IfcSpfHeader::read() {
|
2023-09-17 12:30:17 +02:00
|
|
|
readTerminal(ISO_10303_21, TRAILING_SEMICOLON);
|
|
|
|
|
readTerminal(HEADER, TRAILING_SEMICOLON);
|
|
|
|
|
|
|
|
|
|
// | The header section of every exchange structure shall contain one
|
|
|
|
|
// | instance of each of the following entities: file_description, file_name,
|
|
|
|
|
// | and file_schema, and they shall appear in that order. Instances of
|
|
|
|
|
// | file_population, section_language and section_context may appear after
|
|
|
|
|
// | file_schema. If instances of user-defined header section entities are
|
|
|
|
|
// | present, they shall appear after the header section entity instances
|
|
|
|
|
// | defined in this section.
|
|
|
|
|
//
|
|
|
|
|
// ISO 10303-21 Second edition 2002-01-15 p. 16
|
|
|
|
|
|
2025-02-27 22:07:31 +01:00
|
|
|
readTerminal(Header_section_schema::file_description::Class().name_uc(), NONE);
|
2023-11-06 20:38:19 +01:00
|
|
|
delete file_description_;
|
2025-08-25 12:45:10 +02:00
|
|
|
file_description_ = new Header_section_schema::file_description(read_from_spf_file(storage_, Header_section_schema::file_description::Class().attribute_count()));
|
2025-02-27 22:07:31 +01:00
|
|
|
file_description_->file_ = file_;
|
2024-08-23 20:29:07 +02:00
|
|
|
readSemicolon();
|
2023-09-17 12:30:17 +02:00
|
|
|
|
2025-02-27 22:07:31 +01:00
|
|
|
readTerminal(Header_section_schema::file_name::Class().name_uc(), NONE);
|
2023-11-06 20:38:19 +01:00
|
|
|
delete file_name_;
|
2025-08-25 12:45:10 +02:00
|
|
|
file_name_ = new Header_section_schema::file_name(read_from_spf_file(storage_, Header_section_schema::file_name::Class().attribute_count()));
|
2025-02-27 22:07:31 +01:00
|
|
|
file_name_->file_ = file_;
|
2024-08-23 20:29:07 +02:00
|
|
|
readSemicolon();
|
2023-09-17 12:30:17 +02:00
|
|
|
|
2025-02-27 22:07:31 +01:00
|
|
|
readTerminal(Header_section_schema::file_schema::Class().name_uc(), NONE);
|
2023-11-06 20:38:19 +01:00
|
|
|
delete file_schema_;
|
2025-08-25 12:45:10 +02:00
|
|
|
file_schema_ = new Header_section_schema::file_schema(read_from_spf_file(storage_, Header_section_schema::file_schema::Class().attribute_count()));
|
2025-02-27 22:07:31 +01:00
|
|
|
file_schema_->file_ = file_;
|
2024-08-23 20:29:07 +02:00
|
|
|
readSemicolon();
|
2015-01-05 17:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IfcSpfHeader::tryRead() {
|
2023-09-17 12:30:17 +02:00
|
|
|
try {
|
|
|
|
|
read();
|
|
|
|
|
return true;
|
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
|
Logger::Error(e);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-01-05 17:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
2023-11-06 20:29:00 +01:00
|
|
|
void IfcSpfHeader::write(std::ostream& out) const {
|
|
|
|
|
out << ISO_10303_21 << ";"
|
|
|
|
|
<< "\n";
|
|
|
|
|
out << HEADER << ";"
|
|
|
|
|
<< "\n";
|
2025-02-27 22:07:31 +01:00
|
|
|
file_description()->toString(out, true);
|
|
|
|
|
out << ";"
|
2023-11-06 20:29:00 +01:00
|
|
|
<< "\n";
|
2025-02-27 22:07:31 +01:00
|
|
|
file_name()->toString(out, true);
|
|
|
|
|
out << ";"
|
2023-11-06 20:29:00 +01:00
|
|
|
<< "\n";
|
2025-02-27 22:07:31 +01:00
|
|
|
file_schema()->toString(out, true);
|
|
|
|
|
out << ";"
|
2023-11-06 20:29:00 +01:00
|
|
|
<< "\n";
|
|
|
|
|
out << ENDSEC << ";"
|
|
|
|
|
<< "\n";
|
|
|
|
|
out << DATA << ";"
|
|
|
|
|
<< "\n";
|
2015-01-16 16:26:40 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-27 22:07:31 +01:00
|
|
|
const Header_section_schema::file_description* IfcParse::IfcSpfHeader::file_description() const {
|
2023-11-06 20:38:19 +01:00
|
|
|
if (file_description_ == nullptr) {
|
2025-02-27 22:07:31 +01:00
|
|
|
std::visit([this](auto& m) {
|
|
|
|
|
if constexpr (std::is_same_v<std::decay_t<decltype(m)>, impl::rocks_db_file_storage>) {
|
|
|
|
|
file_description_ = new Header_section_schema::file_description(rocks_db_attribute_storage{});
|
|
|
|
|
} else if constexpr (std::is_same_v<std::decay_t<decltype(m)>, impl::in_memory_file_storage>) {
|
|
|
|
|
file_description_ = new Header_section_schema::file_description(in_memory_attribute_storage(Header_section_schema::file_description::Class().attribute_count()));
|
|
|
|
|
}
|
|
|
|
|
}, file_->storage_);
|
|
|
|
|
file_description_->file_ = file_;
|
2023-09-17 12:30:17 +02:00
|
|
|
}
|
2025-02-27 22:07:31 +01:00
|
|
|
return file_description_;
|
2015-01-16 16:26:40 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-27 22:07:31 +01:00
|
|
|
const Header_section_schema::file_name* IfcParse::IfcSpfHeader::file_name() const {
|
2023-11-06 20:38:19 +01:00
|
|
|
if (file_name_ == nullptr) {
|
2025-02-27 22:07:31 +01:00
|
|
|
std::visit([this](auto& m) {
|
|
|
|
|
if constexpr (std::is_same_v<std::decay_t<decltype(m)>, impl::rocks_db_file_storage>) {
|
|
|
|
|
file_name_ = new Header_section_schema::file_name(rocks_db_attribute_storage{});
|
|
|
|
|
} else if constexpr (std::is_same_v<std::decay_t<decltype(m)>, impl::in_memory_file_storage>) {
|
|
|
|
|
file_name_ = new Header_section_schema::file_name(in_memory_attribute_storage(Header_section_schema::file_name::Class().attribute_count()));
|
|
|
|
|
}
|
|
|
|
|
}, file_->storage_);
|
|
|
|
|
file_name_->file_ = file_;
|
2023-09-17 12:30:17 +02:00
|
|
|
}
|
2025-02-27 22:07:31 +01:00
|
|
|
|
|
|
|
|
return file_name_;
|
2015-01-16 16:26:40 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-27 22:07:31 +01:00
|
|
|
const Header_section_schema::file_schema* IfcParse::IfcSpfHeader::file_schema() const {
|
2023-11-06 20:38:19 +01:00
|
|
|
if (file_schema_ == nullptr) {
|
2025-02-27 22:07:31 +01:00
|
|
|
std::visit([this](auto& m) {
|
|
|
|
|
if constexpr (std::is_same_v<std::decay_t<decltype(m)>, impl::rocks_db_file_storage>) {
|
|
|
|
|
file_schema_ = new Header_section_schema::file_schema(rocks_db_attribute_storage{});
|
|
|
|
|
} else if constexpr (std::is_same_v<std::decay_t<decltype(m)>, impl::in_memory_file_storage>) {
|
|
|
|
|
file_schema_ = new Header_section_schema::file_schema(in_memory_attribute_storage(Header_section_schema::file_schema::Class().attribute_count()));
|
|
|
|
|
}
|
|
|
|
|
}, file_->storage_);
|
|
|
|
|
file_schema_->file_ = file_;
|
2023-09-17 12:30:17 +02:00
|
|
|
}
|
2025-02-27 22:07:31 +01:00
|
|
|
|
|
|
|
|
return file_schema_;
|
2015-01-16 16:26:40 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-27 22:07:31 +01:00
|
|
|
Header_section_schema::file_description* IfcParse::IfcSpfHeader::file_description() {
|
2023-11-06 20:38:19 +01:00
|
|
|
if (file_description_ == nullptr) {
|
2025-02-27 22:07:31 +01:00
|
|
|
std::visit([this](auto& m) {
|
|
|
|
|
if constexpr (std::is_same_v<std::decay_t<decltype(m)>, impl::rocks_db_file_storage>) {
|
|
|
|
|
file_description_ = new Header_section_schema::file_description(rocks_db_attribute_storage{});
|
|
|
|
|
} else if constexpr (std::is_same_v<std::decay_t<decltype(m)>, impl::in_memory_file_storage>) {
|
|
|
|
|
file_description_ = new Header_section_schema::file_description(in_memory_attribute_storage(Header_section_schema::file_description::Class().attribute_count()));
|
|
|
|
|
}
|
|
|
|
|
}, file_->storage_);
|
|
|
|
|
file_description_->file_ = file_;
|
2023-09-17 12:30:17 +02:00
|
|
|
}
|
2025-02-27 22:07:31 +01:00
|
|
|
|
|
|
|
|
return file_description_;
|
2015-01-05 17:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-27 22:07:31 +01:00
|
|
|
Header_section_schema::file_name* IfcParse::IfcSpfHeader::file_name() {
|
2023-11-06 20:38:19 +01:00
|
|
|
if (file_name_ == nullptr) {
|
2025-02-27 22:07:31 +01:00
|
|
|
std::visit([this](auto& m) {
|
|
|
|
|
if constexpr (std::is_same_v<std::decay_t<decltype(m)>, impl::rocks_db_file_storage>) {
|
|
|
|
|
file_name_ = new Header_section_schema::file_name(rocks_db_attribute_storage{});
|
|
|
|
|
} else if constexpr (std::is_same_v<std::decay_t<decltype(m)>, impl::in_memory_file_storage>) {
|
|
|
|
|
file_name_ = new Header_section_schema::file_name(in_memory_attribute_storage(Header_section_schema::file_name::Class().attribute_count()));
|
|
|
|
|
}
|
|
|
|
|
}, file_->storage_);
|
|
|
|
|
file_name_->file_ = file_;
|
2023-09-17 12:30:17 +02:00
|
|
|
}
|
2025-02-27 22:07:31 +01:00
|
|
|
|
|
|
|
|
return file_name_;
|
2015-01-05 17:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-27 22:07:31 +01:00
|
|
|
Header_section_schema::file_schema* IfcParse::IfcSpfHeader::file_schema() {
|
2023-11-06 20:38:19 +01:00
|
|
|
if (file_schema_ == nullptr) {
|
2025-02-27 22:07:31 +01:00
|
|
|
std::visit([this](auto& m) {
|
|
|
|
|
if constexpr (std::is_same_v<std::decay_t<decltype(m)>, impl::rocks_db_file_storage>) {
|
|
|
|
|
file_schema_ = new Header_section_schema::file_schema(rocks_db_attribute_storage{});
|
|
|
|
|
} else if constexpr (std::is_same_v<std::decay_t<decltype(m)>, impl::in_memory_file_storage>) {
|
|
|
|
|
file_schema_ = new Header_section_schema::file_schema(in_memory_attribute_storage(Header_section_schema::file_schema::Class().attribute_count()));
|
|
|
|
|
}
|
|
|
|
|
}, file_->storage_);
|
|
|
|
|
file_schema_->file_ = file_;
|
2023-09-17 12:30:17 +02:00
|
|
|
}
|
2025-02-27 22:07:31 +01:00
|
|
|
|
|
|
|
|
return file_schema_;
|
2015-01-05 17:46:23 +00:00
|
|
|
}
|
2015-01-16 16:26:40 +00:00
|
|
|
|
2025-02-27 22:07:31 +01:00
|
|
|
static auto& _ = Header_section_schema::get_schema();
|