WPILibC++  2020.3.2-60-g3011ebe
SendableChooser.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2011-2020 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <memory>
11 
12 #include <wpi/StringMap.h>
13 #include <wpi/StringRef.h>
14 #include <wpi/deprecated.h>
15 
16 #include "frc/smartdashboard/SendableBuilder.h"
17 #include "frc/smartdashboard/SendableChooserBase.h"
18 
19 namespace frc {
20 
34 template <class T>
36  wpi::StringMap<T> m_choices;
37 
38  template <class U>
39  static U _unwrap_smart_ptr(const U& value);
40 
41  template <class U>
42  static U* _unwrap_smart_ptr(const std::unique_ptr<U>& value);
43 
44  template <class U>
45  static std::weak_ptr<U> _unwrap_smart_ptr(const std::shared_ptr<U>& value);
46 
47  public:
48  ~SendableChooser() override = default;
49 
50  void AddOption(wpi::StringRef name, T object);
51  void SetDefaultOption(wpi::StringRef name, T object);
52 
64  WPI_DEPRECATED("use AddOption() instead")
65  void AddObject(wpi::StringRef name, T object) { AddOption(name, object); }
66 
78  WPI_DEPRECATED("use SetDefaultOption() instead")
79  void AddDefault(wpi::StringRef name, T object) {
80  SetDefaultOption(name, object);
81  }
82 
83  auto GetSelected() -> decltype(_unwrap_smart_ptr(m_choices[""]));
84 
85  void InitSendable(SendableBuilder& builder) override;
86 };
87 
88 } // namespace frc
89 
90 #include "frc/smartdashboard/SendableChooser.inc"
frc::SendableChooser
The SendableChooser class is a useful tool for presenting a selection of options to the SmartDashboar...
Definition: SendableChooser.h:35
frc::SendableChooser::InitSendable
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
Definition: SendableChooser.inc:76
frc::SendableChooser::AddDefault
void AddDefault(wpi::StringRef name, T object)
Add the given object to the list of options and marks it as the default.
Definition: SendableChooser.h:79
frc::SendableChooser::AddObject
void AddObject(wpi::StringRef name, T object)
Adds the given object to the list of options.
Definition: SendableChooser.h:65
wpi
WPILib C++ utilities (wpiutil) namespace.
Definition: Endian.h:31
frc::SendableChooser::SetDefaultOption
void SetDefaultOption(wpi::StringRef name, T object)
Add the given object to the list of options and marks it as the default.
Definition: SendableChooser.inc:44
wpi::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
frc::SendableChooserBase
This class is a non-template base class for SendableChooser.
Definition: SendableChooserBase.h:28
wpi::StringMap< T >
frc
A class that enforces constraints on the differential drive kinematics.
Definition: PDPSim.h:16
frc::SendableChooser::GetSelected
auto GetSelected() -> decltype(_unwrap_smart_ptr(m_choices[""]))
Returns a copy of the selected option (a raw pointer U* if T = std::unique_ptr<U> or a std::weak_ptr<...
Definition: SendableChooser.inc:61
frc::SendableChooser::AddOption
void AddOption(wpi::StringRef name, T object)
Adds the given object to the list of options.
Definition: SendableChooser.inc:30
frc::SendableBuilder
Definition: SendableBuilder.h:23