-
Notifications
You must be signed in to change notification settings - Fork 612
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 methods to get name of SendableChooser's selected value #7580
base: main
Are you sure you want to change the base?
Conversation
/format |
/format was removed. You'll have to format manually. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! I'm really hopeful that this can make it in before kickoff. Just a few things:
- You can change the first 7 lines of
GetSelected()
(currently 98-104) to juststd::string selected = GetSelectedName();
to match Java. - Java's
testChangeListener()
doesn't have the changes done to C++'sChangeListener
test.
It seems an unrelated test has failed in ubsan:
|
wpilibc/src/main/native/include/frc/smartdashboard/SendableChooser.h
Outdated
Show resolved
Hide resolved
Co-authored-by: Joseph Eng <[email protected]>
* | ||
* @return The name of the option selected | ||
*/ | ||
std::string_view GetSelectedName() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string_view GetSelectedName() const { | |
std::string GetSelectedName() const { |
It's not safe to return a string_view here. It needs to return a copy (a std::string) because the access is mutex-protected, so (theoretically) another thread could come in and modify m_selected before the string_view is accessed.
selected = m_selected; | ||
} | ||
} | ||
std::string_view selected = GetSelectedName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string_view selected = GetSelectedName(); | |
std::string selected = GetSelectedName(); |
In some cases, such as logging, it can be useful to get the name of a SendableChooser's currently selected option. This adds:
getSelectedName()
/GetSelectedName()
, to get the name of the currently selected optiononChange(BiConsumer<String, V>)
/OnChange(std::function<void(std::string_view, T)> listener)
to get the name when the currently selected option changes. The original onChange methods are kept for backward compatibility.