Replies: 5 comments 8 replies
-
It would be nice to be able to move this stuff into cpp files. I think we have enough control of the parsing process that we could get additional (compile-time) information into the factory parsing function, so it's not out of the question to pass the list outside of the class itself. Passing a list of derived classes isn't sufficient, as we can parse more than one base class at a time (e.g., |
Beta Was this translation helpful? Give feedback.
-
We would also need to handle registering classes with charm somehow. |
Beta Was this translation helpful? Give feedback.
-
The best idea I've had is to put a map The problem with this is that we only get a single global list for each base class, and we want different lists for different purposes. For example, under LTS, classes derived from |
Beta Was this translation helpful? Give feedback.
-
BTW here's another artifact of the current design that could be mitigated by moving the |
Beta Was this translation helpful? Give feedback.
-
So, here's a possible plan, based on the above discussion:
|
Beta Was this translation helpful? Give feedback.
-
@wthrowe Do you think it’s conceptionally possible to do factory-creation from a base class without templating the derived classes on registrars? I’m asking because the Registrars template parameter makes it quite a bit more difficult to move code into cpp files. I’m working around that in current code (see e.g. https://github.com/sxs-collaboration/spectre/blob/develop/src/Elliptic/Systems/Elasticity/BoundaryConditions/LaserBeam.hpp), but perhaps there’s a better way. Here's a sketch of the current pattern:
This is fairly complicated and could be a bit of an obstacle for new people learning the code, since it's actually reasonably likely that some of the first code that new people come in contact with follow some variation of this pattern (e.g. analytic solutions / data, boundary conditions, events and triggers, equations of state).
Now typically the derived classes don’t actually need to know anything about their siblings, and the need for the
Registrars
template parameter only comes in because the base class has to provide the list ofcreatable_classes
to the options code. So perhaps we could decouple this and, for example, have the option tag provide thecreatable_classes
instead. This would mean the base class and the derived classes don't need to keep track of registrars. I'm thinking something like this:Now of course the code that works with the factory-created object has to deal with the fact that the
Base
doesn't know its derived classes anymore, so in case it wants to use the "FakeVirtual" mechanism it has to keep track of the list of derived classes itself. I feel like this could be a worthy tradeoff. What do you think, could something like this work?Beta Was this translation helpful? Give feedback.
All reactions