Skip to content

Allow to add metadata to json nodes#3028

Closed
barcode wants to merge 2 commits intonlohmann:developfrom
barcode:allow_node_metadata
Closed

Allow to add metadata to json nodes#3028
barcode wants to merge 2 commits intonlohmann:developfrom
barcode:allow_node_metadata

Conversation

@barcode
Copy link
Contributor

@barcode barcode commented Sep 24, 2021

When processing json it is often useful to annotate nodes with some metadata. This PR adds an additional template parameter which allows to set the type of metadata.
By default the parameter is set to void and no metadata is allowed. In this case the library behaves as it already did.
If a user explicitly adds metadata (last template parameter) each node has a data member of this type and access functions for this member.

This metadata can be used to tag nodes or store information such as the line and column number from an input file.


Pull request checklist

Read the Contribution Guidelines for detailed information.

  • Changes are described in the pull request, or an existing issue is referenced.
  • The test suite compiles and runs without error.
  • Code coverage is 100%. Test cases can be added by editing the test suite. (should be. will update state aver coverall is done)
  • The source code is amalgamated; that is, after making changes to the sources in the include/nlohmann directory, run make amalgamate to create the single-header file single_include/nlohmann/json.hpp. The whole process is described here.

* by default no metadata is allowed and the library behaves as it already did
* if a user explicitly adds metadata (last template parameter) each node has a data member of this type and access functions for this member
* add test for this feature
@barcode barcode requested a review from nlohmann as a code owner September 24, 2021 21:43
@coveralls
Copy link

coveralls commented Sep 25, 2021

Coverage Status

Coverage remained the same at 100.0% when pulling a36fb85 on barcode:allow_node_metadata into 0b345b2 on nlohmann:develop.

@barcode
Copy link
Contributor Author

barcode commented Oct 30, 2021

Closed in favour of #3110 which implements the more powerful feature of a custom base class and thus allows adding custom member functions as well.

@barcode barcode closed this Oct 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants