37 requires std::copy_constructible<T> && std::default_initializable<T>
40 std::function<void(T)> m_listener;
42 static U _unwrap_smart_ptr(
const U& value) {
47 static std::weak_ptr<U> _unwrap_smart_ptr(
const std::shared_ptr<U>& value) {
52 using CopyType =
decltype(_unwrap_smart_ptr(m_choices.
find(
"")->second));
69 m_choices[
name] = std::move(
object);
100 std::scoped_lock lock(
m_mutex);
105 if (selected.empty()) {
108 auto it = m_choices.
find(selected);
109 if (it == m_choices.end()) {
112 return _unwrap_smart_ptr(it->second);
123 std::scoped_lock lock(
m_mutex);
124 m_listener = listener;
133 std::vector<std::string> keys;
134 for (
const auto& choice : m_choices) {
135 keys.emplace_back(choice.first);
149 std::scoped_lock lock(
m_mutex);
159 [=,
this](std::string_view val) {
161 std::function<void(T)> listener;
163 std::scoped_lock lock(
m_mutex);
167 choice = m_choices[val];
168 listener = m_listener;
This class is a non-template base class for SendableChooser.
Definition SendableChooserBase.h:23
static constexpr const char * kActive
Definition SendableChooserBase.h:35
std::string m_defaultChoice
Definition SendableChooserBase.h:38
static constexpr const char * kInstance
Definition SendableChooserBase.h:36
wpi::mutex m_mutex
Definition SendableChooserBase.h:41
static constexpr const char * kOptions
Definition SendableChooserBase.h:33
static constexpr const char * kSelected
Definition SendableChooserBase.h:34
std::string m_selected
Definition SendableChooserBase.h:39
bool m_haveSelected
Definition SendableChooserBase.h:40
int m_instance
Definition SendableChooserBase.h:42
static constexpr const char * kDefault
Definition SendableChooserBase.h:32
std::string m_previousVal
Definition SendableChooserBase.h:43
The SendableChooser class is a useful tool for presenting a selection of options to the SmartDashboar...
Definition SendableChooser.h:38
SendableChooser & operator=(SendableChooser &&rhs)=default
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.h:81
SendableChooser(SendableChooser &&rhs)=default
decltype(_unwrap_smart_ptr(m_choices.find("") ->second)) CopyType
Definition SendableChooser.h:52
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
Definition SendableChooser.h:127
void OnChange(std::function< void(T)> listener)
Bind a listener that's called when the selected value changes.
Definition SendableChooser.h:122
~SendableChooser() override=default
void AddOption(std::string_view name, T object)
Adds the given object to the list of options.
Definition SendableChooser.h:68
CopyType GetSelected() const
Returns a copy of the selected option (a std::weak_ptr<U> if T = std::shared_ptr<U>).
Definition SendableChooser.h:97
SendableChooser()=default
Helper class for building Sendable dashboard representations.
Definition SendableBuilder.h:21
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 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 AddSmallStringProperty(std::string_view key, std::function< std::string_view(wpi::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.
virtual void AddStringProperty(std::string_view key, std::function< std::string()> getter, std::function< void(std::string_view)> setter)=0
Add a string property.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition sha1.h:30
void assign(size_type NumElts, ValueParamT Elt)
Definition SmallVector.h:720
size_t size() const
Definition SmallVector.h:99
pointer data()
Return a pointer to the vector's buffer, even if empty().
Definition SmallVector.h:302
StringMap is a sorted associative container that contains key-value pairs with unique string keys.
Definition StringMap.h:26
iterator find(std::string_view key)
Finds an element with key equal to key.
Definition StringMap.h:655