Conversation
src/ifcparse/express.cpp
Outdated
|
|
||
| uint32_t express::Base::id() const { return data()->id(); } | ||
|
|
||
| const InstanceData* express::Base::data() const { |
There was a problem hiding this comment.
This method, as well as the non-const version, defeats using smart pointers. Once the raw pointer is returned it is no longer managed and could be deleted by the caller. Why not
auto sp = data_.lock();
if (sp) {
return sp;
} else {
throw std::runtime_error("Trying to access deleted instance reference")
}
There was a problem hiding this comment.
That's true, but I have the feeling that maybe this should be marked private instead and then it doesn't really matter anymore.
|
Does the weak_ptr encapsulated in the express::Base retain file scope lifetime of objects? It seems like shared_ptr would be required. Though, I don't have a complete understanding. Creating entities as part of the file without constructors has a trade-off. Instead of create() + add() a user of the SDK must do create() + multiple parameter initialization steps by calling set() methods. This isn't bad, but it has these consequences:
I very much like eliminating the custom classes for aggregates. I found them difficult to use. It was difficult to know which one of the classes where needed in different situations. Their interface wasn't the same as std collections, so looping wasn't as easy and they couldn't be used in the std algorithms. This is going to break a lot of my code, but the fixes appear to be easy to deal with. @aothms Let's set up a time for you to walk me through the bigger picture. I'm sure there are lots of details that I'm missing. |
src/examples/IfcAlignment.cpp
Outdated
|
|
||
| // Disable warnings coming from IfcOpenShell | ||
| #pragma warning(disable : 4018 4267 4250 4984 4985) | ||
| /******************************************************************************** |
There was a problem hiding this comment.
It looks like a different example has been applied over the IfcAlignment.cpp example. The revised file is significantly different. Is this intentional?
There was a problem hiding this comment.
Sorry that was sloppy, it's back and updated for the code changes
Yes the file have the shared_ptr not so much for sharing ownership but just so that we have the option to have a weak_ptr derived from them. So that when you have instances pointing to a deleted file or to instances from the file that have been deleted.
Yes that's very valid. The discovery is indeed not really there. I'm also fine with forwarding the arguments from file.create and reinstate the constructor. But as I said since the arguments are not named I find them a bit unclear especially with all the std::nullopts for all the optional arguments, it's hard to interpret. Boost has this named parameters idea, but I think it's a bit lengthy to setup https://www.boost.org/doc/libs/latest/libs/graph/doc/bgl_named_params.html
I think that's indeed also a nice compromise. Then we also have autocompletion in our IDE because I think with std::forward from file.create() I think IDE's will be pretty clueless. Very flexible to have a call these days, let me know some times that suit you please. |
|
I emailed your personal account with some proposed times for next week |
|
@RickBrice The initialize() method is there. There are now three options: // 1.
auto rel = file.create<IfcSchema::IfcRelVoidsElement>();
rel.setGlobalId(guid());
rel.setOwnerHistory(file.getSingle<IfcSchema::IfcOwnerHistory>());
rel.setRelatingObject(roof);
rel.setRelatedObjects({south_roof_part, north_roof_part});
// 2.
file.create<IfcSchema::IfcRelAggregates>(
guid(),
file.getSingle<IfcSchema::IfcOwnerHistory>(),
std::nullopt,
std::nullopt,
roof,
std::vector<::Ifc2x3::IfcObjectDefinition>{south_roof_part, north_roof_part}
);
// 3.
file.create<IfcSchema::IfcRelAggregates>().initialize(
guid(),
file.getSingle<IfcSchema::IfcOwnerHistory>(),
std::nullopt,
std::nullopt,
roof,
{south_roof_part, north_roof_part});For option 2 I couldn't get the untyped initializer list to work. I'm not so familiar with them. Maybe maybe if we have initialize() @Andrej730 @Moult I think it's also a good time for the both of you to have a look. I'm getting to a point that the tests are almost passing. I still need to do quite a bit of cleaning up. I think quite some docstrings and annotations disappeared in the process of moving some things to the SWIG generated classes, I will try and get them back. Things feel quite a bit snappier without the |
src/ifcparse/IfcUtil.cpp
Outdated
| std::distance(declaration().as_entity()->derived().begin(), it), | ||
| Derived{} | ||
| ); | ||
| void InstanceData::populate_derived_() { |
There was a problem hiding this comment.
there is a lot of getting of the begin and end iterator. Probably not a big deal for any one entity, but over thousands of entities in a model, would it be more efficient to do something like this?
if (auto* ent = declaration_->as_entity()) {
auto begin = ent->derived().begin();
auto end = ent->derived().end();
for ( auto it = begin; it != end; ++it) {
if (*it) {
set_attribute_value(
std::distance(begin,it),Derived{}):
}
}
There was a problem hiding this comment.
I can't imagine this would matter with compiler optimizations, but would be good to check the disassembly.
|
I'm not as knowledgeable on C++ as you, but from a little googling, there does seem to be an untyped initializer list in c++. The closest thing I could find is This does not seem like a workable solution. Returning |
|
Another thing comes to mind, but not related to initialization. Not sure how to say it generically, so I'll do it with an example. To add a Related Object to IfcRelAggregates after it is constructed you need to do the following Consider the following Before: After: The same concept could be applied to all of the different Rel types, and other things with lists like IfcSectionedSolidHorizontal.CrossSections |
|
I hope I understand what's happening here, to me it means:
|
|
@aothms what is the current state of this? |
|
Regarding this comment below. Yes, this is something that has always been incredibly wasteful. Also on the python side. And quite problematic because there are a lot of 1-to-many objectified relationships where the many are sometimes really many many. Like the ContainedInStructure relationship in your typical building. Beyond building storey there is typically very little decomposition so in a typical bad case you can literally have a million nodes into a single aggregate attribute, where this copying really starts to exhibit some nasty non-linear behaviour if you're incrementally adding things to it. Since this is also on the python-side. I'd prefer to solve this in the attribute value and not in the schema (python doesn't have acces to the schema). That means re-introducing some custom vector-alternative that has more context (needs to know entity instance and attribute index essentially) so that it can update the inverse relationships also when doing a push_back (or an erase). Previously this was hardly possible at all, because the vectors returned from the attribute storage where constructed on the fly. Now there is at least a vector type in our storage variant. Maybe this also means we can stop with casting-by-copying of the vector types, because this is also really silly. We store them as untyped vector and then create a copy of vector with element type of a specific subtype and do some static or dynamic cast on the elements. But we can also do this lazily with a custom iterator. Becomes even more complex when we have to consider I certainly think this is something worth exploring.
|
You decide:
|
I liked the idea of using STL without something special. I didn't think about dealing with inverses. The fundamental question is then, how much of an actual problem is this? Is it worth the effort to solve it?
It seems like we both have other things going on that are higher priority. We can forget about it for now. While there will be pain on the C++ side, it doesn't appear to be unbearable. |
Yes me too, but on the other hand STL is designed to work with custom containers because everything accepts iterators. I think people in a well-designed library would expect to be able to do
I think if we have |
|
Converted to a draft, as it currently conflicts with see https://github.com/falken10vdl/bonsaiPR/releases/tag/v0.8.5-alpha2603141648 please note the Conflict Report:
|
…ring pool (b) SWAR process multiple chars at once in keywords/enums/strs/stc.
|
I managed to get this to compile and import in Python locally mostly by letting AI work it out without any real understanding. Not sure if it's useful or not, but I've attached the findings. |
|
I experienced segfaults when doing ifcopenshell.open() (after all those compilation fixes in the previous comment) on the ISSUE_159_kleine_Wohnung_R22.ifc model (from the list of profiling models). Here's an updated AI generated findings.md with an explanation of that fix, and a patch showing all the changes so far. I'm also getting iterator initialisation errors on the advanced_model.ifc model saying "Trying to access deleted instance reference" (with detailed logging turned on). Haven't yet found a solution to that yet though. Other than that, with those patches I can compile, and the profiling code is able to basically recreate the same numbers (apart from that initialisation error on that model) as the main branch. |
|
Hm yes apparently openai codex only bothered to verify compilation on windows. These template/typename things are notoriously different between compiler implementations. |
|
Woke up this morning and the "Trying to access deleted instance reference" was solved by AI with this explanation: |
|
Thanks! that fix we probably cannot use, because that means that every deleted instance equals every other deleted instance. We want this generally to bubble up as an exception (I think). But the root cause is super useful we just need to catch this a bit earlier, because apparently this is not a very common issue so I don't think it warrants a fix so high up in the abstraction level. I have a bit of a backlog of other work because I missed a good couple of days due to back issues, but I'll get to this later this week. If you want to have it chew at some other tasks in the meantime, essentially:
|
For the past couple of days I have been rethinking what a sane v1.0 data model on the C++ side would look like that balances safety, readability, performance and a bit more modern language features. I still have work todo but wanted to share a bit of what's going on.
This has huge implications on client C++ code, so to feel the pain I went through most of the code base already. @RickBrice as one of the more active C++ devs lately I'm curious what your thoughts are.
Outcome:
Before:
After:
Rationale
reason for weak_ptr encapsulated in object:
reason for creation as part of file
reasons for no constructor:
no custom class anymore for aggregates (aggregate_of_instance)