Refactor Structure serialization to use Dictionary #993
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.
Refactor some of the
Structure
serialization code to useNAS2D::Dictionary
.I think this gives enough of a structure that people can start to convert serialization code to use
NAS2D::Dictionary
, and minimize direct reliance on XML code.Reference: #830
I'm sure there's more to do with
Structure
serialization. In particular, the various sub-classes can override thegetDataDict()
method to add in their structure specific fields. That would allow much of the custom processing in the higher levelserializeStructure
function to be eliminated. TheFactory
class has been handled as an example.Not addressed are the use of sub-elements to store additional structure data. For example, the
<food level="0" />
sub-element was not changed at all. TheDictionary
object doesn't really provide a multi-level structure to the data, so that concept doesn't map well toDictionary
. If there is a fixed maximum nesting, such as at most 2 levels, we could instead use astd::map
ofDictionary
or similar. Though I suspect some of the current nesting can be removed, making the point perhaps a bit irrelevant.In terms of reducing the nesting level, some sub-element values can be moved to regular attributes, such as
food="0"
. Currently there is some inconsistency in the code as to what format to use. Some sub-classes attach additional attributes to theXmlElement
, others add childXmlElement
objects for the data. I suggest we try to improve consistency by using attributes on the mainstructure
tag whenever possible.Example (existing format):
Suggested: