Page MenuHomeWildfire Games

Make IGUIObject settings a template class

Authored by elexis on Aug 4 2019, 3:33 AM.



This transforms IGUIObject settings to a template class and IGUIObject::AddSetting to a template function.

This means the type information is available for all methods operating with the setting type, which is easier for the authors, allows for compile-time checks and optimizations.
Remove the enum that was used to indirectly obtain the setting type at runtime.
Revised SGUISetting and enum from rP290 (rP74), std::function from rP22574.

Move this to GUIUtil.cpp in anticipation of merging the other functions and since its a complex class that should be in a separate file concering only settings.

rP22596 removed one fringe use case of the enum.

Test Plan

Fight the compilers. Adore the vanished ugliness. Make sure the delete is in place and no leak snuck in.
Ways to reduce the number of GUItypes.h inclusions are to be considered, but will probably be easier to manage in an independent patch.

Brief mentioning on #0ad-dev on

21:48 < elexis> Vladislav: also would you agree that AddSetting<CStrW>("sound_released"); is better than AddSetting(GUIST_CStrW, "sound_released");?
21:49 < Vladislav> elexis: yes, the template one looks more strict.

I've compiled with gcc 9, clang 8.0.1, VS2015, Jenkins.

Diff Detail

rP 0 A.D. Public Repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

elexis created this revision.Aug 4 2019, 3:33 AM
Vulcan added a comment.Aug 4 2019, 3:45 AM

Successful build - Chance fights ever on the side of the prudent.

Linter detected issues:
Executing section Source...

| 169| »   ·*·example·a·CRect(10,10,20,20)·would·be·"10·10·20·20"
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'classCClientArea{' is invalid C code. Use --std or --language to configure the language.

|  45| template<typename·T>·class·GUI;
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'template<...' is invalid C code. Use --std or --language to configure the language.
Executing section JS...
Executing section cli...

Link to build:

elexis edited the test plan for this revision. (Show Details)Aug 4 2019, 4:13 AM
This revision was not accepted when it landed; it landed in state Needs Review.Aug 4 2019, 4:20 AM
This revision was automatically updated to reflect the committed changes.
elexis edited the summary of this revision. (Show Details)Aug 4 2019, 4:24 AM
elexis updated the Trac tickets for this revision.Aug 29 2019, 11:22 AM