Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Support serialization through (smart) pointers to abstract classes #13153

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

avdg81
Copy link
Contributor

@avdg81 avdg81 commented Feb 20, 2025

📝 Description
This PR adds a few compile-time checks that avoid attempting to instantiate abstract base classes while loading objects from a serializer. So far, it was not possible to use (smart) pointers to abstract base classes when serializing objects of derived classes. By adding a few compile-time checks, we now can supply (smart) pointers to abstract base classes to the existing (de)serialization code.

For each modified load function, a corresponding unit test has been created.

To keep the scope of changes to the registry as local as possible during a test run, a test class is registered and deregistered as needed using the RAII idiom. To this end, class Serializer has been extended with a member function to deregister data types.

When loading a serialized smart pointer (or an owning raw pointer), don't attempt to instantiate the corresponding data type when it is abstract. This is useful when passing a (smart) pointer to an interface class, which was not supported so far. Note that without the added check, a compile-time error would be raised when passing a (smart) pointer to an abstract class.

Other changes include:
- Added a member function to class `Serializer` to deregister data types for (de)serialization.
- Added four unit tests that verify whether an instance can be saved and loaded through a (smart) pointer to an interface class.
Copy link
Contributor

@rfaasse rfaasse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition to get the serialization of abstract classes to work! Apart from the mysterious build issues, I don't have any blocking comments or questions (since we also discussed it quite a bit already).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[GeoMechanicsApplication] Fix serialization of the stress state policies
2 participants