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

More easy serialization for STL containers #33742

Merged
merged 5 commits into from
Sep 2, 2019

Conversation

jbytheway
Copy link
Contributor

Summary

SUMMARY: Infrastructure "Improve built-in support for (de)serialization of containers"

Purpose of change

To make implementing (de)serialization code as pain- and bug-free as possible by consolidating container serialization in one place.

Describe the solution

  • Add serialization support for std::pair
  • Support (de)serialization of std::map with enum key types by using write_as_string for the keys (and adding more write_as_string overloads for std::string and string_id to support existing use cases).
  • When deserializing enum values, auto detect whether the json value is a string or integer, and read accordingly.
  • Add a few tests for the json code.

Additional context

I've been adding various new things that need serialization recently, and these issues came up. They will be used by my forthcoming PR implementing a statistics tracker, but they could equally be used by many of the existing game classes that currently have home-brew container serialization code. A use case I saw recently was the artifact effect maps in #33471, which use enum keys.

It will now read enums stored either as strings or ints.  This is useful
because when they are e.g. inside a container it might not be easy to
specify which form they are in.
src/json.h Outdated Show resolved Hide resolved
A cleaner implementations suggested by @BevapDin.
@ZhilkinSerg ZhilkinSerg added [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style labels Sep 2, 2019
@ZhilkinSerg ZhilkinSerg merged commit 33d3060 into CleverRaven:master Sep 2, 2019
@jbytheway jbytheway deleted the more_std_serialization branch September 3, 2019 01:31
@jbytheway jbytheway mentioned this pull request Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants