file: rework saving and loading for correctness and to avoid copying #1538
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rework the object attributes to avoid needlessly iterating over all of them when needing to save a specific object or load a specific attribute of an object.
While at it, add type verification for member serialisation. This caught an issue with the
Group::forceToMeshmember, which was incorrectly serialised as anint, rather than as abool. Thankfully this didn't overwrite the next member because there are padding bytes in between, but we shouldn't continue to rely on this broken behaviour.However, this change unfortunately breaks the tests, since the save logic skips int members which are set to 0, but not boolean members which are set to
false. This now causes theGroup::forceToMeshmember to be emitted into the file where it previously wasn't. If we add the same logic to boolean as well, this would still break the tests because other boolean values were previously serialised. So we need to update the tests either way, but I'm not sure if I should just change the existing files, or back them up with_v31added to their name, like the other ones which have_v20and_v21. @ruevs, @phkahler please advise on the way to do it, and if I should change the boolean serialisation logic to match the one used for ints, and skip members set tofalse.Also change the file saving logic so that it doesn't have to go through the
svmember ofSolveSpaceUI, which needlessly requires copying objects over and over.This leaves
svto be used only as a temporary during file loading, but there's no reason to keep it as a member for this, so it is now made a local variable in the two functions that need it.