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

add ConfigObject::get-/setValue<EnumType> #11883

Merged
merged 8 commits into from Aug 31, 2023

Conversation

Swiftb0y
Copy link
Member

This allows the callsites to avoid verbose static_casts (see 491b436). It also makes it easier to change the machanism used when storing enums in the config easier in the future. The remaining commits are cleanups I did along the way while making use of the new overload.

Comment on lines 178 to 182
template <class ResultType>
ResultType getValue(const ConfigKey& key, const ResultType& default_value) const;
QString getValue(const ConfigKey& key, const char* default_value) const;
template<typename EnumType>
requires std::is_enum_v<EnumType>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
template <class ResultType>
ResultType getValue(const ConfigKey& key, const ResultType& default_value) const;
QString getValue(const ConfigKey& key, const char* default_value) const;
template<typename EnumType>
requires std::is_enum_v<EnumType>
template <class ResultType, std::enable_if_t<!std::is_enum_v<ResultType>, bool> = true>
ResultType getValue(const ConfigKey& key, const ResultType& default_value) const;
QString getValue(const ConfigKey& key, const char* default_value) const;
template<typename EnumType, std::enable_if_t<std::is_enum_v<EnumType>, bool> = true>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicitly opting out of enums for the default template is unnecessary when using requires as the template with requires has a higher specificity and is thus chosen over the unconstrained template. I'd prefer to not have the negative requirement, as the maintenance burden will explode in case we add even more templates.

Comment on lines 157 to 160
template <class ResultType>
void setValue(const ConfigKey& key, const ResultType& value);
template<class EnumType>
requires std::is_enum_v<EnumType>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to use std::enable_if if you want to merge this into 2.4 because requires does not work with Ubuntu Focal
The alternative would be to merge that to main, because this is not a last minute bug fix.
But I consider that a low risk PR that we can let slip in.

Suggested change
template <class ResultType>
void setValue(const ConfigKey& key, const ResultType& value);
template<class EnumType>
requires std::is_enum_v<EnumType>
template <class ResultType, std::enable_if_t<!std::is_enum_v<ResultType>, bool> = true>
void setValue(const ConfigKey& key, const ResultType& value);
template<class EnumType, std::enable_if_t<std::is_enum_v<EnumType>, bool> = true>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative would be to merge that to main, because this is not a last minute bug fix.

I'd prefer merging to main then. The error messages generated when using enable_if are much uglier than the ones generated by requires clauses.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

src/mixxxmainwindow.cpp Outdated Show resolved Hide resolved
src/preferences/dialog/dlgprefautodj.cpp Outdated Show resolved Hide resolved
src/preferences/dialog/dlgprefautodj.cpp Outdated Show resolved Hide resolved
src/preferences/dialog/dlgprefautodj.cpp Show resolved Hide resolved
src/preferences/dialog/dlgprefautodj.cpp Outdated Show resolved Hide resolved
src/preferences/dialog/dlgprefautodj.cpp Outdated Show resolved Hide resolved
@Swiftb0y
Copy link
Member Author

I'll push a couple fixups. If you're okay with them I'll squash them and rebase onto main in a single step after approval. Reverting to draft as long as the history contains fixups.

@Swiftb0y Swiftb0y marked this pull request as draft August 29, 2023 07:21
Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Ready to rebase.

@Swiftb0y Swiftb0y changed the base branch from 2.4 to main August 29, 2023 15:21
@Swiftb0y Swiftb0y marked this pull request as ready for review August 29, 2023 15:22
@Swiftb0y
Copy link
Member Author

rebased to main, fixups are gone and it builds. merge?

@@ -91,7 +91,7 @@ repos:
- manual
language: python
additional_dependencies:
- clang-format==14.0.6
- clang-format==16.0.6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this from the pre-commit PR? Did you pull 2.4 into main?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it was required to resolve the messed formatting I posted about above. I didn't pull 2.4 into main because thats currently broken IIUC. I just figured I'd just update it here and the merge conflict will be easy to resolve later. The Alternative would be to cherry-pick #11889 into main.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, my local test worked fine, but if we changed deps this does look weird. Since #11839 has already been merged I'd rather take care of updating the vcpkg env now rather than risking that changes in 2.4 pile up and become a pain to resolve later on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I just don't like messing with the buildenv as that's not my area of expertise. Thank you for taking care.

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, we see now everything is green. So I suggest to remove the .pre-commit-config.yaml and we can merge this with the failing pre-commit (if #11892 does not make it before). This will avoid later conflicts and doe snot block this PR.

@Swiftb0y
Copy link
Member Author

removed the pre-commit change. CI is obviously still failing due it being broken on main.

@Swiftb0y
Copy link
Member Author

merge?

@daschuer
Copy link
Member

Yes, thank you.

@daschuer daschuer merged commit 18d695d into mixxxdj:main Aug 31, 2023
13 checks passed
@Swiftb0y
Copy link
Member Author

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants