ifcparse: fix clang-tidy warning readability-implicit-bool-conversion

This commit is contained in:
Dirk Olbrich
2023-10-24 14:16:26 +02:00
committed by Thomas Krijnen
parent 95b5926353
commit c29e7b32ad
12 changed files with 158 additions and 159 deletions
+2 -2
View File
@@ -37,7 +37,7 @@ namespace IfcUtil {
class IFC_PARSE_API IfcBaseInterface { class IFC_PARSE_API IfcBaseInterface {
protected: protected:
static bool is_null(const IfcBaseInterface* not_this) { static bool is_null(const IfcBaseInterface* not_this) {
return !not_this; return not_this == nullptr;
} }
template <typename T> template <typename T>
@@ -90,7 +90,7 @@ class IFC_PARSE_API IfcBaseClass : public virtual IfcBaseInterface {
IfcEntityInstanceData* data_; IfcEntityInstanceData* data_;
static bool is_null(const IfcBaseClass* not_this) { static bool is_null(const IfcBaseClass* not_this) {
return !not_this; return not_this == nullptr;
} }
public: public:
+22 -22
View File
@@ -135,16 +135,16 @@ class pure_impure_helper {
if (EXPECTS_CHARACTER(parse_state)) { if (EXPECTS_CHARACTER(parse_state)) {
builder_.push_back(IfcUtil::convert_codepage(codepage, current_char + 0x80)); builder_.push_back(IfcUtil::convert_codepage(codepage, current_char + 0x80));
parse_state = 0; parse_state = 0;
} else if (current_char == '\'' && !parse_state) { } else if (current_char == '\'' && (parse_state == 0U)) {
parse_state = APOSTROPHE; parse_state = APOSTROPHE;
} else if (current_char == '\\' && !parse_state) { } else if (current_char == '\\' && (parse_state == 0U)) {
parse_state = FIRST_SOLIDUS; parse_state = FIRST_SOLIDUS;
} else if (current_char == '\\' && EXPECTS_SOLIDUS(parse_state)) { } else if (current_char == '\\' && EXPECTS_SOLIDUS(parse_state)) {
if (parse_state & ALPHABET_DEFINITION || if (((parse_state & ALPHABET_DEFINITION) != 0U) ||
parse_state & IGNORED_DIRECTIVE || ((parse_state & IGNORED_DIRECTIVE) != 0U) ||
parse_state & ENDEXTENDED_0) { ((parse_state & ENDEXTENDED_0) != 0U)) {
parse_state = hex = hex_count = 0; parse_state = hex = hex_count = 0;
} else if (parse_state & ENCOUNTERED_HEX) { } else if ((parse_state & ENCOUNTERED_HEX) != 0U) {
parse_state += THIRD_SOLIDUS; parse_state += THIRD_SOLIDUS;
parse_state -= ENCOUNTERED_HEX; parse_state -= ENCOUNTERED_HEX;
} else { } else {
@@ -173,8 +173,8 @@ class pure_impure_helper {
hex <<= 4; hex <<= 4;
parse_state += HEX((++hex_count)); parse_state += HEX((++hex_count));
hex += HEX_TO_INT(current_char); hex += HEX_TO_INT(current_char);
if ((hex_count == 2 && !(parse_state & EXTENDED2)) || if ((hex_count == 2 && ((parse_state & EXTENDED2) == 0U)) ||
(hex_count == 4 && !(parse_state & EXTENDED4)) || (hex_count == 4 && ((parse_state & EXTENDED4) == 0U)) ||
(hex_count == 8)) { (hex_count == 8)) {
builder_.push_back(hex); builder_.push_back(hex);
if (hex_count == 2) { if (hex_count == 2) {
@@ -185,9 +185,9 @@ class pure_impure_helper {
} }
hex = hex_count = 0; hex = hex_count = 0;
} }
} else if (parse_state && !( } else if ((parse_state != 0U) && !(
(current_char == '\\' && parse_state == FIRST_SOLIDUS) || (current_char == '\\' && parse_state == FIRST_SOLIDUS) ||
(current_char == '\'' && parse_state == APOSTROPHE))) { (current_char == '\'' && parse_state == APOSTROPHE))) {
if (parse_state == APOSTROPHE && current_char != '\'') { if (parse_state == APOSTROPHE && current_char != '\'') {
break; break;
} }
@@ -255,16 +255,16 @@ void IfcCharacterDecoder::skip() {
while ((current_char = file->Peek()) != 0) { while ((current_char = file->Peek()) != 0) {
if (EXPECTS_CHARACTER(parse_state)) { if (EXPECTS_CHARACTER(parse_state)) {
parse_state = 0; parse_state = 0;
} else if (current_char == '\'' && !parse_state) { } else if (current_char == '\'' && (parse_state == 0U)) {
parse_state = APOSTROPHE; parse_state = APOSTROPHE;
} else if (current_char == '\\' && !parse_state) { } else if (current_char == '\\' && (parse_state == 0U)) {
parse_state = FIRST_SOLIDUS; parse_state = FIRST_SOLIDUS;
} else if (current_char == '\\' && EXPECTS_SOLIDUS(parse_state)) { } else if (current_char == '\\' && EXPECTS_SOLIDUS(parse_state)) {
if (parse_state & ALPHABET_DEFINITION || if (((parse_state & ALPHABET_DEFINITION) != 0U) ||
parse_state & IGNORED_DIRECTIVE || ((parse_state & IGNORED_DIRECTIVE) != 0U) ||
parse_state & ENDEXTENDED_0) { ((parse_state & ENDEXTENDED_0) != 0U)) {
parse_state = hex_count = 0; parse_state = hex_count = 0;
} else if (parse_state & ENCOUNTERED_HEX) { } else if ((parse_state & ENCOUNTERED_HEX) != 0U) {
parse_state += THIRD_SOLIDUS; parse_state += THIRD_SOLIDUS;
parse_state -= ENCOUNTERED_HEX; parse_state -= ENCOUNTERED_HEX;
} else { } else {
@@ -290,8 +290,8 @@ void IfcCharacterDecoder::skip() {
parse_state += PAGE; parse_state += PAGE;
} else if (IS_HEXADECIMAL(current_char) && EXPECTS_HEX(parse_state)) { } else if (IS_HEXADECIMAL(current_char) && EXPECTS_HEX(parse_state)) {
parse_state += HEX((++hex_count)); parse_state += HEX((++hex_count));
if ((hex_count == 2 && !(parse_state & EXTENDED2)) || if ((hex_count == 2 && ((parse_state & EXTENDED2) == 0U)) ||
(hex_count == 4 && !(parse_state & EXTENDED4)) || (hex_count == 4 && ((parse_state & EXTENDED4) == 0U)) ||
(hex_count == 8)) { (hex_count == 8)) {
if (hex_count == 2) { if (hex_count == 2) {
parse_state = 0; parse_state = 0;
@@ -301,9 +301,9 @@ void IfcCharacterDecoder::skip() {
} }
hex_count = 0; hex_count = 0;
} }
} else if (parse_state && !( } else if ((parse_state != 0U) && !(
(current_char == '\\' && parse_state == FIRST_SOLIDUS) || (current_char == '\\' && parse_state == FIRST_SOLIDUS) ||
(current_char == '\'' && parse_state == APOSTROPHE))) { (current_char == '\'' && parse_state == APOSTROPHE))) {
if (parse_state == APOSTROPHE && current_char != '\'') { if (parse_state == APOSTROPHE && current_char != '\'') {
break; break;
} }
+1 -1
View File
@@ -84,7 +84,7 @@ class IFC_PARSE_API IfcEntityInstanceData {
if (type_ == 0) { if (type_ == 0) {
return 0; return 0;
} }
if (type_->as_entity()) { if (type_->as_entity() != nullptr) {
return type_->as_entity()->attribute_count(); return type_->as_entity()->attribute_count();
} }
return 1; return 1;
+2 -2
View File
@@ -35,7 +35,7 @@ static const char* chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop
std::string base64(unsigned v, int l) { std::string base64(unsigned v, int l) {
std::string r; std::string r;
r.reserve(l); r.reserve(l);
while (v) { while (v != 0U) {
r.push_back(chars[v % 64]); r.push_back(chars[v % 64]);
v /= 64; v /= 64;
} }
@@ -54,7 +54,7 @@ unsigned from_base64(const std::string& s) {
for (std::string::const_iterator i = s.begin() + zeros; i != s.end(); ++i) { for (std::string::const_iterator i = s.begin() + zeros; i != s.end(); ++i) {
r *= 64; r *= 64;
const char* c = strchr(chars, *i); const char* c = strchr(chars, *i);
if (!c) { if (c == nullptr) {
throw IfcParse::IfcException("Failed to decode GlobalId"); throw IfcParse::IfcException("Failed to decode GlobalId");
} }
r += (unsigned)(c - chars); r += (unsigned)(c - chars);
+9 -9
View File
@@ -126,7 +126,7 @@ void Logger::SetOutput(std::ostream* l1, std::ostream* l2) {
wlog1 = wlog2 = 0; wlog1 = wlog2 = 0;
log1 = l1; log1 = l1;
log2 = l2; log2 = l2;
if (!log2) { if (log2 == nullptr) {
log2 = &log_stream; log2 = &log_stream;
} }
} }
@@ -135,7 +135,7 @@ void Logger::SetOutput(std::wostream* l1, std::wostream* l2) {
log1 = log2 = 0; log1 = log2 = 0;
wlog1 = l1; wlog1 = l1;
wlog2 = l2; wlog2 = l2;
if (!wlog2) { if (wlog2 == nullptr) {
log2 = &log_stream; log2 = &log_stream;
} }
} }
@@ -160,17 +160,17 @@ void Logger::Message(Logger::Severity type, const std::string& message, const If
if (type > max_severity) { if (type > max_severity) {
max_severity = type; max_severity = type;
} }
if ((log2 || wlog2) && type >= verbosity) { if (((log2 != nullptr) || (wlog2 != nullptr)) && type >= verbosity) {
if (format == FMT_PLAIN) { if (format == FMT_PLAIN) {
if (log2) { if (log2 != nullptr) {
plain_text_message(*log2, current_product, type, message, instance); plain_text_message(*log2, current_product, type, message, instance);
} else if (wlog2) { } else if (wlog2 != nullptr) {
plain_text_message(*wlog2, current_product, type, message, instance); plain_text_message(*wlog2, current_product, type, message, instance);
} }
} else if (format == FMT_JSON) { } else if (format == FMT_JSON) {
if (log2) { if (log2 != nullptr) {
json_message(*log2, current_product, type, message, instance); json_message(*log2, current_product, type, message, instance);
} else if (wlog2) { } else if (wlog2 != nullptr) {
json_message(*wlog2, current_product, type, message, instance); json_message(*wlog2, current_product, type, message, instance);
} }
} }
@@ -192,9 +192,9 @@ void status(T& log1, const std::string& message, bool new_line) {
} }
void Logger::Status(const std::string& message, bool new_line) { void Logger::Status(const std::string& message, bool new_line) {
if (log1) { if (log1 != nullptr) {
status(*log1, message, new_line); status(*log1, message, new_line);
} else if (wlog1) { } else if (wlog1 != nullptr) {
status(*wlog1, message, new_line); status(*wlog1, message, new_line);
} }
} }
+53 -53
View File
@@ -210,7 +210,7 @@ void IfcSpfStream::Close() {
} }
#endif #endif
delete[] buffer; delete[] buffer;
if (stream) { if (stream != nullptr) {
fclose(stream); fclose(stream);
} }
} }
@@ -320,7 +320,7 @@ Token IfcSpfLexer::Next() {
return NoneTokenPtr(); return NoneTokenPtr();
} }
while (skipWhitespace() || skipComment()) { while ((skipWhitespace() != 0U) || (skipComment() != 0U)) {
} }
if (stream->eof) { if (stream->eof) {
@@ -342,7 +342,7 @@ Token IfcSpfLexer::Next() {
// Read character and increment pointer if not starting a new token // Read character and increment pointer if not starting a new token
c = stream->Peek(); c = stream->Peek();
if (len && (c == '(' || c == ')' || c == '=' || c == ',' || c == ';' || c == '/')) { if ((len != 0) && (c == '(' || c == ')' || c == '=' || c == ',' || c == ';' || c == '/')) {
break; break;
} }
stream->Inc(); stream->Inc();
@@ -353,7 +353,7 @@ Token IfcSpfLexer::Next() {
decoder->skip(); decoder->skip();
} }
} }
if (len) { if (len != 0) {
return GeneralTokenPtr(this, pos, stream->Tell()); return GeneralTokenPtr(this, pos, stream->Tell());
} }
return NoneTokenPtr(); return NoneTokenPtr();
@@ -385,7 +385,7 @@ void IfcSpfLexer::TokenString(unsigned int offset, std::string& buffer) {
buffer.clear(); buffer.clear();
while (!stream->is_eof_at(offset)) { while (!stream->is_eof_at(offset)) {
char c = stream->peek_at(offset); char c = stream->peek_at(offset);
if (buffer.size() && (c == '(' || c == ')' || c == '=' || c == ',' || c == ';' || c == '/')) { if (!buffer.empty() && (c == '(' || c == ')' || c == '=' || c == ',' || c == ';' || c == '/')) {
break; break;
} }
stream->increment_at(offset); stream->increment_at(offset);
@@ -639,7 +639,7 @@ boost::dynamic_bitset<> TokenFunc::asBinary(const Token& t) {
if (i-- == 0) { if (i-- == 0) {
break; break;
} }
if (value & (1 << (3 - j))) { if ((value & (1 << (3 - j))) != 0) {
bitset.set(i); bitset.set(i);
} }
} }
@@ -719,7 +719,7 @@ size_t IfcParse::IfcFile::load(unsigned entity_instance_name, const IfcParse::en
// If num_attributes is zero we know this is a top-level entity instance (or header entity) being parsed. // If num_attributes is zero we know this is a top-level entity instance (or header entity) being parsed.
// There can only be parsed one of these at a time, so we can reuse the vector we have defined at the file // There can only be parsed one of these at a time, so we can reuse the vector we have defined at the file
// scope. // scope.
if (entity) { if (entity != nullptr) {
vector = &internal_attribute_vector_; vector = &internal_attribute_vector_;
} else { } else {
vector = &internal_attribute_vector_simple_type_; vector = &internal_attribute_vector_simple_type_;
@@ -733,7 +733,7 @@ size_t IfcParse::IfcFile::load(unsigned entity_instance_name, const IfcParse::en
size_t return_value = 0; size_t return_value = 0;
while (next.startPos || next.lexer) { while ((next.startPos != 0U) || (next.lexer != nullptr)) {
if (TokenFunc::isOperator(next, ',')) { if (TokenFunc::isOperator(next, ',')) {
// do nothing // do nothing
} else if (TokenFunc::isOperator(next, ')')) { } else if (TokenFunc::isOperator(next, ')')) {
@@ -768,9 +768,9 @@ size_t IfcParse::IfcFile::load(unsigned entity_instance_name, const IfcParse::en
next = tokens->Next(); next = tokens->Next();
} }
if (vector) { if (vector != nullptr) {
// Obviously don't try and create a 0-length array. // Obviously don't try and create a 0-length array.
if (num_attributes || vector->size()) { if ((num_attributes != 0U) || !vector->empty()) {
// @todo figure out whether all this logic is still necessary, since we know the // @todo figure out whether all this logic is still necessary, since we know the
// expected amount of attributes and shouldn't be able to access more than allowed // expected amount of attributes and shouldn't be able to access more than allowed
// by the schema. // by the schema.
@@ -874,7 +874,7 @@ ArgumentList::operator aggregate_of_aggregate_of_instance::ptr() const {
l->push(e); l->push(e);
} else { } else {
auto token = dynamic_cast<const TokenArgument*>(arg); auto token = dynamic_cast<const TokenArgument*>(arg);
int startpos = token ? token->token.startPos : 0; int startpos = token != nullptr ? token->token.startPos : 0;
std::string string_rep = this->toString(); std::string string_rep = this->toString();
throw IfcInvalidTokenException(startpos, string_rep, "nested aggregate"); throw IfcInvalidTokenException(startpos, string_rep, "nested aggregate");
} }
@@ -1053,7 +1053,7 @@ void IfcParse::IfcFile::register_inverse(unsigned id_from, const IfcParse::entit
// Assume a check on token type has already been performed // Assume a check on token type has already been performed
auto e = from_entity; auto e = from_entity;
byref_excl[t.value_int].push_back(id_from); byref_excl[t.value_int].push_back(id_from);
while (e) { while (e != nullptr) {
byref[{t.value_int, e->index_in_schema(), attribute_index}].push_back(id_from); byref[{t.value_int, e->index_in_schema(), attribute_index}].push_back(id_from);
e = e->supertype(); e = e->supertype();
} }
@@ -1062,7 +1062,7 @@ void IfcParse::IfcFile::register_inverse(unsigned id_from, const IfcParse::entit
void IfcParse::IfcFile::register_inverse(unsigned id_from, const IfcParse::entity* from_entity, IfcUtil::IfcBaseClass* inst, int attribute_index) { void IfcParse::IfcFile::register_inverse(unsigned id_from, const IfcParse::entity* from_entity, IfcUtil::IfcBaseClass* inst, int attribute_index) {
auto e = from_entity; auto e = from_entity;
byref_excl[inst->data().id()].push_back(id_from); byref_excl[inst->data().id()].push_back(id_from);
while (e) { while (e != nullptr) {
byref[{inst->data().id(), e->index_in_schema(), attribute_index}].push_back(id_from); byref[{inst->data().id(), e->index_in_schema(), attribute_index}].push_back(id_from);
e = e->supertype(); e = e->supertype();
} }
@@ -1070,7 +1070,7 @@ void IfcParse::IfcFile::register_inverse(unsigned id_from, const IfcParse::entit
void IfcParse::IfcFile::unregister_inverse(unsigned id_from, const IfcParse::entity* from_entity, IfcUtil::IfcBaseClass* inst, int attribute_index) { void IfcParse::IfcFile::unregister_inverse(unsigned id_from, const IfcParse::entity* from_entity, IfcUtil::IfcBaseClass* inst, int attribute_index) {
auto e = from_entity; auto e = from_entity;
while (e) { while (e != nullptr) {
std::vector<int>& ids = byref[{inst->data().id(), e->index_in_schema(), attribute_index}]; std::vector<int>& ids = byref[{inst->data().id(), e->index_in_schema(), attribute_index}];
std::vector<int>::iterator it = std::find(ids.begin(), ids.end(), id_from); std::vector<int>::iterator it = std::find(ids.begin(), ids.end(), id_from);
if (it == ids.end()) { if (it == ids.end()) {
@@ -1105,13 +1105,13 @@ std::string IfcEntityInstanceData::toString(bool upper) const {
ss.imbue(std::locale::classic()); ss.imbue(std::locale::classic());
std::string dt; std::string dt;
if (type_) { if (type_ != nullptr) {
dt = type()->name(); dt = type()->name();
if (upper) { if (upper) {
boost::to_upper(dt); boost::to_upper(dt);
} }
if (type()->as_entity() || id_ != 0) { if ((type()->as_entity() != nullptr) || id_ != 0) {
ss << "#" << id_ << "="; ss << "#" << id_ << "=";
} }
} }
@@ -1182,7 +1182,7 @@ void IfcEntityInstanceData::load() const {
// type_ is 0 for header entities which have their size predetermined in code // type_ is 0 for header entities which have their size predetermined in code
// in that we have attributes_ pre-constructed to the correct size in the constructor // in that we have attributes_ pre-constructed to the correct size in the constructor
// in the other case load() will use a vector internally to grow to the size found in the file // in the other case load() will use a vector internally to grow to the size found in the file
size_t n = file->load(id(), type_ ? type_->as_entity() : nullptr, type_ ? tmp_data : attributes_, getArgumentCount()); size_t n = file->load(id(), type_ != nullptr ? type_->as_entity() : nullptr, type_ != nullptr ? tmp_data : attributes_, getArgumentCount());
if (n != getArgumentCount()) { if (n != getArgumentCount()) {
Logger::Error("Wrong number of attributes on instance with id #" + std::to_string(id_) + Logger::Error("Wrong number of attributes on instance with id #" + std::to_string(id_) +
" at offset " + std::to_string(this->offset_in_file()) + " at offset " + std::to_string(this->offset_in_file()) +
@@ -1193,7 +1193,7 @@ void IfcEntityInstanceData::load() const {
file->try_read_semicolon(); file->try_read_semicolon();
// @todo does this need to be atomic somehow? // @todo does this need to be atomic somehow?
if (tmp_data) { if (tmp_data != nullptr) {
attributes_ = tmp_data; attributes_ = tmp_data;
} }
} }
@@ -1203,14 +1203,14 @@ namespace {
// different handling of enumerations) // different handling of enumerations)
IfcUtil::ArgumentType get_argument_type(const IfcParse::declaration* decl, size_t i) { IfcUtil::ArgumentType get_argument_type(const IfcParse::declaration* decl, size_t i) {
const IfcParse::parameter_type* pt = 0; const IfcParse::parameter_type* pt = 0;
if (decl->as_entity()) { if (decl->as_entity() != nullptr) {
pt = decl->as_entity()->attribute_by_index(i)->type_of_attribute(); pt = decl->as_entity()->attribute_by_index(i)->type_of_attribute();
if (decl->as_entity()->derived()[i]) { if (decl->as_entity()->derived()[i]) {
return IfcUtil::Argument_DERIVED; return IfcUtil::Argument_DERIVED;
} }
} else if (decl->as_type_declaration() && i == 0) { } else if ((decl->as_type_declaration() != nullptr) && i == 0) {
pt = decl->as_type_declaration()->declared_type(); pt = decl->as_type_declaration()->declared_type();
} else if (decl->as_enumeration_type() && i == 0) { } else if ((decl->as_enumeration_type() != nullptr) && i == 0) {
return IfcUtil::Argument_ENUMERATION; return IfcUtil::Argument_ENUMERATION;
} }
@@ -1416,7 +1416,7 @@ void IfcEntityInstanceData::setArgument(size_t i, Argument* a, IfcUtil::Argument
// Remove leading and trailing '.' // Remove leading and trailing '.'
enum_literal = enum_literal.substr(1, enum_literal.size() - 2); enum_literal = enum_literal.substr(1, enum_literal.size() - 2);
const IfcParse::enumeration_type* enum_type = type()->as_enumeration_type() const IfcParse::enumeration_type* enum_type = type()->as_enumeration_type() != nullptr
? type()->as_enumeration_type() ? type()->as_enumeration_type()
: type()->as_entity()->attribute_by_index(i)->type_of_attribute()->as_named_type()->declared_type()->as_enumeration_type(); : type()->as_entity()->attribute_by_index(i)->type_of_attribute()->as_named_type()->declared_type()->as_enumeration_type();
@@ -1483,7 +1483,7 @@ void IfcEntityInstanceData::setArgument(size_t i, Argument* a, IfcUtil::Argument
break; break;
} }
if (!copy) { if (copy == nullptr) {
return; return;
} }
@@ -1492,10 +1492,10 @@ void IfcEntityInstanceData::setArgument(size_t i, Argument* a, IfcUtil::Argument
if (attributes_[i] != 0) { if (attributes_[i] != 0) {
Argument* current_attribute = attributes_[i]; Argument* current_attribute = attributes_[i];
if (this->file) { if (this->file != nullptr) {
// Deregister old attribute guid in file guid map. // Deregister old attribute guid in file guid map.
if (i == 0 && this->type() && this->file->ifcroot_type() && this->type()->is(*this->file->ifcroot_type())) { if (i == 0 && (this->type() != nullptr) && (this->file->ifcroot_type() != nullptr) && this->type()->is(*this->file->ifcroot_type())) {
try { try {
auto guid = (std::string)*current_attribute; auto guid = (std::string)*current_attribute;
auto it = this->file->internal_guid_map().find(guid); auto it = this->file->internal_guid_map().find(guid);
@@ -1514,7 +1514,7 @@ void IfcEntityInstanceData::setArgument(size_t i, Argument* a, IfcUtil::Argument
delete attributes_[i]; delete attributes_[i];
} }
if (this->file) { if (this->file != nullptr) {
// Register inverse indices in file // Register inverse indices in file
register_inverse_visitor visitor(*this->file, *this); register_inverse_visitor visitor(*this->file, *this);
apply_individual_instance_visitor(new_attribute, i).apply(visitor); apply_individual_instance_visitor(new_attribute, i).apply(visitor);
@@ -1523,8 +1523,8 @@ void IfcEntityInstanceData::setArgument(size_t i, Argument* a, IfcUtil::Argument
attributes_[i] = new_attribute; attributes_[i] = new_attribute;
// Register new attribute guid in guid map // Register new attribute guid in guid map
if (this->file) { if (this->file != nullptr) {
if (i == 0 && this->type() && this->file->ifcroot_type() && this->type()->is(*this->file->ifcroot_type())) { if (i == 0 && (this->type() != nullptr) && (this->file->ifcroot_type() != nullptr) && this->type()->is(*this->file->ifcroot_type())) {
try { try {
auto guid = (std::string)*new_attribute; auto guid = (std::string)*new_attribute;
auto it = this->file->internal_guid_map().find(guid); auto it = this->file->internal_guid_map().find(guid);
@@ -1662,7 +1662,7 @@ void IfcFile::initialize_(IfcParse::IfcSpfStream* s) {
/// @todo Printing to stdout in a library class feels weird. Maybe move the progress prints to the client code? /// @todo Printing to stdout in a library class feels weird. Maybe move the progress prints to the client code?
// Update the status after every 1000 instances parsed // Update the status after every 1000 instances parsed
if (!((++progress) % 1000)) { if (((++progress) % 1000) == 0) {
std::stringstream ss; std::stringstream ss;
ss << "\r#" << current_id; ss << "\r#" << current_id;
Logger::Status(ss.str(), false); Logger::Status(ss.str(), false);
@@ -1708,7 +1708,7 @@ void IfcFile::initialize_(IfcParse::IfcSpfStream* s) {
} }
insts->push(instance); insts->push(instance);
const IfcParse::declaration* pt = ty->as_entity()->supertype(); const IfcParse::declaration* pt = ty->as_entity()->supertype();
if (pt) { if (pt != nullptr) {
ty = pt; ty = pt;
} else { } else {
break; break;
@@ -1723,7 +1723,7 @@ void IfcFile::initialize_(IfcParse::IfcSpfStream* s) {
byid[current_id] = instance; byid[current_id] = instance;
MaxId = (std::max)(MaxId, current_id); MaxId = (std::max)(MaxId, current_id);
} else if (token_stream[0].type == IfcParse::Token_IDENTIFIER && instance) { } else if (token_stream[0].type == IfcParse::Token_IDENTIFIER && (instance != nullptr)) {
register_inverse(current_id, instance->declaration().as_entity(), token_stream[0], attribute_index); register_inverse(current_id, instance->declaration().as_entity(), token_stream[0], attribute_index);
} else if (token_stream[0].type == IfcParse::Token_OPERATOR && token_stream[0].value_char == '(') { } else if (token_stream[0].type == IfcParse::Token_OPERATOR && token_stream[0].value_char == '(') {
paren_stack_depth++; paren_stack_depth++;
@@ -1913,7 +1913,7 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity, int id)
// See whether the instance is already part of a file // See whether the instance is already part of a file
if (entity->data().file != 0) { if (entity->data().file != 0) {
if (entity->data().file == this) { if (entity->data().file == this) {
if (!entity->declaration().as_entity()) { if (entity->declaration().as_entity() == nullptr) {
// While not a mapping that can be queried, we do need to free the instance later on // While not a mapping that can be queried, we do need to free the instance later on
byidentity[new_entity->identity()] = new_entity; byidentity[new_entity->identity()] = new_entity;
} }
@@ -1939,13 +1939,13 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity, int id)
IfcUtil::ArgumentType attr_type = attr->type(); IfcUtil::ArgumentType attr_type = attr->type();
IfcParse::declaration* decl = 0; IfcParse::declaration* decl = 0;
if (entity->declaration().as_entity()) { if (entity->declaration().as_entity() != nullptr) {
decl = 0; decl = 0;
const parameter_type* pt = entity->declaration().as_entity()->attribute_by_index(i)->type_of_attribute(); const parameter_type* pt = entity->declaration().as_entity()->attribute_by_index(i)->type_of_attribute();
while (pt->as_aggregation_type()) { while (pt->as_aggregation_type() != nullptr) {
pt = pt->as_aggregation_type()->type_of_element(); pt = pt->as_aggregation_type()->type_of_element();
} }
if (pt->as_named_type()) { if (pt->as_named_type() != nullptr) {
decl = pt->as_named_type()->declared_type(); decl = pt->as_named_type()->declared_type();
} }
} }
@@ -1991,7 +1991,7 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity, int id)
IfcWrite::IfcWriteArgument* copy = new IfcWrite::IfcWriteArgument(); IfcWrite::IfcWriteArgument* copy = new IfcWrite::IfcWriteArgument();
copy->set(new_instances); copy->set(new_instances);
we->setArgument(i, copy); we->setArgument(i, copy);
} else if (decl && decl->is(*schema()->declaration_by_name("IfcLengthMeasure"))) { } else if ((decl != nullptr) && decl->is(*schema()->declaration_by_name("IfcLengthMeasure"))) {
if (boost::math::isnan(conversion_factor)) { if (boost::math::isnan(conversion_factor)) {
std::pair<IfcUtil::IfcBaseClass*, double> this_file_unit = {nullptr, 1.0}; std::pair<IfcUtil::IfcBaseClass*, double> this_file_unit = {nullptr, 1.0};
std::pair<IfcUtil::IfcBaseClass*, double> other_file_unit = {nullptr, 1.0}; std::pair<IfcUtil::IfcBaseClass*, double> other_file_unit = {nullptr, 1.0};
@@ -2000,7 +2000,7 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity, int id)
other_file_unit = other_file->getUnit("LENGTHUNIT"); other_file_unit = other_file->getUnit("LENGTHUNIT");
} catch (IfcParse::IfcException&) { } catch (IfcParse::IfcException&) {
} }
if (this_file_unit.first && other_file_unit.first) { if ((this_file_unit.first != nullptr) && (other_file_unit.first != nullptr)) {
conversion_factor = other_file_unit.second / this_file_unit.second; conversion_factor = other_file_unit.second / this_file_unit.second;
} else { } else {
conversion_factor = 1.; conversion_factor = 1.;
@@ -2041,7 +2041,7 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity, int id)
// A new entity instance name is generated and // A new entity instance name is generated and
// the instance is pointed to this file. // the instance is pointed to this file.
we->file = this; we->file = this;
if (we->type()->as_entity()) { if (we->type()->as_entity() != nullptr) {
if (id == -1) { if (id == -1) {
we->set_id(FreshId()); we->set_id(FreshId());
} else { } else {
@@ -2073,7 +2073,7 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity, int id)
// The mapping by entity type is updated. // The mapping by entity type is updated.
const IfcParse::declaration* ty = &new_entity->declaration(); const IfcParse::declaration* ty = &new_entity->declaration();
if (ty->as_entity()) { if (ty->as_entity() != nullptr) {
aggregate_of_instance::ptr insts = instances_by_type_excl_subtypes(ty); aggregate_of_instance::ptr insts = instances_by_type_excl_subtypes(ty);
if (!insts) { if (!insts) {
insts = aggregate_of_instance::ptr(new aggregate_of_instance()); insts = aggregate_of_instance::ptr(new aggregate_of_instance());
@@ -2082,7 +2082,7 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity, int id)
insts->push(new_entity); insts->push(new_entity);
} }
for (; ty->as_entity();) { for (; ty->as_entity() != nullptr;) {
aggregate_of_instance::ptr insts = instances_by_type(ty); aggregate_of_instance::ptr insts = instances_by_type(ty);
if (!insts) { if (!insts) {
insts = aggregate_of_instance::ptr(new aggregate_of_instance()); insts = aggregate_of_instance::ptr(new aggregate_of_instance());
@@ -2091,16 +2091,16 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity, int id)
insts->push(new_entity); insts->push(new_entity);
const IfcParse::declaration* pt = ty->as_entity()->supertype(); const IfcParse::declaration* pt = ty->as_entity()->supertype();
if (pt) { if (pt != nullptr) {
ty = pt; ty = pt;
} else { } else {
break; break;
} }
} }
if (ty->as_entity()) { if (ty->as_entity() != nullptr) {
int new_id = -1; int new_id = -1;
if (!new_entity->data().file) { if (new_entity->data().file == nullptr) {
// For newly created entities ensure a valid ENTITY_INSTANCE_NAME is set // For newly created entities ensure a valid ENTITY_INSTANCE_NAME is set
new_entity->data().file = this; new_entity->data().file = this;
boost::optional<unsigned> id_value; boost::optional<unsigned> id_value;
@@ -2124,7 +2124,7 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity, int id)
// The mapping by entity instance name is updated. // The mapping by entity instance name is updated.
byid[new_id] = new_entity; byid[new_id] = new_entity;
} else if (!new_entity->data().file) { } else if (new_entity->data().file == nullptr) {
// For non-entity instances, no mappings are updated, but the file // For non-entity instances, no mappings are updated, but the file
// pointer has to be set, so that actual copies are created in subsequent // pointer has to be set, so that actual copies are created in subsequent
// times. // times.
@@ -2134,7 +2134,7 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity, int id)
byidentity[new_entity->identity()] = new_entity; byidentity[new_entity->identity()] = new_entity;
} }
if (parsing_complete_ && ty->as_entity()) { if (parsing_complete_ && (ty->as_entity() != nullptr)) {
build_inverses_(new_entity); build_inverses_(new_entity);
} }
@@ -2213,7 +2213,7 @@ void IfcFile::process_deletion_() {
if (instance_list->contains(entity)) { if (instance_list->contains(entity)) {
IfcWrite::IfcWriteArgument* copy = new IfcWrite::IfcWriteArgument(); IfcWrite::IfcWriteArgument* copy = new IfcWrite::IfcWriteArgument();
instance_list->remove(entity); instance_list->remove(entity);
if (!instance_list->size() && related_instance->declaration().as_entity()->attribute_by_index(i)->optional()) { if ((instance_list->size() == 0U) && related_instance->declaration().as_entity()->attribute_by_index(i)->optional()) {
// @todo we can also check the lower bound of the attribute type before setting to null. // @todo we can also check the lower bound of the attribute type before setting to null.
copy->set(boost::blank()); copy->set(boost::blank());
} else { } else {
@@ -2317,7 +2317,7 @@ void IfcFile::process_deletion_() {
} }
const IfcParse::declaration* pt = ty->as_entity()->supertype(); const IfcParse::declaration* pt = ty->as_entity()->supertype();
if (pt) { if (pt != nullptr) {
ty = pt; ty = pt;
} else { } else {
break; break;
@@ -2473,7 +2473,7 @@ std::ostream& operator<<(std::ostream& os, const IfcParse::IfcFile& f) {
for (vector_t::const_iterator it = sorted.begin(); it != sorted.end(); ++it) { for (vector_t::const_iterator it = sorted.begin(); it != sorted.end(); ++it) {
const IfcUtil::IfcBaseClass* e = it->second; const IfcUtil::IfcBaseClass* e = it->second;
if (e->declaration().as_entity()) { if (e->declaration().as_entity() != nullptr) {
os << e->data().toString(true) << ";" << std::endl; os << e->data().toString(true) << ";" << std::endl;
} }
} }
@@ -2493,7 +2493,7 @@ std::string IfcFile::createTimestamp() const {
struct tm* ti = localtime(&t); struct tm* ti = localtime(&t);
std::string result = ""; std::string result = "";
if (strftime(buf, 255, "%Y-%m-%dT%H:%M:%S", ti)) { if (strftime(buf, 255, "%Y-%m-%dT%H:%M:%S", ti) != 0U) {
result = std::string(buf); result = std::string(buf);
} }
@@ -2578,7 +2578,7 @@ void IfcFile::setDefaultHeaderValues() {
std::vector<std::string> file_description, schema_identifiers, empty_vector; std::vector<std::string> file_description, schema_identifiers, empty_vector;
file_description.push_back("ViewDefinition [CoordinationView]"); file_description.push_back("ViewDefinition [CoordinationView]");
if (schema()) { if (schema() != nullptr) {
schema_identifiers.push_back(schema()->name()); schema_identifiers.push_back(schema()->name());
} }
@@ -2648,7 +2648,7 @@ std::pair<IfcUtil::IfcBaseClass*, double> IfcFile::getUnit(const std::string& un
return_value.first = siunit = unit; return_value.first = siunit = unit;
} }
if (siunit) { if (siunit != nullptr) {
Argument* prefix = siunit->data().getArgument( Argument* prefix = siunit->data().getArgument(
siunit->declaration().as_entity()->attribute_index("Prefix")); siunit->declaration().as_entity()->attribute_index("Prefix"));
@@ -2665,11 +2665,11 @@ std::pair<IfcUtil::IfcBaseClass*, double> IfcFile::getUnit(const std::string& un
void IfcParse::IfcFile::build_inverses_(IfcUtil::IfcBaseClass* inst) { void IfcParse::IfcFile::build_inverses_(IfcUtil::IfcBaseClass* inst) {
std::function<void(IfcUtil::IfcBaseClass*, int)> fn = [this, inst](IfcUtil::IfcBaseClass* attr, int idx) { std::function<void(IfcUtil::IfcBaseClass*, int)> fn = [this, inst](IfcUtil::IfcBaseClass* attr, int idx) {
if (attr->declaration().as_entity()) { if (attr->declaration().as_entity() != nullptr) {
unsigned entity_attribute_id = attr->data().id(); unsigned entity_attribute_id = attr->data().id();
auto decl = inst->declaration().as_entity(); auto decl = inst->declaration().as_entity();
byref_excl[entity_attribute_id].push_back(inst->data().id()); byref_excl[entity_attribute_id].push_back(inst->data().id());
while (decl) { while (decl != nullptr) {
byref[{entity_attribute_id, decl->index_in_schema(), idx}].push_back(inst->data().id()); byref[{entity_attribute_id, decl->index_in_schema(), idx}].push_back(inst->data().id());
decl = decl->supertype(); decl = decl->supertype();
} }
+11 -11
View File
@@ -72,12 +72,12 @@ bool IfcParse::declaration::is(const std::string& name) const {
return true; return true;
} }
if (this->as_entity() && this->as_entity()->supertype()) { if ((this->as_entity() != nullptr) && (this->as_entity()->supertype() != nullptr)) {
return this->as_entity()->supertype()->is(name); return this->as_entity()->supertype()->is(name);
} }
if (this->as_type_declaration()) { if (this->as_type_declaration() != nullptr) {
const IfcParse::named_type* nt = this->as_type_declaration()->declared_type()->as_named_type(); const IfcParse::named_type* nt = this->as_type_declaration()->declared_type()->as_named_type();
if (nt) { if (nt != nullptr) {
return nt->is(name); return nt->is(name);
} }
} }
@@ -90,12 +90,12 @@ bool IfcParse::declaration::is(const IfcParse::declaration& decl) const {
return true; return true;
} }
if (this->as_entity() && this->as_entity()->supertype()) { if ((this->as_entity() != nullptr) && (this->as_entity()->supertype() != nullptr)) {
return this->as_entity()->supertype()->is(decl); return this->as_entity()->supertype()->is(decl);
} }
if (this->as_type_declaration()) { if (this->as_type_declaration() != nullptr) {
const IfcParse::named_type* nt = this->as_type_declaration()->declared_type()->as_named_type(); const IfcParse::named_type* nt = this->as_type_declaration()->declared_type()->as_named_type();
if (nt) { if (nt != nullptr) {
return nt->is(decl); return nt->is(decl);
} }
} }
@@ -129,16 +129,16 @@ IfcParse::schema_definition::schema_definition(const std::string& name, const st
for (std::vector<const declaration*>::iterator it = declarations_.begin(); it != declarations_.end(); ++it) { for (std::vector<const declaration*>::iterator it = declarations_.begin(); it != declarations_.end(); ++it) {
(**it).schema_ = this; (**it).schema_ = this;
if ((**it).as_type_declaration()) { if ((**it).as_type_declaration() != nullptr) {
type_declarations_.push_back((**it).as_type_declaration()); type_declarations_.push_back((**it).as_type_declaration());
} }
if ((**it).as_select_type()) { if ((**it).as_select_type() != nullptr) {
select_types_.push_back((**it).as_select_type()); select_types_.push_back((**it).as_select_type());
} }
if ((**it).as_enumeration_type()) { if ((**it).as_enumeration_type() != nullptr) {
enumeration_types_.push_back((**it).as_enumeration_type()); enumeration_types_.push_back((**it).as_enumeration_type());
} }
if ((**it).as_entity()) { if ((**it).as_entity() != nullptr) {
entities_.push_back((**it).as_entity()); entities_.push_back((**it).as_entity());
} }
} }
@@ -153,7 +153,7 @@ IfcParse::schema_definition::~schema_definition() {
} }
IfcUtil::IfcBaseClass* IfcParse::schema_definition::instantiate(IfcEntityInstanceData* data) const { IfcUtil::IfcBaseClass* IfcParse::schema_definition::instantiate(IfcEntityInstanceData* data) const {
if (factory_) { if (factory_ != nullptr) {
return (*factory_)(data); return (*factory_)(data);
} }
return new IfcUtil::IfcLateBoundEntity(data->type(), data); return new IfcUtil::IfcLateBoundEntity(data->type(), data);
+4 -4
View File
@@ -319,7 +319,7 @@ class IFC_PARSE_API entity : public declaration {
const attribute* attribute_by_index_(size_t& index) const { const attribute* attribute_by_index_(size_t& index) const {
const attribute* attr = 0; const attribute* attr = 0;
if (supertype_) { if (supertype_ != nullptr) {
attr = supertype_->attribute_by_index_(index); attr = supertype_->attribute_by_index_(index);
} }
if (attr == 0) { if (attr == 0) {
@@ -361,7 +361,7 @@ class IFC_PARSE_API entity : public declaration {
const std::vector<const attribute*> all_attributes() const { const std::vector<const attribute*> all_attributes() const {
std::vector<const attribute*> attrs; std::vector<const attribute*> attrs;
attrs.reserve(derived_.size()); attrs.reserve(derived_.size());
if (supertype_) { if (supertype_ != nullptr) {
const std::vector<const attribute*> supertype_attrs = supertype_->all_attributes(); const std::vector<const attribute*> supertype_attrs = supertype_->all_attributes();
std::copy(supertype_attrs.begin(), supertype_attrs.end(), std::back_inserter(attrs)); std::copy(supertype_attrs.begin(), supertype_attrs.end(), std::back_inserter(attrs));
} }
@@ -371,7 +371,7 @@ class IFC_PARSE_API entity : public declaration {
const std::vector<const inverse_attribute*> all_inverse_attributes() const { const std::vector<const inverse_attribute*> all_inverse_attributes() const {
std::vector<const inverse_attribute*> attrs; std::vector<const inverse_attribute*> attrs;
if (supertype_) { if (supertype_ != nullptr) {
const std::vector<const inverse_attribute*> supertype_inv_attrs = supertype_->all_inverse_attributes(); const std::vector<const inverse_attribute*> supertype_inv_attrs = supertype_->all_inverse_attributes();
std::copy(supertype_inv_attrs.begin(), supertype_inv_attrs.end(), std::back_inserter(attrs)); std::copy(supertype_inv_attrs.begin(), supertype_inv_attrs.end(), std::back_inserter(attrs));
} }
@@ -389,7 +389,7 @@ class IFC_PARSE_API entity : public declaration {
size_t attribute_count() const { size_t attribute_count() const {
size_t super_count = 0; size_t super_count = 0;
if (supertype_) { if (supertype_ != nullptr) {
super_count = supertype_->attribute_count(); super_count = supertype_->attribute_count();
} }
return super_count + attributes_.size(); return super_count + attributes_.size();
+19 -19
View File
@@ -40,7 +40,7 @@ HeaderEntity::HeaderEntity(const char* const datatype, size_t size, IfcFile* fil
: IfcEntityInstanceData(file, size), : IfcEntityInstanceData(file, size),
_datatype(datatype), _datatype(datatype),
size_(size) { size_(size) {
if (file) { if (file != nullptr) {
offset_in_file_ = file->stream->Tell(); offset_in_file_ = file->stream->Tell();
load(); load();
} }
@@ -131,45 +131,45 @@ void IfcSpfHeader::write(std::ostream& os) const {
} }
const FileDescription& IfcSpfHeader::file_description() const { const FileDescription& IfcSpfHeader::file_description() const {
if (_file_description) { if (_file_description == nullptr) {
return *_file_description; throw IfcException("File description not set");
} }
throw IfcException("File description not set"); return *_file_description;
} }
const FileName& IfcSpfHeader::file_name() const { const FileName& IfcSpfHeader::file_name() const {
if (_file_name) { if (_file_name == nullptr) {
return *_file_name; throw IfcException("File name not set");
} }
throw IfcException("File name not set"); return *_file_name;
} }
const FileSchema& IfcSpfHeader::file_schema() const { const FileSchema& IfcSpfHeader::file_schema() const {
if (_file_schema) { if (_file_schema == nullptr) {
return *_file_schema; throw IfcException("File schema not set");
} }
throw IfcException("File schema not set"); return *_file_schema;
} }
FileDescription& IfcSpfHeader::file_description() { FileDescription& IfcSpfHeader::file_description() {
if (_file_description) { if (_file_description == nullptr) {
return *_file_description; throw IfcException("File description not set");
} }
throw IfcException("File description not set"); return *_file_description;
} }
FileName& IfcSpfHeader::file_name() { FileName& IfcSpfHeader::file_name() {
if (_file_name) { if (_file_name == nullptr) {
return *_file_name; throw IfcException("File name not set");
} }
throw IfcException("File name not set"); return *_file_name;
} }
FileSchema& IfcSpfHeader::file_schema() { FileSchema& IfcSpfHeader::file_schema() {
if (_file_schema) { if (_file_schema == nullptr) {
return *_file_schema; throw IfcException("File schema not set");
} }
throw IfcException("File schema not set"); return *_file_schema;
} }
FileDescription::FileDescription(IfcFile* file) : HeaderEntity(FILE_DESCRIPTION, 2, file) {} FileDescription::FileDescription(IfcFile* file) : HeaderEntity(FILE_DESCRIPTION, 2, file) {}
+10 -10
View File
@@ -62,14 +62,14 @@
#include <boost/optional.hpp> #include <boost/optional.hpp>
void aggregate_of_instance::push(IfcUtil::IfcBaseClass* l) { void aggregate_of_instance::push(IfcUtil::IfcBaseClass* l) {
if (l) { if (l != nullptr) {
ls.push_back(l); ls.push_back(l);
} }
} }
void aggregate_of_instance::push(const aggregate_of_instance::ptr& l) { void aggregate_of_instance::push(const aggregate_of_instance::ptr& l) {
if (l) { if (l) {
for (it i = l->begin(); i != l->end(); ++i) { for (it i = l->begin(); i != l->end(); ++i) {
if (*i) { if (*i != nullptr) {
ls.push_back(*i); ls.push_back(*i);
} }
} }
@@ -253,23 +253,23 @@ IfcUtil::ArgumentType IfcUtil::from_parameter_type(const IfcParse::parameter_typ
const IfcParse::named_type* nt = pt->as_named_type(); const IfcParse::named_type* nt = pt->as_named_type();
const IfcParse::simple_type* st = pt->as_simple_type(); const IfcParse::simple_type* st = pt->as_simple_type();
if (at) { if (at != nullptr) {
return make_aggregate(from_parameter_type(at->type_of_element())); return make_aggregate(from_parameter_type(at->type_of_element()));
} }
if (nt) { if (nt != nullptr) {
if (nt->declared_type()->as_entity()) { if (nt->declared_type()->as_entity() != nullptr) {
return IfcUtil::Argument_ENTITY_INSTANCE; return IfcUtil::Argument_ENTITY_INSTANCE;
} }
if (nt->declared_type()->as_enumeration_type()) { if (nt->declared_type()->as_enumeration_type() != nullptr) {
return IfcUtil::Argument_ENUMERATION; return IfcUtil::Argument_ENUMERATION;
} }
if (nt->declared_type()->as_select_type()) { if (nt->declared_type()->as_select_type() != nullptr) {
return IfcUtil::Argument_ENTITY_INSTANCE; return IfcUtil::Argument_ENTITY_INSTANCE;
} }
if (nt->declared_type()->as_type_declaration()) { if (nt->declared_type()->as_type_declaration() != nullptr) {
return from_parameter_type(nt->declared_type()->as_type_declaration()->declared_type()); return from_parameter_type(nt->declared_type()->as_type_declaration()->declared_type());
} }
} else if (st) { } else if (st != nullptr) {
switch (st->declared_type()) { switch (st->declared_type()) {
case IfcParse::simple_type::binary_type: case IfcParse::simple_type::binary_type:
return IfcUtil::Argument_BINARY; return IfcUtil::Argument_BINARY;
@@ -336,7 +336,7 @@ IFC_PARSE_API bool IfcUtil::path::rename_file(const std::string& old_filename, c
} }
IFC_PARSE_API bool IfcUtil::path::delete_file(const std::string& filename) { IFC_PARSE_API bool IfcUtil::path::delete_file(const std::string& filename) {
return std::remove(filename.c_str()); return std::remove(filename.c_str()) != 0;
} }
#endif #endif
+2 -2
View File
@@ -145,7 +145,7 @@ class StringBuilderVisitor : public boost::static_visitor<void> {
} }
void operator()(const IfcUtil::IfcBaseClass* const& i) { void operator()(const IfcUtil::IfcBaseClass* const& i) {
const IfcEntityInstanceData& e = i->data(); const IfcEntityInstanceData& e = i->data();
if (!e.type()->as_entity()) { if (e.type()->as_entity() == nullptr) {
data << e.toString(upper); data << e.toString(upper);
} else { } else {
data << "#" << e.id(); data << "#" << e.id();
@@ -309,7 +309,7 @@ void IfcWriteArgument::set(const aggregate_of_aggregate_of_instance::ptr& v) {
// Overload to detect null values // Overload to detect null values
void IfcWriteArgument::set(IfcUtil::IfcBaseInterface* const& v) { void IfcWriteArgument::set(IfcUtil::IfcBaseInterface* const& v) {
if (v) { if (v != nullptr) {
container = v->as<IfcUtil::IfcBaseClass>(); container = v->as<IfcUtil::IfcBaseClass>();
} else { } else {
container = boost::blank(); container = boost::blank();
+23 -24
View File
@@ -45,8 +45,8 @@ enum ifcxml_dialect {
// "Dereferences" a named_attribute. For example: // "Dereferences" a named_attribute. For example:
// IfcCompoundPlaneAngleMeasure -> LIST [3:4] OF INTEGER // IfcCompoundPlaneAngleMeasure -> LIST [3:4] OF INTEGER
void follow_named(const IfcParse::parameter_type*& pt) { void follow_named(const IfcParse::parameter_type*& pt) {
while (pt->as_named_type()) { while (pt->as_named_type() != nullptr) {
if (pt->as_named_type()->declared_type()->as_type_declaration()) { if (pt->as_named_type()->declared_type()->as_type_declaration() != nullptr) {
pt = pt->as_named_type()->declared_type()->as_type_declaration()->declared_type(); pt = pt->as_named_type()->declared_type()->as_type_declaration()->declared_type();
} else { } else {
break; break;
@@ -164,7 +164,7 @@ class stack_node {
std::stringstream ss; std::stringstream ss;
static const char* const node_type_names[] = {"empty", "inst", "attr", "aggr", "agelem", "inv", "sel", "head", "hdentry"}; static const char* const node_type_names[] = {"empty", "inst", "attr", "aggr", "agelem", "inv", "sel", "head", "hdentry"};
ss << "[" << node_type_names[type_] << "] "; ss << "[" << node_type_names[type_] << "] ";
if (inst_) { if (inst_ != nullptr) {
ss << inst_->declaration().name() << " "; ss << inst_->declaration().name() << " ";
} }
if (type_ == node_aggregate) { if (type_ == node_aggregate) {
@@ -288,7 +288,7 @@ static void process_characters(void* user, const xmlChar* ch, int len) {
state_type = state->stack.back().ntype(); state_type = state->stack.back().ntype();
} }
if (!state->stack.empty() && state->stack.back().inst() != nullptr && state->stack.back().inst()->declaration().as_type_declaration()) { if (!state->stack.empty() && state->stack.back().inst() != nullptr && (state->stack.back().inst()->declaration().as_type_declaration() != nullptr)) {
auto pt = state->stack.back().inst()->declaration().as_type_declaration()->declared_type(); auto pt = state->stack.back().inst()->declaration().as_type_declaration()->declared_type();
Argument* val = nullptr; Argument* val = nullptr;
try { try {
@@ -296,7 +296,7 @@ static void process_characters(void* user, const xmlChar* ch, int len) {
} catch (const std::exception& e) { } catch (const std::exception& e) {
Logger::Error(e, state->stack.back().inst()); Logger::Error(e, state->stack.back().inst());
} }
if (val) { if (val != nullptr) {
// type declaration always at idx 0 // type declaration always at idx 0
state->stack.back().inst()->data().setArgument(0, val); state->stack.back().inst()->data().setArgument(0, val);
} }
@@ -327,14 +327,14 @@ static void process_characters(void* user, const xmlChar* ch, int len) {
auto cpp_type = IfcUtil::from_parameter_type(pt); auto cpp_type = IfcUtil::from_parameter_type(pt);
if (cpp_type != IfcUtil::Argument_ENTITY_INSTANCE) { if (cpp_type != IfcUtil::Argument_ENTITY_INSTANCE) {
auto val = parse_attribute_value(pt, txt); auto val = parse_attribute_value(pt, txt);
if (val) { if (val != nullptr) {
state->stack.back().inst()->data().setArgument(state->stack.back().idx(), val); state->stack.back().inst()->data().setArgument(state->stack.back().idx(), val);
} }
} }
} else if (state_type == stack_node::node_aggregate_element) { } else if (state_type == stack_node::node_aggregate_element) {
auto pt = state->stack.back().aggregate_elem_type(); auto pt = state->stack.back().aggregate_elem_type();
auto val = parse_attribute_value(pt, txt); auto val = parse_attribute_value(pt, txt);
if (val) { if (val != nullptr) {
(*(state->stack.rbegin() + 1)).aggregate_elements.push_back(val); (*(state->stack.rbegin() + 1)).aggregate_elements.push_back(val);
} }
} }
@@ -357,11 +357,11 @@ static void start_element(void* user, const xmlChar* tag, const xmlChar** attrs)
std::vector<std::pair<std::string, std::string>> attributes; std::vector<std::pair<std::string, std::string>> attributes;
if (attrs) { if (attrs != nullptr) {
std::string attrname; std::string attrname;
int i = 0; int i = 0;
while (attrs[i] != NULL) { while (attrs[i] != NULL) {
if (i % 2) { if ((i % 2) != 0) {
const std::string value = (char*)attrs[i]; const std::string value = (char*)attrs[i];
#ifndef NDEBUG #ifndef NDEBUG
std::cout << " " << attrname << "='" << value << "'"; std::cout << " " << attrname << "='" << value << "'";
@@ -444,10 +444,9 @@ static void start_element(void* user, const xmlChar* tag, const xmlChar** attrs)
if (state->idmap.find(pair.second) == state->idmap.end()) { if (state->idmap.find(pair.second) == state->idmap.end()) {
rv = pair.second; rv = pair.second;
return rv; return rv;
} else {
rv = state->file->instance_by_id(state->idmap[pair.second]);
return rv;
} }
rv = state->file->instance_by_id(state->idmap[pair.second]);
return rv;
} }
} else if (pair.first == "xsi:type") { } else if (pair.first == "xsi:type") {
decl = state->file->schema()->declaration_by_name(pair.second)->as_entity(); decl = state->file->schema()->declaration_by_name(pair.second)->as_entity();
@@ -457,7 +456,7 @@ static void start_element(void* user, const xmlChar* tag, const xmlChar** attrs)
auto untyped = new IfcEntityInstanceData(decl); auto untyped = new IfcEntityInstanceData(decl);
const IfcParse::entity* entity = decl->as_entity(); const IfcParse::entity* entity = decl->as_entity();
if (entity) { if (entity != nullptr) {
for (auto& pair : attributes) { for (auto& pair : attributes) {
if (pair.first == "id" || pair.first == "xsi:type" || pair.first == "pos") { if (pair.first == "id" || pair.first == "xsi:type" || pair.first == "pos") {
continue; continue;
@@ -467,7 +466,7 @@ static void start_element(void* user, const xmlChar* tag, const xmlChar** attrs)
if (idx != -1) { if (idx != -1) {
auto attr = entity->attribute_by_index(idx); auto attr = entity->attribute_by_index(idx);
auto val = parse_attribute_value(attr->type_of_attribute(), pair.second); auto val = parse_attribute_value(attr->type_of_attribute(), pair.second);
if (val) { if (val != nullptr) {
untyped->setArgument(idx, val); untyped->setArgument(idx, val);
} }
} else { } else {
@@ -522,7 +521,7 @@ static void start_element(void* user, const xmlChar* tag, const xmlChar** attrs)
boost::lexical_cast<int>(it->second); boost::lexical_cast<int>(it->second);
*/ */
if (element_type->as_simple_type()) { if (element_type->as_simple_type() != nullptr) {
state->stack.push_back(stack_node::aggregate_element(element_type, aggrpos)); state->stack.push_back(stack_node::aggregate_element(element_type, aggrpos));
} else { } else {
const IfcParse::declaration* decl = nullptr; const IfcParse::declaration* decl = nullptr;
@@ -531,7 +530,7 @@ static void start_element(void* user, const xmlChar* tag, const xmlChar** attrs)
} catch (const std::exception& e) { } catch (const std::exception& e) {
Logger::Error(e); Logger::Error(e);
} }
if (decl) { if (decl != nullptr) {
auto inst_or_ref = create_instance(decl); auto inst_or_ref = create_instance(decl);
IfcUtil::IfcBaseClass* inst; IfcUtil::IfcBaseClass* inst;
Argument* attr; Argument* attr;
@@ -581,7 +580,7 @@ static void start_element(void* user, const xmlChar* tag, const xmlChar** attrs)
const IfcParse::parameter_type* attribute_type = current->attribute_by_index(idx)->type_of_attribute(); const IfcParse::parameter_type* attribute_type = current->attribute_by_index(idx)->type_of_attribute();
if (state->dialect == ifcxml_dialect_ifc2x3) { if (state->dialect == ifcxml_dialect_ifc2x3) {
follow_named(attribute_type); follow_named(attribute_type);
if (attribute_type->as_aggregation_type()) { if (attribute_type->as_aggregation_type() != nullptr) {
state->stack.push_back(stack_node::aggregate(state->stack.back().inst(), idx)); state->stack.push_back(stack_node::aggregate(state->stack.back().inst(), idx));
} else { } else {
state->stack.push_back(stack_node::instance_attribute(state->stack.back().inst(), idx)); state->stack.push_back(stack_node::instance_attribute(state->stack.back().inst(), idx));
@@ -595,17 +594,17 @@ static void start_element(void* user, const xmlChar* tag, const xmlChar** attrs)
instance_to_attribute(inst_or_reference, attr, newinst); instance_to_attribute(inst_or_reference, attr, newinst);
state->stack.back().inst()->data().setArgument(idx, attr); state->stack.back().inst()->data().setArgument(idx, attr);
state->stack.push_back(stack_node::instance(id_in_file, newinst)); state->stack.push_back(stack_node::instance(id_in_file, newinst));
} else if (attribute_type->as_named_type()->declared_type()->as_select_type()) { } else if (attribute_type->as_named_type()->declared_type()->as_select_type() != nullptr) {
// Select types cause an additional indirection, so the current stack node is simply repeated // Select types cause an additional indirection, so the current stack node is simply repeated
state->stack.push_back(stack_node::select(state->stack.back().inst(), idx)); state->stack.push_back(stack_node::select(state->stack.back().inst(), idx));
} }
} else if (attribute_type->as_aggregation_type()) { } else if (attribute_type->as_aggregation_type() != nullptr) {
state->stack.push_back(stack_node::aggregate(state->stack.back().inst(), idx)); state->stack.push_back(stack_node::aggregate(state->stack.back().inst(), idx));
} }
} }
} }
} }
} else if (state->file) { } else if (state->file != nullptr) {
if (state_type == stack_node::node_header) { if (state_type == stack_node::node_header) {
state->stack.push_back(stack_node::header_entry(tagname)); state->stack.push_back(stack_node::header_entry(tagname));
} else if (tagname == "ex:iso_10303_28_header" || tagname == "header") { } else if (tagname == "ex:iso_10303_28_header" || tagname == "header") {
@@ -620,12 +619,12 @@ static void start_element(void* user, const xmlChar* tag, const xmlChar** attrs)
Logger::Error(e); Logger::Error(e);
} }
if (!decl) { if (decl == nullptr) {
goto end; goto end;
} }
const IfcParse::entity* entity = decl->as_entity(); const IfcParse::entity* entity = decl->as_entity();
if (!entity && state_type != stack_node::node_instance_attribute) { if ((entity == nullptr) && state_type != stack_node::node_instance_attribute) {
Logger::Error("Not an entity definition " + tagname); Logger::Error("Not an entity definition " + tagname);
goto end; goto end;
} }
@@ -640,7 +639,7 @@ static void start_element(void* user, const xmlChar* tag, const xmlChar** attrs)
state->stack.back().inv_attr()->attribute_reference()); state->stack.back().inv_attr()->attribute_reference());
IfcWrite::IfcWriteArgument* attr_inv = new IfcWrite::IfcWriteArgument(); IfcWrite::IfcWriteArgument* attr_inv = new IfcWrite::IfcWriteArgument();
attr_inv->set(state->stack.back().inst()); attr_inv->set(state->stack.back().inst());
if (inst) { if (inst != nullptr) {
inst->data().setArgument(idx, attr_inv); inst->data().setArgument(idx, attr_inv);
} else { } else {
Logger::Error("Internal error, inverse attribute not processed"); Logger::Error("Internal error, inverse attribute not processed");
@@ -689,7 +688,7 @@ IFC_PARSE_API IfcParse::IfcFile* IfcParse::parse_ifcxml(const std::string& filen
} }
} }
if (state.file) { if (state.file != nullptr) {
state.file->parsing_complete() = true; state.file->parsing_complete() = true;
state.file->build_inverses(); state.file->build_inverses();
} }