CleverRaven/Cataclysm-DDA — pull request #3379 by yobbobanana (2013-10-01 02:32:41+00:00)
Title: [WIP] [CR] New JsonOut class for JSON serialization.

Implementation in json.cpp.

Usage in savegame_json.cpp.

Functions added to savegame_json.cpp are all near-duplicates of the ones using picojson.

For an example of the difference, check out player::json_save() in savegame_json.cpp, as it was completely converted over. Everything else was duplicated so as not to interfere with NPC saving, which has not been modified.

I'm posting this to get comments on the style of the new output class.

Output control is mostly manual, giving the user full control over what gets output when, where and how. It just handles all the details of outputting correct JSON.

One aspect that could change is the explicit method naming scheme: `write_int`, `write_string_member`, etc. Technically they could all just be `write`, as the function signatures are unique (except for `write_member_name`). It's easier to catch errors if the names are explicit, but dropping the type names would make it a lot more concise.

Array and object construction is manual, using `start_array()`, `end_array()`, etc., although vectors of integers or strings can be fed to `write_array()` for convenience.

Separators are inserted automagically.

No pretty-printing yet. It's all single-line no-whitespace, as that's what the current save system uses.

Seems to be 100% compatible with current save system, although object members are in a different order (picojson likes to alphabetize).

Comments are welcome.