Codechange: use C++ containers for parsing the settings int lists #12436
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.
Motivation / Problem
In #12432 I used a hacky method to get rid of a bad
lengthof
and added a to-do. Now it's time to get rid of that to-do.Description
In the past you passed
ParseIntList
a pointer and a number of elements. This works fine for C-style arrays orstd::array
, but it's cumbersome withstd::vector
as you need to preallocate memory in the hope that it's right.Furthermore some other magic was performed to clamp values to be within a specific range. This could have unexpected side effects, for example
2**32-1
would not be within the bounds ofsigned long
and clamped to2**31-1
before later being converted back to an uint32.Now
ParseIntList
returns an optional vector with uint32s. Each of the current user is either uint32 (NewGRF parameters, base graphics parameters, resolution) or uint8 (custom music playlist).Also simplify the code a bit by:
memset
directly on the array, instead ofmemset
on a temporary table and then copying values over.WriteValue
instead of our own version.Finally the resolution's configuration suggests it's a signed integer, but it's stored in
Dimension
which usesuint
. So, change the configuration to that as well.Limitations
ParseIntList
does not support allVarType
s, but given its limited use implementing support for that seems pointless. If it's needed at a later point, it shouldn't be too hard to add by going to parse a 64 bit integer. But out of scope for now.I haven't put much thought into the best performance, as this is only used when reading the configuration file, so any gains would be really minimal over maintainability of the code..
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.