Don't compare smart pointers to zero, but convert to bool

This commit is contained in:
Thomas Krijnen
2014-11-04 12:02:28 +00:00
parent 33625c6422
commit d28871e7fc
+22 -15
View File
@@ -734,40 +734,45 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* f) {
Logger::Message(Logger::LOG_ERROR,ex.what()); Logger::Message(Logger::LOG_ERROR,ex.what());
} }
} }
Ifc2x3::Type::Enum ty = entity->type(); Ifc2x3::Type::Enum ty = entity->type();
do { do {
IfcEntities L = EntitiesByType(ty); IfcEntities instances_by_type = EntitiesByType(ty);
if ( L == 0 ) { if (!instances_by_type) {
L = IfcEntities(new IfcEntityList()); instances_by_type = IfcEntities(new IfcEntityList());
bytype[ty] = L; bytype[ty] = instances_by_type;
} }
L->push(entity); instances_by_type->push(entity);
ty = Ifc2x3::Type::Parent(ty); ty = Ifc2x3::Type::Parent(ty);
} while ( ty > -1 ); } while ( ty > -1 );
if ( byid.find(currentId) != byid.end() ) { if ( byid.find(currentId) != byid.end() ) {
std::stringstream ss; std::stringstream ss;
ss << "Overwriting entity with id " << currentId; ss << "Overwriting entity with id " << currentId;
Logger::Message(Logger::LOG_WARNING,ss.str()); Logger::Message(Logger::LOG_WARNING,ss.str());
} }
byid[currentId] = entity; byid[currentId] = entity;
MaxId = (std::max)(MaxId,currentId); MaxId = (std::max)(MaxId,currentId);
currentId = 0; currentId = 0;
} else { } else {
try { token = tokens->Next(); } try { token = tokens->Next(); }
catch (... ) { token = TokenPtr(); } catch (... ) { token = TokenPtr(); }
} }
if ( ! (token.second || token.first) ) break; if ( ! (token.second || token.first) ) break;
if ( (previous.second || previous.first) && TokenFunc::isIdentifier(previous) ) { if ( (previous.second || previous.first) && TokenFunc::isIdentifier(previous) ) {
int id = TokenFunc::asInt(previous); int id = TokenFunc::asInt(previous);
if ( TokenFunc::isOperator(token,'=') ) { if ( TokenFunc::isOperator(token,'=') ) {
currentId = id; currentId = id;
} else if (entity) { } else if (entity) {
IfcEntities L = EntitiesByReference(id); IfcEntities instances_by_ref = EntitiesByReference(id);
if ( L == 0 ) { if (!instances_by_ref) {
L = IfcEntities(new IfcEntityList()); instances_by_ref = IfcEntities(new IfcEntityList());
byref[id] = L; byref[id] = instances_by_ref;
} }
L->push(entity); instances_by_ref->push(entity);
} }
} }
previous = token; previous = token;
@@ -795,16 +800,18 @@ void IfcFile::AddEntity(IfcUtil::IfcSchemaEntity entity) {
Logger::Message(Logger::LOG_ERROR,ex.what()); Logger::Message(Logger::LOG_ERROR,ex.what());
} }
} }
Ifc2x3::Type::Enum ty = entity->type(); Ifc2x3::Type::Enum ty = entity->type();
do { do {
IfcEntities L = EntitiesByType(ty); IfcEntities instances_by_type = EntitiesByType(ty);
if ( L == 0 ) { if (!instances_by_type) {
L = IfcEntities(new IfcEntityList()); instances_by_type = IfcEntities(new IfcEntityList());
bytype[ty] = L; bytype[ty] = instances_by_type;
} }
L->push(entity); instances_by_type->push(entity);
ty = Ifc2x3::Type::Parent(ty); ty = Ifc2x3::Type::Parent(ty);
} while ( ty > -1 ); } while ( ty > -1 );
int new_id = -1; int new_id = -1;
// For newly created entities ensure a valid ENTITY_INSTANCE_NAME is set // For newly created entities ensure a valid ENTITY_INSTANCE_NAME is set
if ( entity->entity->isWritable() ) { if ( entity->entity->isWritable() ) {