mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-14 16:07:09 +00:00
![]() Previously the config class had an operator bool and it was a common pattern to use if(const config& = cfg.child(..)). While this pattern was nice to use. It has severe drawbacks, in particular it was unclear whether a function that took a config& parameter allowed "invalid" configs, while most functions did not, there were some that did. Furtheremore it lead to a few buggy codes that were unconvered by this change (Not fixed though!), in particular codes that tested local config objects that were not references to being invalid, which could never be the case. This commits replaces those with just `true` in order to not change behaviour. Some obvious cases were also removed including for example things like `assert(config());` There is ony case in the ai code that i'm not 100% sure of where one implementation of a virtual function checked for an invalid config and another one that didn't. With this, all code that check for a config child to be present now uses config::optional_child which returns an object that behaves similar to optional<(const) config&>, so it throws on invalid dereferencing. But it also has operator[string] for convinience, in particular to make is similary easy to use the the previous `if (config& = .. child())`. Also it has a tool DEBUG_CONFIG which tests whether all optional_config values are checked before they are derefereneced. Another method manditory_child was added that throws when the key is not found, which replaces all occurances of child() that did not check whether the result was valid. This was neccecary (this= adding a new method instead of renaming .child) to keep track of converted changes, and be sure no occurances of child() were accidentally changed to the throwing version. We might want to rename one of mandatory_child or optional_child to just child later. Not sure which one yet. I think it's better to keep it in the current state (no config::child() ) for a while though, so that people that currently used child() in their open prs or other work get an error and not wrongly rely on the previous behviour of config::child. The interface of vconfig was not changed in this commit. |
||
---|---|---|
.. | ||
gui2 | ||
umcd | ||
CMakeLists.txt | ||
gui2.sty | ||
gui2.tex | ||
umcd.tex |