Skip to content

Commit 8f853ac

Browse files
committed
Initialize the attributes of IfcLateBoundEntity to NULL upon construction.
Make sure IfcWritableEntity does not return null pointers, since getArgumentCount() is unreliable for instances being created from keyword arguments in Python.
1 parent 6822e84 commit 8f853ac

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/ifcparse/IfcLateBoundEntity.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ IfcParse::IfcLateBoundEntity::IfcLateBoundEntity(const std::string& s) {
4848
for (std::string::iterator i = S.begin(); i != S.end(); ++i ) *i = toupper(*i);
4949
_type = IfcSchema::Type::FromString(S);
5050
entity = new IfcWrite::IfcWritableEntity(_type);
51+
for (unsigned i = 0; i < getArgumentCount(); ++i) {
52+
// Side effect of this is that a NULL attribute is created.
53+
entity->getArgument(i);
54+
}
5155
IfcSchema::Type::PopulateDerivedFields(writable_entity());
5256
}
5357
IfcParse::IfcLateBoundEntity::IfcLateBoundEntity(IfcAbstractEntity* e) {

src/ifcparse/IfcWrite.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ IfcEntityList::ptr IfcWritableEntity::getInverse(IfcSchema::Type::Enum type, int
7171
}
7272

7373
std::string IfcWritableEntity::datatype() const { return IfcSchema::Type::ToString(_type); }
74-
Argument* IfcWritableEntity::getArgument (unsigned int i) { if ( i >= getArgumentCount() ) throw IfcParse::IfcException("Argument not set"); return args[i]; }
74+
Argument* IfcWritableEntity::getArgument (unsigned int i) {
75+
if (args[i] == 0) {
76+
_setArgument(i, boost::none);
77+
}
78+
return args[i];
79+
}
7580
unsigned int IfcWritableEntity::getArgumentCount() const {return args.size(); }
7681
IfcSchema::Type::Enum IfcWritableEntity::type() const { return _type; }
7782
bool IfcWritableEntity::is(IfcSchema::Type::Enum v) const { return _type == v; }

0 commit comments

Comments
 (0)