mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[wpilibc] Const-qualify SendableChooser::GetSelected() (#6356)
This commit is contained in:
@@ -40,6 +40,8 @@ class SendableChooser : public SendableChooserBase {
|
||||
static std::weak_ptr<U> _unwrap_smart_ptr(const std::shared_ptr<U>& value);
|
||||
|
||||
public:
|
||||
using CopyType = decltype(_unwrap_smart_ptr(m_choices.lookup("")));
|
||||
|
||||
SendableChooser() = default;
|
||||
~SendableChooser() override = default;
|
||||
SendableChooser(SendableChooser&& rhs) = default;
|
||||
@@ -78,7 +80,7 @@ class SendableChooser : public SendableChooserBase {
|
||||
*
|
||||
* @return The option selected
|
||||
*/
|
||||
auto GetSelected() -> decltype(_unwrap_smart_ptr(m_choices[""]));
|
||||
CopyType GetSelected() const;
|
||||
|
||||
/**
|
||||
* Bind a listener that's called when the selected value changes.
|
||||
|
||||
@@ -33,8 +33,7 @@ void SendableChooser<T>::SetDefaultOption(std::string_view name, T object) {
|
||||
|
||||
template <class T>
|
||||
requires std::copy_constructible<T> && std::default_initializable<T>
|
||||
auto SendableChooser<T>::GetSelected()
|
||||
-> decltype(_unwrap_smart_ptr(m_choices[""])) {
|
||||
typename SendableChooser<T>::CopyType SendableChooser<T>::GetSelected() const {
|
||||
std::string selected = m_defaultChoice;
|
||||
{
|
||||
std::scoped_lock lock(m_mutex);
|
||||
@@ -43,9 +42,9 @@ auto SendableChooser<T>::GetSelected()
|
||||
}
|
||||
}
|
||||
if (selected.empty()) {
|
||||
return decltype(_unwrap_smart_ptr(m_choices[""])){};
|
||||
return CopyType{};
|
||||
} else {
|
||||
return _unwrap_smart_ptr(m_choices[selected]);
|
||||
return _unwrap_smart_ptr(m_choices.lookup(selected));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class SendableChooserBase : public wpi::Sendable,
|
||||
std::string m_defaultChoice;
|
||||
std::string m_selected;
|
||||
bool m_haveSelected = false;
|
||||
wpi::mutex m_mutex;
|
||||
mutable wpi::mutex m_mutex;
|
||||
int m_instance;
|
||||
std::string m_previousVal;
|
||||
static std::atomic_int s_instances;
|
||||
|
||||
Reference in New Issue
Block a user