From 96ce5f6b25e0f1836cf4285394d4ab7e5071e1ef Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 4 Nov 2014 12:02:28 +0000 Subject: [PATCH] Don't compare smart pointers to zero, but convert to bool --- src/ifcparse/IfcParse.cpp | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index f3b2352b1e..bd90b09827 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -807,40 +807,45 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* f) { Logger::Message(Logger::LOG_ERROR,ex.what()); } } + IfcSchema::Type::Enum ty = entity->type(); do { - IfcEntityList::ptr L = EntitiesByType(ty); - if ( L == 0 ) { - L = IfcEntityList::ptr(new IfcEntityList()); - bytype[ty] = L; + IfcEntityList::ptr instances_by_type = EntitiesByType(ty); + if (!instances_by_type) { + instances_by_type = IfcEntityList::ptr(new IfcEntityList()); + bytype[ty] = instances_by_type; } - L->push(entity); + instances_by_type->push(entity); ty = IfcSchema::Type::Parent(ty); } while ( ty > -1 ); + if ( byid.find(currentId) != byid.end() ) { std::stringstream ss; ss << "Overwriting entity with id " << currentId; Logger::Message(Logger::LOG_WARNING,ss.str()); } byid[currentId] = entity; + MaxId = (std::max)(MaxId,currentId); currentId = 0; } else { try { token = tokens->Next(); } catch (... ) { token = TokenPtr(); } } + if ( ! (token.second || token.first) ) break; + if ( (previous.second || previous.first) && TokenFunc::isIdentifier(previous) ) { int id = TokenFunc::asInt(previous); if ( TokenFunc::isOperator(token,'=') ) { currentId = id; } else if (entity) { - IfcEntityList::ptr L = EntitiesByReference(id); - if ( L == 0 ) { - L = IfcEntityList::ptr(new IfcEntityList()); - byref[id] = L; + IfcEntityList::ptr instances_by_ref = EntitiesByReference(id); + if (!instances_by_ref) { + instances_by_ref = IfcEntityList::ptr(new IfcEntityList()); + byref[id] = instances_by_ref; } - L->push(entity); + instances_by_ref->push(entity); } } previous = token; @@ -868,16 +873,18 @@ void IfcFile::AddEntity(IfcUtil::IfcBaseClass* entity) { Logger::Message(Logger::LOG_ERROR,ex.what()); } } + IfcSchema::Type::Enum ty = entity->type(); do { - IfcEntityList::ptr L = EntitiesByType(ty); - if ( L == 0 ) { - L = IfcEntityList::ptr(new IfcEntityList()); - bytype[ty] = L; + IfcEntityList::ptr instances_by_type = EntitiesByType(ty); + if (!instances_by_type) { + instances_by_type = IfcEntityList::ptr(new IfcEntityList()); + bytype[ty] = instances_by_type; } - L->push(entity); + instances_by_type->push(entity); ty = IfcSchema::Type::Parent(ty); } while ( ty > -1 ); + int new_id = -1; // For newly created entities ensure a valid ENTITY_INSTANCE_NAME is set if ( entity->entity->isWritable() ) {