36 requires std::copy_constructible<T> && std::default_initializable<T>
39 std::function<void(T)> m_listener;
41 static U _unwrap_smart_ptr(
const U& value) {
46 static std::weak_ptr<U> _unwrap_smart_ptr(
const std::shared_ptr<U>& value) {
51 using CopyType =
decltype(_unwrap_smart_ptr(m_choices.find(
"")->second));
68 m_choices[
name] = std::move(
object);
104 if (selected.empty()) {
107 auto it = m_choices.find(selected);
108 if (it == m_choices.end()) {
111 return _unwrap_smart_ptr(it->second);
122 std::scoped_lock lock(
m_mutex);
123 m_listener = listener;
132 std::vector<std::string> keys;
133 for (
const auto& choice : m_choices) {
134 keys.emplace_back(choice.first);
148 std::scoped_lock lock(
m_mutex);
151 return {buf.data(), buf.size()};
158 [=,
this](std::string_view val) {
160 std::function<void(T)> listener;
162 std::scoped_lock lock(
m_mutex);
166 choice = m_choices[val];
167 listener = m_listener;
@ name
Definition base.h:690
std::string m_selected
Definition SendableChooserBase.hpp:40
wpi::util::mutex m_mutex
Definition SendableChooserBase.hpp:42
static constexpr const char * kDefault
Definition SendableChooserBase.hpp:33
bool m_haveSelected
Definition SendableChooserBase.hpp:41
static constexpr const char * kOptions
Definition SendableChooserBase.hpp:34
std::string m_previousVal
Definition SendableChooserBase.hpp:44
static constexpr const char * kActive
Definition SendableChooserBase.hpp:36
std::string m_defaultChoice
Definition SendableChooserBase.hpp:39
int m_instance
Definition SendableChooserBase.hpp:43
static constexpr const char * kInstance
Definition SendableChooserBase.hpp:37
static constexpr const char * kSelected
Definition SendableChooserBase.hpp:35
void SetDefaultOption(std::string_view name, T object)
Add the given object to the list of options and marks it as the default.
Definition SendableChooser.hpp:80
SendableChooser & operator=(SendableChooser &&rhs)=default
CopyType GetSelected() const
Returns a copy of the selected option (a std::weak_ptr<U> if T = std::shared_ptr<U>).
Definition SendableChooser.hpp:96
SendableChooser(SendableChooser &&rhs)=default
decltype(_unwrap_smart_ptr(m_choices.find("") ->second)) CopyType
Definition SendableChooser.hpp:51
void AddOption(std::string_view name, T object)
Adds the given object to the list of options.
Definition SendableChooser.hpp:67
~SendableChooser() override=default
SendableChooser()=default
void OnChange(std::function< void(T)> listener)
Bind a listener that's called when the selected value changes.
Definition SendableChooser.hpp:121
void InitSendable(wpi::util::SendableBuilder &builder) override
Initializes this Sendable object.
Definition SendableChooser.hpp:126
Helper class for building Sendable dashboard representations.
Definition SendableBuilder.hpp:21
virtual void AddStringProperty(std::string_view key, std::function< std::string()> getter, std::function< void(std::string_view)> setter)=0
Add a string property.
virtual void SetSmartDashboardType(std::string_view type)=0
Set the string representation of the named data type that will be used by the smart dashboard for thi...
virtual void AddStringArrayProperty(std::string_view key, std::function< std::vector< std::string >()> getter, std::function< void(std::span< const std::string >)> setter)=0
Add a string array property.
virtual void AddSmallStringProperty(std::string_view key, std::function< std::string_view(wpi::util::SmallVectorImpl< char > &buf)> getter, std::function< void(std::string_view)> setter)=0
Add a string property (SmallString form).
virtual void PublishConstInteger(std::string_view key, int64_t value)=0
Add a constant integer property.
Definition BooleanTopic.hpp:24
StringMap is a sorted associative container that contains key-value pairs with unique string keys.
Definition StringMap.hpp:26
Definition CvSource.hpp:15