If you case to IfcBaseEntity, you can use the latebound attribute access:
IfcBaseEntity* space;
auto attr = space->get("Name");
if (!attr->isNull()) {
std::string name = *attr;
}
Otherwise you can do some sort of if statement (but it's ugly) either with
dynamic_cast<Ifc2x3::IfcSpace> or dynamic_cast<Ifc4::IfcSpace>
Or with space->declaration().schema() (I think)
We could also think of some sort of visitor:
template <typename Schema>
std::string get_name(typename Schema::IfcSpace*) {
...
}
template <typename Fn>
std::string apply_visitor(IfcBaseEntity* x, Fn fn) {
if (dynamic_cast<Ifc2x3::IfcSpace>(x)) {
fn(dynamic_cast<Ifc2x3::IfcSpace>(x))
} else (dynamic_cast<Ifc4::IfcSpace>(x)) { ...
}
IfcBaseEntity* space;
apply_visitor(space, get_name);
But in that last approach it would be nice to be able to reuse it to other classes not only IfcSpace but I haven't found a way yet to do that.;
Maybe the only way is to create some sort of meta schema that unifies all IFC schemas so that you have a
meta::IfcSpace that is maybe a boost::mpl::list of (Ifc2x3::IfcSpace, Ifc4::IfcSpace, ...) so that you do a compile time iteration.
https://sourceforge.net/p/ifcopenshell/discussion/1782717/thread/cc4c489825/?limit=25
See also http://blog.ifcopenshell.org/2019/12/v060.html
If you case to IfcBaseEntity, you can use the latebound attribute access:
Otherwise you can do some sort of if statement (but it's ugly) either with
dynamic_cast<Ifc2x3::IfcSpace>ordynamic_cast<Ifc4::IfcSpace>Or with
space->declaration().schema()(I think)We could also think of some sort of visitor:
But in that last approach it would be nice to be able to reuse it to other classes not only IfcSpace but I haven't found a way yet to do that.;
Maybe the only way is to create some sort of meta schema that unifies all IFC schemas so that you have a
meta::IfcSpacethat is maybe aboost::mpl::listof (Ifc2x3::IfcSpace,Ifc4::IfcSpace, ...) so that you do a compile time iteration.https://sourceforge.net/p/ifcopenshell/discussion/1782717/thread/cc4c489825/?limit=25
See also http://blog.ifcopenshell.org/2019/12/v060.html