mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 18:43:26 +00:00
populate_derived() upon instance creation, don't only rely on serialization 'hack' #5364
This commit is contained in:
@@ -210,7 +210,7 @@ entity_implementation = """// Function implementations for %(name)s
|
||||
const IfcParse::entity& %(schema_name)s::%(name)s::declaration() const { return *((IfcParse::entity*)%(schema_name_upper)s_types[%(index_in_schema)d]); }
|
||||
const IfcParse::entity& %(schema_name)s::%(name)s::Class() { return *((IfcParse::entity*)%(schema_name_upper)s_types[%(index_in_schema)d]); }
|
||||
%(schema_name)s::%(name)s::%(name)s(IfcEntityInstanceData&& e) : %(superclass)s { }
|
||||
%(schema_name)s::%(name)s::%(name)s(%(constructor_arguments)s) : %(superclass_num_attrs)s { %(constructor_implementation)s }
|
||||
%(schema_name)s::%(name)s::%(name)s(%(constructor_arguments)s) : %(superclass_num_attrs)s { %(constructor_implementation)s; populate_derived(); }
|
||||
"""
|
||||
|
||||
# data_ = e;
|
||||
|
||||
@@ -139,7 +139,7 @@ class IFC_PARSE_API IfcLateBoundEntity : public IfcBaseClass {
|
||||
|
||||
class IFC_PARSE_API IfcBaseEntity : public IfcBaseClass {
|
||||
public:
|
||||
IfcBaseEntity(IfcEntityInstanceData&& data) : IfcBaseClass(std::move(data)) {}
|
||||
IfcBaseEntity(IfcEntityInstanceData&& data);
|
||||
|
||||
IfcBaseEntity(size_t n)
|
||||
: IfcBaseClass(IfcEntityInstanceData(storage_t(n)))
|
||||
@@ -158,6 +158,8 @@ class IFC_PARSE_API IfcBaseEntity : public IfcBaseClass {
|
||||
boost::shared_ptr<aggregate_of_instance> get_inverse(const std::string& name) const;
|
||||
|
||||
unsigned set_id(const boost::optional<unsigned>& i);
|
||||
|
||||
void populate_derived();
|
||||
};
|
||||
|
||||
// TODO: Investigate whether these should be template classes instead
|
||||
|
||||
@@ -202,11 +202,20 @@ void IfcUtil::unescape_xml(std::string& str) {
|
||||
boost::replace_all(str, ">", ">");
|
||||
}
|
||||
|
||||
/*
|
||||
Argument* IfcUtil::IfcBaseEntity::get(const std::string& name) const {
|
||||
return data().getArgument(declaration().attribute_index(name));
|
||||
IfcUtil::IfcBaseEntity::IfcBaseEntity(IfcEntityInstanceData&& data)
|
||||
: IfcBaseClass(std::move(data))
|
||||
{}
|
||||
|
||||
void IfcUtil::IfcBaseEntity::populate_derived() {
|
||||
for (auto it = declaration().derived().begin(); it != declaration().derived().end(); ++it) {
|
||||
if (*it) {
|
||||
this->data().storage_.set(
|
||||
std::distance(declaration().derived().begin(), it),
|
||||
Derived{}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
AttributeValue IfcUtil::IfcBaseEntity::get(const std::string& name) const
|
||||
{
|
||||
|
||||
@@ -596,7 +596,11 @@ static IfcUtil::ArgumentType helper_fn_attribute_type(const IfcUtil::IfcBaseClas
|
||||
const IfcParse::schema_definition* schema = IfcParse::schema_by_name(schema_identifier);
|
||||
const IfcParse::declaration* decl = schema->declaration_by_name(name);
|
||||
IfcEntityInstanceData data(storage_t(decl->as_entity() ? decl->as_entity()->attribute_count() : 1));
|
||||
return schema->instantiate(decl, std::move(data));
|
||||
auto inst = schema->instantiate(decl, std::move(data));
|
||||
if (auto entinst = inst->as<IfcUtil::IfcBaseEntity>()) {
|
||||
entinst->populate_derived();
|
||||
}
|
||||
return inst;
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user