Introduce jomini::Value for loosely typed data - #184
Open
nickbabcock wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🚧 👷 WIP code and WIP description👷 🚧
This PR introduces
jomini::Value, the analogserde_json::Valuefor jomini.jomini::Valueserves a variety of use cases.untyped data
When reading data where you have no inkling of the structure of a field, and need to dynamically access and manipulate values.
Whereas with a
TextTape, any edits to the underlying tokens (if such an API were to exist) risks corrupting object and array indices,jomini::Valueis structured as a DOM tree, allowing for easier modifications.It is not recommended to reach for
jomini::Valuewhen the structure of values can vary simply, as this use case is often covered by implementingDeserializeover an enum. For instance, the following data would not be a good use forjomini::Valueas it can be represented by:
lossless data
owned data
drawbacks
encoding issues
Performance
Write API
Example
We can write use
jomini::Valueto construct an eager variable interpolation program, which can then be deserialized into strongly typed object.For instance, given:
We deserialize it as:
This is accomplished via the following steps:
jomini::ValueTODO: code to follow