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

Replace usage of JsonArray::has_more with range-based loops. #36227

Merged
merged 21 commits into from
Dec 19, 2019

Conversation

BevapDin
Copy link
Contributor

SUMMARY: None

Fixes a bug as well.

Changes a few functions to take a const JsonValue & instead of a JsonIn stream.

@I-am-Erk I-am-Erk added <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` labels Dec 18, 2019
The current code would just skip the array entry if it was neither a string nor an object. There is no indication to the modder that their data has been ignored.

The new code will trigger an error instead. The modder will know about the invalid format.
The code would always use the first entry of the parent array (`trait`) instead of the that of the subarray. It would however use the *second* value of the subarray and skip the first one. Makes no sense.
There is a check for whether the array has more entries. That one will catch empty array.
It checks the same thing essentially: that there is at least one intensity level defined.
Change `requirement_data::load_obj_list` to take a reference to const JsonArray. This allows to inline the code in the caller (the JsonArray instance does not need to be stored in a variable).
Inside the function, change the loops to range-based loops over the array / the subarray.

In turn, change the various `load` functions to accept `const JsonValue &` (entries of the array). The functions used to get the full array as reference and would extract the next element from it.
This allows to iterate over the array using a range-based lood.
Which can be used just like the stream.

Also added a `JsonObject::get_member` function to get a specific member as `JsonValue`.
…nce.

Which allows to iterate over the array using a range-based loop.
The loop would previously read more data than there was storage reserved for (it could read more than `adv_inv_in_vehicle.size()` elements).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants